Just nu i M3-nätverket
Jump to content

Bugg i snake-spelet


ampy

Recommended Posts

Har denna kod till ett snake-spel:

 

<script language="JavaScript">
direct="null";sec=0;run="get";S=0;var top=new Array();var left=new Array();var go=new Array()
for(n=2;n<=100;n++){go[n]="not";top[n]=-200;left[n]=-200};for(n=1;n<5;n++){go[n]="yes"}
function locatEm(turn){ar=new Array(70,160,140,10,60,70,100,30,190,180);am=new Array(10,110,190,170,60,30,60,80,150,120,20,130,180,160,200,180,70,100,90,20);test=sec;now=new Date();sec=now.getSeconds();if(test==sec){sec+=sec};left[turn]=ar[sec%10];top[turn]=am[sec%20];showEm(turn);if(turn!=5){showscore();speed-=rate}}
function SSnake(){if(go[100]=="yes"){document.all.yw.style.pixelTop=60;lost="yes"};for(i=99;i>1;i--){if(go[i]=="yes"){top[i]=top[(i-1)];left[i]=left[(i-1)]}};if(direct=="up"){top[1]-=10};if(direct=="down"){top[1]+=10};if(direct=="left"){left[1]-=10};if(direct=="right"){left[1]+=10};for(m=99;m>4;m--){if(top[1]==top[m]){if(left[1]==left[m]){if(go[m]!="yes"){go[m]="yes";locatEm((m+1))}else{lost="yes"}}}};if(top[1]==top[100]){if(left[1]==left[100]){go[100]="yes"}};for(z=1;z<=99;z++){if(go[z]=="yes"){showEm(z)}};if(top[1]==0){lost="yes"};if(top[1]==210){lost="yes"};if(left[1]==0){lost="yes"};if(left[1]==210){lost="yes"};if(lost!="yes"){setTimeout("SSnake()",speed)}else{hideEm(1);if(go[100]!="yes"){document.all.go.style.pixelTop=60;setTimeout("reaload()",2000)}}}
function showEm(turn){eval("document.all.dot"+turn+".style.pixelTop ="+top[turn]);eval("document.all.dot"+turn+".style.pixelLeft ="+left[turn])}
function keyDown(){k=window.event.keyCode;if(k==104){if(direct!="down"){direct="up"}};if(k==98){if(direct!="up"){direct="down"}};if(k==100){if(direct!="right"){direct="left"}};if(k==102){if(direct!="left"){direct="right"}};if(k==38){if(direct!="down"){direct="up"}};if(k==40){if(direct!="up"){direct="down"}};if(k==37){if(direct!="right"){direct="left"}};if(k==39){if(direct!="left"){direct="right"}}}
function startIt(){if(run=="not"){S=0;add=0;showscore();if(level==1){speed=151;rate=1.5;add=3};if(level==2){speed=101;rate=1;add=5};if(level==3){speed=51;rate=.5;add=9};if(level==4){speed=11;rate=.1;add=15};direct="null";lost="not";top[1]=100;left[1]=90;setTimeout('locatEm(5)',3000);document.all.bd.style.pixelTop=-200;run="once";SSnake()}}
function reaload(){for(n=4;n<=199;n++){go[n]="not"};for(e=1;e<=199;e++){hideEm(e)};run="not";document.all.go.style.pixelTop=-200;document.all.bd.style.pixelTop=15;document.all.yw.style.pixelTop=-200}

function hideEm(turn){top[turn]=-200;eval("document.all.dot"+turn+".style.pixelTop=-200")}
function showscore(){S+=add;parent.score.document.write("<bo"+"dy bgcolor=#FFFFFF text=#000000 topmargin='0' leftmargin='0'><center><table border='0' width='100%'><tr><td align='center'><font face=Verdana size=2><strong>Poäng "+S+"</font></strong></td></tr><tr><td align='center'><input type='button' onClick=parent.document.location.href='game.asp?points="+S+"' value='Spara poängen' style='width:140px;border-width: 1px;background-color: #FFFFFF;cursor:hand;font-weight: bold' onfocus='blur()'></td></tr></table></center>");parent.score.document.close()}
function cantplay(){if(navigator.appName=="Netscape"){document.write("<div style='position:absolute; left: 9; top: 9'><img src=screan.gif></div>");alert("Sorry this game cannot be played with Netscape, please use Explorer 4 or heigher")}else{document.all.ld.style.pixelTop=-200;run="not"}}
document.onkeydown = keyDown
</script>

Men någonstanns i denna kod finns det en kod som gör att man inte kan få mer än 95 "äpplen". Kan ni hitta "spären" i denna kod?

 

Jag har letat själv men hittar inte det rätta stället.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.



×
×
  • Create New...