Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script language="JavaScript" type="text/JavaScript">
- <!--
- var moving_timer, count_down_timer; // Declare the two timers
- var score = 0; // To store the score of the player
- var time_remaining = 10; // To store the time remaining
- var monster_position=0; // To store the position of the monster
- var finished=false; // Indicate whether the game is finished or not
- var hitSound, missSound; // Declare the two sounds
- var difficulty;
- var difficulty2=1;
- var froze=false;
- var radios;
- function game_start(){
- difficulty = document.getElementsByName('diffs');
- radios = document.getElementsByName('func2');
- hitSound = document.getElementById("ouch");
- missSound = document.getElementById("boo");
- unfreeze();
- }
- function count_down(){
- time_remaining = time_remaining - 1;
- timer_text.innerHTML = "Time remaining: " + time_remaining + " sec";
- if (time_remaining == 0)
- game_over(); // do nothing
- else
- count_down_timer = setTimeout("count_down()", 1000);
- }
- function relocate(){
- for (var i = 0, length = difficulty.length; i < length; i++)
- {
- if (difficulty[i].checked)
- {
- // do whatever you want with the checked radio
- difficulty2=difficulty[i].value;
- // only one radio can be logically checked, don't check the rest
- break;
- }
- }
- document.images[monster_position].src = 'empty.png';
- monster_position = Math.floor(Math.random()*8)
- document.images[monster_position].src = 'monster.png';
- switch(difficulty2)
- {
- case '0': moving_timer = setTimeout("relocate()", 1000); break;
- case '1': moving_timer = setTimeout("relocate()", 600); break;
- case '2': moving_timer = setTimeout("relocate()", 200); break;
- }
- for (var i = 0, length = radios.length; i < length; i++)
- {
- if (radios[1].checked && froze == true)
- {
- alert(froze)
- unfreeze();
- froze = false;
- // only one radio can be logically checked, don't check the rest
- break;
- }
- if (radios[0].checked && froze == false)
- {
- alert(froze)
- freeze();
- froze=true;
- // only one radio can be logically checked, don't check the rest
- break;
- }
- }
- }
- function game_over(){
- finished = true;
- clearTimeout(moving_timer);
- alert("Times up!!!");
- }
- function freeze(){
- clearTimeout(moving_timer);
- clearTimeout(count_down_timer);
- }
- function unfreeze(){
- count_down();
- relocate();
- }
- function keyboard_event(event){
- var pressed_key = String.fromCharCode(event.keyCode);
- var hit_box;
- switch(pressed_key)
- {
- case 'Q': hit_box=0; break;
- case 'W': hit_box=1; break;
- case 'E': hit_box=2; break;
- case 'A': hit_box=3; break;
- case 'S': hit_box=4; break;
- case 'D': hit_box=5; break;
- case 'Z': hit_box=6; break;
- case 'X': hit_box=7; break;
- case 'C': hit_box=8; break;
- }
- if (hit_box == monster_position){
- hitSound.play();
- score = score + 1;
- score_text.innerHTML = "Score: " + score;
- clearTimeout(moving_timer);
- relocate();
- }
- else {
- missSound.play();
- }
- }
- -->
- </script>
- </head>
- <body onload="game_start()" onKeyDown="if (!finished) keyboard_event(event)">
- <form action="#n" name="theForm">
- <label for="diff">Difficulty: </label>
- <input type="radio" name="diffs" value="2"> Expert
- <input type="radio" name="diffs" value="1" checked="checked" > Normal
- <input type="radio" name="diffs" value="0" > Novice<br><br>
- </form>
- <label for="func2">Stop: </label>
- <input type="radio" name="func" value="1" checked="checked" > False
- <input type="radio" name="func" value="0"> True<br><br>
- </form>
- <audio src="./boo.mp3" type="audio/mpeg" id="boo" preload="auto" autobuffer controls> </audio>
- <audio src="./ouch.mp3" type="audio/mpeg" id="ouch" preload="auto" autobuffer controls > </audio>
- <table border="10" width="300">
- <tr>
- <td height="100" width="100"> <img src="empty.png" height="100" width="100"> </td>
- <td height="100" width="100"> <img src="empty.png" height="100" width="100"> </td>
- <td height="100" width="100"> <img src="empty.png" height="100" width="100"> </td>
- </tr>
- <tr>
- <td height="100" width="100"> <img src="empty.png" height="100" width="100"> </td>
- <td height="100" width="100"> <img src="empty.png" height="100" width="100"> </td>
- <td height="100" width="100"> <img src="empty.png" height="100" width="100"> </td>
- </tr>
- <tr>
- <td height="100" width="100"> <img src="empty.png" height="100" width="100"> </td>
- <td height="100" width="100"> <img src="empty.png" height="100" width="100"> </td>
- <td height="100" width="100"> <img src="empty.png" height="100" width="100"> </td>
- </tr>
- </table>
- <div id="timer_text" style="font-size:32pt">
- Time remaining: 10 sec
- </div>
- <div id="score_text" style="font-size:32pt">
- Score: 0
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement