Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.14 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  4. <script src="scripts/jquery-3.2.1.min.js"></script>
  5. <style>
  6.     /* K6ik stiilid on siin */
  7.  
  8.     header {
  9.         color: aquamarine;
  10.     }
  11.  
  12.     td {
  13.         width: 17vw;
  14.         height: 17vw;
  15.     }
  16.  
  17.     button {
  18.         margin-top: 2vh;
  19.     }
  20.  
  21. </style>
  22.  
  23. <body>
  24.     <center>
  25.         <!-- Veebilehe kood l2heb siia -->
  26.         <h1>Clicker Game</h1>
  27.         <p>Score: <text id="score">0</text></p>
  28.         <table border="1">
  29.             <tr>
  30.                 <td id="11"></td>
  31.                 <td id="12"></td>
  32.                 <td id="13"></td>
  33.                 <td id="14"></td>
  34.                 <td id="15"></td>
  35.             </tr>
  36.             <tr>
  37.                 <td id="21"></td>
  38.                 <td id="22"></td>
  39.                 <td id="23"></td>
  40.                 <td id="24"></td>
  41.                 <td id="25"></td>
  42.             </tr>
  43.             <tr>
  44.                 <td id="31"></td>
  45.                 <td id="32"></td>
  46.                 <td id="33"></td>
  47.                 <td id="34"></td>
  48.                 <td id="35"></td>
  49.             </tr>
  50.             <tr>
  51.                 <td id="41"></td>
  52.                 <td id="42"></td>
  53.                 <td id="43"></td>
  54.                 <td id="44"></td>
  55.                 <td id="45"></td>
  56.             </tr>
  57.             <tr>
  58.                 <td id="51"></td>
  59.                 <td id="52"></td>
  60.                 <td id="53"></td>
  61.                 <td id="54"></td>
  62.                 <td id="55"></td>
  63.             </tr>
  64.         </table>
  65.  
  66.         <button id="startGame">Start</button>
  67.     </center>
  68. </body>
  69.  
  70. <script>
  71.     let score = 0;
  72.     let timeout = 1000; // in ms
  73.     let squareColor = "rgb(255, 0, 0)";
  74.     let gameStarted = false;
  75.  
  76.     function getRandomSquareId() {
  77.         let min = 1;
  78.         let max = 5;
  79.         let x = Math.floor(Math.random() * max) + min;
  80.         let y = Math.floor(Math.random() * max) + min;
  81.         return y.toString() + x.toString();
  82.     }
  83.  
  84.     function clearTheBoard() {
  85.         for (let y = 1; y <= 5; y++) {
  86.            for (let x = 1; x <= 5; x++) {
  87.                let id = "#" + y.toString() + x.toString();
  88.                $(id).css("background-color", "white");
  89.            }
  90.        }
  91.    }
  92.  
  93.    function renewPointSquare() {
  94.        clearTheBoard();
  95.        let randomID = getRandomSquareId();
  96.        $("#" + randomID).css("background-color", squareColor);
  97.        setTimeout(renewPointSquare, timeout);
  98.        timeout = timeout * 0.95;
  99.        if (timeout < 150) {
  100.            timeout = 150;
  101.        }
  102.    }
  103.  
  104.    // M2ngu loogika
  105.  
  106.  
  107.    $("#startGame").click(function() {
  108.        if (gameStarted) {
  109.            location.reload();
  110.        } else {
  111.            gameStarted = true;
  112.            renewPointSquare();
  113.            $("td").click(function() {
  114.                if ($(this).css("background-color") == squareColor) {
  115.                    score += 1;
  116.                } else {
  117.                    score -= 1;
  118.                }
  119.                $("#score").text(score);
  120.            });
  121.        }
  122.    });
  123.  
  124. </script>
  125.  
  126. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement