Guest User

Untitled

a guest
Jan 4th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. <html>
  2. <head>
  3. <style>
  4. .element {
  5. border: 1px solid #ccc;
  6. width: 50px;
  7. height: 50px;
  8. display: inline-block;
  9. }
  10. .moneda {
  11. border: 1px solid #ccc;
  12. width: 50px;
  13. height: 50px;
  14. display: inline-block;
  15. background-color: yellow;
  16. }
  17. #matriu {
  18. width: 850px;
  19. }
  20. </style>
  21. </head>
  22. <body>
  23.  
  24. <div id="matriu">
  25.  
  26. </div>
  27.  
  28. <div id="temps">
  29. <p> hola </p>
  30. </div>
  31.  
  32. <script>
  33. const totalNumber = 50;
  34. var matriu = [];
  35. var count = 0;
  36. var time = 25;
  37. var countWin = 0;
  38.  
  39. for(let _i = 0; _i < 16; _i++) {
  40. matriu.push([]);
  41. for(let _j = 0; _j < 16; _j++) {
  42. var element = document.createElement('div');
  43. element.onclick = function () {
  44. test(_i, _j, element)
  45. };
  46. element.id = `element_${_i}_${_j}`
  47.  
  48. if(getRandomInt(1, 5) > 3 && count < totalNumber) {
  49. matriu[_i].push(1);
  50. element.className = 'moneda';
  51. count++;
  52. }
  53. else {
  54. matriu[_i].push(0);
  55. element.className = 'element';
  56. }
  57.  
  58. document.getElementById('matriu').appendChild(element);
  59. }
  60. }
  61.  
  62. function test(x, y, element) {
  63. if(matriu[x][y] == 1) {
  64. countWin++;
  65. matriu[x][y] = 0;
  66. }
  67. document.getElementById(`element_${x}_${y}`).className = 'element';
  68. }
  69.  
  70. function getRandomInt(min, max) {
  71. return Math.floor(Math.random() * (max - min)) + min;
  72. }
  73.  
  74. setInterval(function() {
  75. time = time - 1;
  76. document.getElementById('temps').innerHTML = `<p>${time}</p>`;
  77.  
  78. if(countWin === 50) {
  79. alert("win");
  80. }
  81.  
  82. if(time < 1) {
  83. if(countWin === 50) alert("win");
  84. else alert("lose");
  85. }
  86. }, 1000);
  87. </script>
  88. </body>
  89. </html>
Advertisement
Add Comment
Please, Sign In to add comment