Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.46 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>Document</title>
  8. <style>
  9. *{
  10. margin:0;
  11. padding:0;
  12. }
  13. #poj{
  14. position:relative
  15. }
  16. .pole{
  17. font-size:30px;
  18. font-weight:bolder;
  19. text-align:center;
  20. }
  21. </style>
  22. <script src="libs/jquery.js"></script>
  23. </head>
  24. <body>
  25. <div id="main">
  26.  
  27. </div>
  28. <script>
  29. $(document).ready(function(){
  30. let tab = [];
  31. createGame();
  32. klikanie();
  33. let wygrana = 0;
  34. function klikanie(){
  35. let kolko = false;
  36.  
  37.  
  38.  
  39. $('.pole').on('click', function(){
  40. if (kolko){
  41. $(this).html('O').addClass('checkedy').off('click');
  42. tab.push(this)
  43. kolko = !kolko;
  44.  
  45. }
  46. else{
  47. $(this).html('X').addClass('checkedx').off('click');
  48. tab.push(this)
  49.  
  50. kolko = !kolko;
  51. console.log(this)
  52. }
  53. setTimeout(function(){winCheck()},100);
  54. });
  55. }
  56. function createGame(){
  57. $('.pole').remove()
  58. let numer = 1
  59. for (let i = 0; i < 3; i++){
  60. for(let j = 0; j < 3; j++){
  61. let pole = $('<div>').addClass('pole').css({'position': 'absolute', 'width': '50px', 'height': '50px', 'border': '1px solid black', 'top': 50 + 50 * i, 'left': 50*j }).addClass('p'+numer);
  62. $('#main').append(pole);
  63. numer++
  64. }
  65. }
  66. $('.pole').on('click', klikanie());
  67. }
  68. function winCheck(){
  69.  
  70.  
  71. if($('.p1').hasClass('checkedx') && $('.p4').hasClass('checkedx') && $('.p7').hasClass('checkedx')){
  72. wygrana = 1
  73. console.log('eluwa1')
  74. }
  75. else if($('.p2').hasClass('checkedx') && $('.p5').hasClass('checkedx') && $('.p8').hasClass('checkedx')){
  76. wygrana = 1
  77. console.log('eluwa2')
  78. }
  79. else if($('.p3').hasClass('checkedx') && $('.p6').hasClass('checkedx') && $('.p9').hasClass('checkedx')){
  80. wygrana = 1
  81. console.log('eluwa3')
  82. }
  83. else if($('.p1').hasClass('checkedx') && $('.p2').hasClass('checkedx') && $('.p3').hasClass('checkedx')){
  84. wygrana = 1
  85. console.log('eluwa4')
  86. }
  87. else if($('.p4').hasClass('checkedx') && $('.p5').hasClass('checkedx') && $('.p6').hasClass('checkedx')){
  88. wygrana = 1
  89. console.log('eluwa5')
  90. }
  91. else if($('.p7').hasClass('checkedx') && $('.p8').hasClass('checkedx') && $('.p9').hasClass('checkedx')){
  92. wygrana = 1
  93. console.log('eluwa6')
  94. }
  95. else if($('.p1').hasClass('checkedx') && $('.p5').hasClass('checkedx') && $('.p9').hasClass('checkedx')){
  96. wygrana = 1
  97. console.log('eluwa7')
  98. }
  99. else if($('.p3').hasClass('checkedx') && $('.p5').hasClass('checkedx') && $('.p7').hasClass('checkedx')){
  100. wygrana = 1
  101. console.log('eluwa8')
  102. }
  103. else if($('.p1').hasClass('checkedy') && $('.p4').hasClass('checkedy') && $('.p7').hasClass('checkedy')){
  104. wygrana = 2
  105. console.log('eluwa9')
  106. }
  107. else if($('.p2').hasClass('checkedy') && $('.p5').hasClass('checkedy') && $('.p8').hasClass('checkedy')){
  108. wygrana = 2
  109. console.log('1eluwa')
  110. }
  111. else if($('.p3').hasClass('checkedy') && $('.p6').hasClass('checkedy') && $('.p7').hasClass('checkedy')){
  112. wygrana = 2
  113. console.log('2eluwa')
  114. }
  115. else if($('.p1').hasClass('checkedy') && $('.p2').hasClass('checkedy') && $('.p3').hasClass('checkedy')){
  116. wygrana = 2
  117. console.log('3eluwa')
  118. }
  119. else if($('.p4').hasClass('checkedy') && $('.p5').hasClass('checkedy') && $('.p6').hasClass('checkedy')){
  120. wygrana = 2
  121. console.log('4eluwa')
  122. }
  123. else if($('.p7').hasClass('checkedy') && $('.p8').hasClass('checkedy') && $('.p9').hasClass('checkedy')){
  124. wygrana = 2
  125. console.log('5eluwa')
  126. }
  127. else if($('.p1').hasClass('checkedy') && $('.p5').hasClass('checkedy') && $('.p9').hasClass('checkedy')){
  128. wygrana = 2
  129. console.log('6eluwa')
  130. }
  131. else if($('.p3').hasClass('checkedy') && $('.p5').hasClass('checkedy') && $('.p7').hasClass('checkedy')){
  132. wygrana = 2
  133. console.log('7eluwa')
  134. }
  135. else if(tab.length == 9 ){
  136. wygrana = 3
  137. }
  138.  
  139.  
  140. if(wygrana == 2){
  141. window.alert('WYGRANA KÓŁKA, aby zagrac od nowa nacisnij ok')
  142. wygrana = 0
  143. createGame();
  144. }
  145. else if(wygrana == 1){
  146. window.alert('WYGRANA KRZYŻYKA, aby zagrac od nowa nacisnij ok')
  147. wygrana = 0
  148. createGame();
  149. }
  150. else if(wygrana == 3){
  151. window.alert ('REMIS, aby zagrac od nowa nacisnij ok')
  152. wygrana = 0
  153. createGame();
  154. }
  155. }
  156. /* function klikniecie(){
  157. if (kolko){
  158. $(this).html('O').addClass('o').off('click');
  159. kolko = !kolko;
  160. console.log(this);
  161. }
  162. else{
  163. $(this).html('X').addClass('x').off('click');
  164. kolko = !kolko;
  165. console.log(this)
  166. }
  167. }*/
  168.  
  169. })
  170. </script>
  171. </body>
  172. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement