Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.52 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="pl">
  3.   <head>
  4.     <title>[title]</title>
  5.     <meta charset="utf-8" />
  6.     <link rel="stylesheet" href="style.css" />
  7.   </head>
  8.   <body>
  9.     <div id="board">
  10.        
  11.     </div>
  12.     <script>
  13.         var board = document.getElementById("board");
  14.         var colors = ['green','green','yellow','yellow','orange','orange','blue','blue','magenta','magenta','lime','lime','pink','pink','turquoise','turquoise'];
  15.         var isFirstClick = true;
  16.         var firstCardValue;
  17.         var firstCardId;
  18.         sortCards();
  19.         for(var i=0; i<16; i++){
  20.             if(i % 4 == 3){
  21.                 board.innerHTML += "<div class='card right' onclick='clickEvent(this,"+i+");'></div>";
  22.             }else{
  23.                 board.innerHTML += "<div class='card' onclick='clickEvent(this,"+i+");'></div>";
  24.             }
  25.             /*
  26.                 lub:
  27.                 board.innerHTML = board.innerHTML + "<div class='card'></div>"
  28.             */
  29.         }
  30.         function clickEvent(elem,num){
  31.             if(isFirstClick == true){
  32.                 isFirstClick = false;
  33.                 firstCardValue = colors[num];
  34.                 firstCardId = num;
  35.             }else{
  36.                 if(firstCardId == num){
  37.                     console.log("dirty cheater");
  38.                 }else{
  39.                     if(firstCardValue == colors[num]){
  40.                         console.log("para");
  41.                     }
  42.                     isFirstClick = true;
  43.                 }
  44.             }
  45.        
  46.             elem.style.backgroundColor = colors[num];
  47.         }
  48.        
  49.         function sortCards(){
  50.             var tmp;
  51.             var rand;
  52.             for(var i=0; i<16; i++){
  53.                 tmp = colors[i];
  54.                 rand = Math.round(Math.random()*15)
  55.                 colors[i] = colors[rand];
  56.                 colors[rand] = tmp;
  57.                 //console.log(Math.round(Math.random()*15));
  58.             }
  59.         }
  60.     </script>
  61.   </body>
  62. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement