ahmed0saber

Tic Tac Toe 2 players in HTML , CSS , JS

Dec 6th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <head>
  3. <title>Tic Tac Toe</title>
  4. <style>
  5. input[type="button"]
  6. {height:100px;
  7. width:100px;
  8. margin:5px 5px 5px 5px;
  9. background-color:#FFFFAA;
  10. color: black;
  11. border: 2px solid #4CAF50;
  12. transition-duration: 0.5s;
  13. cursor: pointer;
  14. border-radius:5px;
  15. font-size: 50px;}
  16. input[type="button"]:hover {background-color: #4CAF50;
  17. color: white;
  18. border: 2px solid #000000;}
  19. #play {display:none;
  20. height:500px;
  21. width:400px;
  22. position:absolute;
  23. top:25%;
  24. left:25%;
  25. text-align:center;
  26. box-shadow:0px 0px 10px #000000;
  27. background-color:#B8EEF8;}
  28. #start {position:absolute;
  29. height:500px;
  30. width:400px;
  31. top:25%;
  32. left:25%;
  33. text-align:center;
  34. box-shadow:0px 0px 10px #000000;
  35. background-color:#B8EEF8;}
  36. #go0 {height:50px;
  37. width:200px;
  38. margin:100px 10px 10px 10px;
  39. background-color:#FFFFAA;
  40. color: black;
  41. border: 2px solid #4CAF50;
  42. transition-duration: 0.5s;
  43. cursor: pointer;
  44. border-radius:25px;}
  45. #go0:hover {background-color: #4CAF50;
  46. color: white;
  47. border: 2px solid #000000;}
  48. #back0 {height:50px;
  49. width:200px;
  50. margin:20px 10px 40px 10px;
  51. background-color:#FFFFAA;
  52. color: black;
  53. border: 2px solid #4CAF50;
  54. transition-duration: 0.5s;
  55. cursor: pointer;
  56. border-radius:25px;}
  57. #back0:hover {background-color: #4CAF50;
  58. color: white;
  59. border: 2px solid #000000;}
  60. #p1 {margin:25px 10px 0px 10px;
  61. font-size: 20px;}
  62. #p2 {margin:0px 10px 0px 10px;}
  63. </style>
  64. <script>
  65. var turn=0;
  66. function done(x){if(turn==0){document.getElementById(x).disabled=true;
  67. turn=1;
  68. document.getElementById(x).value="X";}
  69. else if(turn==1){document.getElementById(x).disabled=true;
  70. turn=0;
  71. document.getElementById(x).value="O";}}
  72. function go(){document.getElementById("play").style.display = "block";
  73. document.getElementById("start").style.display = "none";}
  74. function back(){document.getElementById("start").style.display = "block";
  75. document.getElementById("play").style.display = "none";}
  76. </script>
  77. </head>
  78. <body>
  79. <div id="start">
  80. <p id="p1"><b>Tic Tac Toe</b></p><br/>
  81. <p id="p2">2 Players</p><br/>
  82. <button onclick="go()" id="go0">Start</button>
  83. </div>
  84. <div id="play">
  85. <button onclick="back()" id="back0">Back</button>
  86. <table align="center">
  87. <tr>
  88. <td><input type="button" value="" onclick="done('b1')" id="b1"/></td>
  89. <td><input type="button" value="" onclick="done('b2')" id="b2"/></td>
  90. <td><input type="button" value="" onclick="done('b3')" id="b3"/></td>
  91. </tr>
  92. <tr>
  93. <td><input type="button" value="" onclick="done('b4')" id="b4"/></td>
  94. <td><input type="button" value="" onclick="done('b5')" id="b5"/></td>
  95. <td><input type="button" value="" onclick="done('b6')" id="b6"/></td>
  96. </tr>
  97. <tr>
  98. <td><input type="button" value="" onclick="done('b7')" id="b7"/></td>
  99. <td><input type="button" value="" onclick="done('b8')" id="b8"/></td>
  100. <td><input type="button" value="" onclick="done('b9')" id="b9"/></td>
  101. </tr>
  102. </table>
  103. </div>
  104. </body>
  105. </html>
Advertisement
Add Comment
Please, Sign In to add comment