Advertisement
drunkspinda02

Trabalho DA

Jan 2nd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.54 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Jogo do galo</title>
  5. <style type="text/css">
  6.  
  7. body{
  8. background-color: blue;
  9. color: white;
  10. }
  11.  
  12. table,td{
  13. border: 1px solid white;
  14. margin: auto;
  15. border-collapse: collapse;
  16. background-color: green;
  17. text-align: center;
  18.  
  19. }
  20.  
  21. td{
  22. width: 100px;
  23. height: 100px;
  24.  
  25. }
  26.  
  27. table{
  28. width: 300px;
  29. height: 300px;
  30. }
  31.  
  32. p{
  33. text-align: center;
  34. }
  35.  
  36. input{
  37. border-radius: 15px;
  38. }
  39.  
  40. input[type=button]{
  41. background-color: #00BFFF;
  42. width: 150px;
  43. height: 27px;
  44. color: white;
  45. border-color: yellow;
  46. }
  47.  
  48. input[type=text]{
  49. text-align: center;
  50. border-color: yellow;
  51. background-color: #00FF00;
  52. }
  53.  
  54. .off{
  55. background-color: brown;
  56. }
  57.  
  58. .on{
  59. background-color: green;
  60. }
  61.  
  62. </style>
  63. </head>
  64. <body>
  65. <h1 style="text-align: center;">Jogo do Galo</h1>
  66. <table>
  67. <tr>
  68. <td class="off" id="a1" onclick="marca('a1');">&nbsp;</td>
  69. <td class="off" id="a2" onclick="marca('a2');">&nbsp;</td>
  70. <td class="off" id="a3" onclick="marca('a3');">&nbsp;</td>
  71. </tr>
  72. <tr>
  73. <td class="off" id="a4" onclick="marca('a4');">&nbsp;</td>
  74. <td class="off" id="a5" onclick="marca('a5');">&nbsp;</td>
  75. <td class="off" id="a6" onclick="marca('a6');">&nbsp;</td>
  76. </tr>
  77. <tr>
  78. <td class="off" id="a7" onclick="marca('a7');">&nbsp;</td>
  79. <td class="off" id="a8" onclick="marca('a8');">&nbsp;</td>
  80. <td class="off" id="a9" onclick="marca('a9');">&nbsp;</td>
  81. </tr>
  82. </table>
  83. <p><input type="button" name="start" value="Start" id="start" onclick="start()"></p>
  84. <p><input type="button" name="reset" value="Reset" id="reset" onclick="limpa()"></p>
  85. <p>Jogador<br><input type="text" name="jg1" id="jg1" value="0"></p>
  86. <p>CPU<br><input type="text" name="jg2" id="jg2" value="0"></p>
  87. <p>Empate<br><input type="text" name="emp" id="emp" value="0"></p>
  88.  
  89. <script type="text/javascript">
  90. var j=0;
  91. var i,b,c;
  92. var win=0;
  93. var jogada=0;
  94. var k =0;
  95.  
  96. function start(){
  97. for(i=1;i<=9;i++){
  98. if(document.getElementById('a' +i).className= "off"){
  99. document.getElementById('a' +i).className= "on"
  100. }
  101. }
  102. }
  103.  
  104. function marca(x){
  105. if (win==0 && k==0) {
  106. if(document.getElementById(x).innerHTML=='&nbsp;' && document.getElementById(x).className== "on"){
  107. document.getElementById(x).innerHTML='X';
  108. jogada++;
  109. k=1;
  110. verifica();
  111. }
  112.  
  113. else{
  114. alert('Não pode clickar nesta casa.')
  115. }
  116.  
  117. if (jogada<9 && win==0 && k==1) {
  118. do{
  119. c=Math.floor((Math.random()*9)+1);
  120. }while (document.getElementById('a' + c ).innerHTML!='&nbsp;' && document.getElementById(x).className== "on");
  121.  
  122. jogada++;
  123. document.getElementById('a'+c).innerHTML='O';
  124. k=0;
  125. verifica();
  126.  
  127. }
  128.  
  129. }
  130. }
  131. function verifica(){
  132.  
  133. for(i=1,b=4,c=7;i<=3;i++,b++,c++){
  134. if(win==0){
  135. if (document.getElementById('a' + i).innerHTML==document.getElementById('a' + b).innerHTML && document.getElementById('a' + i).innerHTML== document.getElementById('a' + c).innerHTML && document.getElementById('a' + i).innerHTML!='&nbsp;') {
  136. if(document.getElementById('a'+i).innerHTML=='X'){
  137. alert('Jogador venceu!');
  138. document.getElementById('jg1').value=parseInt(document.getElementById('jg1').value) + 1;
  139. win=1;
  140.  
  141. }
  142. else
  143. if(document.getElementById('a'+i).innerHTML=='O'){
  144. alert('CPU venceu!');
  145. document.getElementById('jg2').value=parseInt(document.getElementById('jg2').value) + 1;
  146. win=1;
  147. }
  148. }
  149. }
  150. }
  151.  
  152. for(i=1,b=2,c=3;i<=7;i=i+3,b=b+3,c=c+3){
  153. if(win==0){
  154. if (document.getElementById('a' + i).innerHTML==document.getElementById('a' + b).innerHTML && document.getElementById('a' + i).innerHTML== document.getElementById('a' + c).innerHTML && document.getElementById('a' + i).innerHTML!='&nbsp;') {
  155. if(document.getElementById('a'+i).innerHTML=='X'){
  156. alert('Jogador venceu!');
  157. document.getElementById('jg1').value=parseInt(document.getElementById('jg1').value) + 1;
  158. win=1;
  159.  
  160. }
  161. else
  162. if(document.getElementById('a'+i).innerHTML=='O'){
  163. alert('CPU venceu!');
  164. document.getElementById('jg2').value=parseInt(document.getElementById('jg2').value) + 1;
  165. win=1;
  166. }
  167. }
  168.  
  169. }
  170. }
  171.  
  172. if(win==0){
  173. if(document.getElementById('a1').innerHTML== document.getElementById('a5').innerHTML && document.getElementById('a1').innerHTML==document.getElementById('a9').innerHTML && document.getElementById('a1').innerHTML!='&nbsp;'){
  174. if(document.getElementById('a1').innerHTML=='X' && document.getElementById('a5').innerHTML=='X' && document.getElementById('a9').innerHTML=='X' ){
  175. alert('Jogador venceu!');
  176. document.getElementById('jg1').value=parseInt(document.getElementById('jg1').value) + 1;
  177. win=1;
  178.  
  179. }
  180. else
  181. if(document.getElementById('a1').innerHTML=='O' && document.getElementById('a5').innerHTML=='O' && document.getElementById('a9').innerHTML=='O' ){
  182. alert('CPU venceu!');
  183. document.getElementById('jg2').value=parseInt(document.getElementById('jg2').value) + 1;
  184. win=1;
  185. }
  186. }
  187. }
  188.  
  189. if(win==0){
  190. if(document.getElementById('a3').innerHTML== document.getElementById('a5').innerHTML && document.getElementById('a3').innerHTML==document.getElementById('a7').innerHTML && document.getElementById('a3').innerHTML!='&nbsp;'){
  191. if(document.getElementById('a3').innerHTML=='X' && document.getElementById('a5').innerHTML=='X' && document.getElementById('a7').innerHTML=='X' ){
  192. alert('Jogador venceu!');
  193. document.getElementById('jg1').value=parseInt(document.getElementById('jg1').value) + 1;
  194. win=1;
  195.  
  196. }
  197. else
  198. if(document.getElementById('a3').innerHTML=='O' && document.getElementById('a5').innerHTML=='O' && document.getElementById('a7').innerHTML=='O' ){
  199. alert('CPU venceu!');
  200. document.getElementById('jg2').value=parseInt(document.getElementById('jg2').value) + 1;
  201. win=1;
  202. }
  203. }
  204. }
  205.  
  206. if (win==0 && jogada==9) {
  207. alert('Empate.');
  208. document.getElementById('emp').value=parseInt(document.getElementById('emp').value) + 1;
  209.  
  210.  
  211. }
  212. }
  213. function limpa(){
  214. for(i=1;i<=9;i++){
  215. document.getElementById('a' + i).innerHTML='&nbsp;';
  216. }
  217. jogada=0;
  218. win=0;
  219. j=0;
  220. k=0;
  221. }
  222.  
  223.  
  224. </script>
  225. </body>
  226. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement