상위 문서로: ProjectD
1. 송치완 ¶
발퀄주의
<html> <head> <title>URL Hunter</title> <script> var mapSize=50; var hunter=25; var map=new Array(mapSize); var mopNum=15; var time=0; function mapInitialize(){ for (var i=0; i<mapSize; i++) { map[i] = '-'; } i=0; map[hunter] = 'O' while (i<15) { var temp=Math.floor(Math.random()*50); if(map[temp] != 'a' && temp != 25){ map[temp] = 'a'; i++; } } } function mapDraw(){ location.href="./URLHunter.html#|||" + map.join('') + "|||"; } function timeCheck(){ setInterval("time+=1", 1000); } function gamePlay(){ switch(event.keyCode) { case 37: // move left if (hunter != 0) { if (map[hunter] == 'O') { if (map[hunter-1] == 'a') { map[hunter-1] = '@'; map[hunter] = '-'; hunter--; break; } else { map[hunter-1] = 'O'; map[hunter] = '-'; hunter--; break; } } else { if (map[hunter-1] == 'a') { map[hunter-1] = '@'; map[hunter] = 'a'; hunter--; break; } else { map[hunter-1] = 'O'; map[hunter] = 'a'; hunter--; break; } } } else break; case 39: //move right if (hunter != mapSize-1) { if (map[hunter] == 'O') { if (map[hunter+1] == 'a') { map[hunter+1] = '@'; map[hunter] = '-'; hunter++; break; } else { map[hunter+1] = 'O'; map[hunter] = '-'; hunter++; break; } } else { if (map[hunter+1] == 'a') { map[hunter+1] = '@'; map[hunter] = 'a'; hunter++; break; } else { map[hunter+1] = 'O'; map[hunter] = 'a'; hunter++; break; } } } else break; case 32: //kill if (map[hunter] == '@') { map[hunter] = 'O'; mopNum--; break; } else break; } mapDraw(); } function gameFin(){ if (mopNum==0) alert("you spent " + time + " seconds"); } </script> </head> <body onload="mapInitialize(); mapDraw(); timeCheck();" onkeydown="gamePlay(); gameFin();"> Move with Arrow Key and press Space Bar to kill <br>tic-tok </body> </html>
버그: 게임이 끝나도 시간이 안 멈춤
2. 최다인 ¶
제껀 움직입니다!!
<html> <meta charset = "utf-8"> <head> <title>URL Hunter by MeYou</title> <script> var lineLength = 40; var hunterLoca = 20; var enemyNumber = 10; var URLline = new Array(lineLength); var time = 0; function initializeURL () { for(var i = 0; i < lineLength; i++){ URLline[i] = '-'; } URLline[hunterLoca] = 'O'; allocEnemy(); printMap(); } function allocEnemy () { for(var i = 0; i < enemyNumber; i++){ var enemyLoca = Math.floor(Math.random()*lineLength); if(enemyLoca == hunterLoca || URLline[enemyLoca] == 'a'){ i--; continue; } URLline[enemyLoca] = 'a'; } } function checkTime () { setInterval("time++",1000); setInterval(function e () {moveEnemy();},333); } function printMap () { location.href = "./URLHunter.html#|||" + URLline.join('') + "|||"; } function moveEnemy () { for(var i = 0; i < lineLength; i++){ var temp = Math.floor(Math.random()*3) - 1; if(URLline[i] == 'a'){ if(URLline[i + temp] == '-'){ URLline[i] = '-'; URLline[i + temp] = 'a'; } else if(URLline[i + temp] == 'O'){ URLline[i] = '-'; URLline[i + temp] = '@'; } } else if(URLline[i] == '@'){ if(URLline[i + temp] == '-'){ URLline[i] = 'O'; URLline[i + temp] = 'a'; } } } printMap(); } function keyboardInput() { switch(event.keyCode){ case 37: //left if(hunterLoca == 0) break; if(URLline[hunterLoca] == '@'){ URLline[hunterLoca] = 'a'; if(URLline[hunterLoca - 1] == '-') URLline[hunterLoca - 1] = 'O'; else if(URLline[hunterLoca - 1] == 'a') URLline[hunterLoca - 1] = '@'; } else if(URLline[hunterLoca] == 'O'){ URLline[hunterLoca] = '-'; if(URLline[hunterLoca - 1] == '-') URLline[hunterLoca - 1] = 'O'; else if(URLline[hunterLoca - 1] == 'a') URLline[hunterLoca - 1] = '@'; } hunterLoca--; break; case 39: //right if(hunterLoca == lineLength - 1) break; if(URLline[hunterLoca] == '@'){ URLline[hunterLoca] = 'a'; if(URLline[hunterLoca + 1] == '-') URLline[hunterLoca + 1] = 'O'; else if(URLline[hunterLoca + 1] == 'a') URLline[hunterLoca + 1] = '@'; } else if(URLline[hunterLoca] == 'O'){ URLline[hunterLoca] = '-'; if(URLline[hunterLoca + 1] == '-') URLline[hunterLoca + 1] = 'O'; else if(URLline[hunterLoca + 1] == 'a') URLline[hunterLoca + 1] = '@'; } hunterLoca++; break; case 32: //space if(URLline[hunterLoca] == '@'){ URLline[hunterLoca] = 'O'; enemyNumber--; } break; } printMap(); } function checkGameEnd() { if(enemyNumber == 0) alert("게임 클리어! [걸린 시간 : " + time + "초]"); } </script> </head> <body onload = "initializeURL(); checkTime();" onkeydown = "keyboardInput();" onkeyup = "checkGameEnd();"> URL Hunter </body> </html>
근데 치완선배랑 똑같은 버그 ㅋㅋㅋㅋㅋㅋㅋ시간아 멈춰라.....
- clearInterval(timecheck); , var timecheck = function (){} 이런 구문이면 가능했던걸로 기억하는데 실험해보시죠! - 이원준