Advertisement
drunkspinda02

DA FINAL!!!!

Mar 19th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.83 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Jogo do galo</title>
  5. <meta charset="utf-8">
  6. <style type="text/css">
  7.  
  8. body{
  9. background-color: blue;
  10. color: white;
  11. }
  12.  
  13. table,td{
  14. border: 1px solid white;
  15. margin: auto;
  16. border-collapse: collapse;
  17. background-color: green;
  18. text-align: center;
  19.  
  20. }
  21.  
  22. td{
  23. width: 100px;
  24. height: 100px;
  25.  
  26. }
  27.  
  28. table{
  29. width: 300px;
  30. height: 300px;
  31. }
  32.  
  33. p{
  34. text-align: center;
  35. }
  36.  
  37. input{
  38. border-radius: 15px;
  39. }
  40.  
  41. input[type=button]{
  42. width: 150px;
  43. height: 27px;
  44. border-color: yellow;
  45. }
  46.  
  47. input[type=text]{
  48. text-align: center;
  49. border-color: yellow;
  50. }
  51.  
  52. .off{
  53. background-color: brown;
  54. }
  55.  
  56. .on{
  57. background-color: green;
  58. }
  59.  
  60. .naoganhou{
  61. display: none;
  62. }
  63.  
  64. .ganhou{
  65. background-color: yellow;
  66. border: 1px solid black;
  67. color: black;
  68. width: 50%;
  69. margin: auto;
  70. }
  71.  
  72. </style>
  73. </head>
  74. <body>
  75. <?php
  76.  
  77. $turnbd = new mysqli('localhost','root','','exemplo da');
  78.  
  79. if ($turnbd->connect_error) {
  80. die('Erro na ligação : ('. $turnbd->connect_errno .') '. $turnbd->connect_error);
  81.  
  82. }
  83.  
  84. //Inserçao
  85.  
  86. if(isset($_POST['inserir'])){
  87.  
  88. $query = "INSERT INTO resultados(numero,nick,tempo) VALUES(?,?,?)";
  89.  
  90.  
  91. if ($_POST['numero']=='' || $_POST['nick']=='' || $_POST['tempo']=='') {
  92. echo "<div class='alert'><h1>Existem campos que nao foram preenchidos!</h1></div>";
  93. }
  94.  
  95. else{
  96.  
  97.  
  98. $statement = $turnbd->prepare($query);
  99.  
  100. $statement->bind_param('sss', $_POST["numero"],
  101. $_POST["nick"],
  102. $_POST["tempo"]);
  103. $statement->execute();
  104.  
  105. if ($statement->affected_rows>0){
  106. echo "<div class='alert'><h1> O seu registo foi inserido!</h1></div>";
  107. }
  108. else{
  109. die('Erro: ('. $turnbd->errno .') '. $turnbd->error);
  110. }
  111. $statement->close();
  112.  
  113. }
  114.  
  115. $turnbd->close();
  116. }
  117.  
  118. ?>
  119. <h1 style="text-align: center; text-shadow: 2px 2px grey;">Jogo do Galo</h1>
  120. <h2 style="text-align: center; text-shadow: 2px 2px grey;">Contra o CPU</h2>
  121. <div class="naoganhou" id="vitoria">
  122. <h1 style="text-align: center;">PARABÉNS, VOCÊ GANHOU!!!</h1>
  123. <form class="" action="" method="post">
  124. <p style="text-align:center;">Introduza aqui o seu numero de aluno numero de aluno:</p>
  125. <p style="text-align:center;"><input type="text" name="numero" value="" placeholder="Numero" ></p>
  126. <p style="text-align:center;"> Introduza aqui o seu nickname:</p>
  127. <p style="text-align:center;"><input type="text" name="nick" value="" placeholder="Nome" ></p>
  128. <p style="text-align:center;">O seu tempo:</p>
  129. <p style="text-align:center;"><input type="text" name="tempo" value="" id="tempo" readonly=""></p>
  130. <p style="text-align:center;"><input class="" name="inserir" type="submit" value="Enviar Resultados"></p>
  131. </form>
  132. </div>
  133. <br>
  134. <br>
  135. <table>
  136. <tr>
  137. <td class="off" id="a1" onclick="marca('a1');">&nbsp;</td>
  138. <td class="off" id="a2" onclick="marca('a2');">&nbsp;</td>
  139. <td class="off" id="a3" onclick="marca('a3');">&nbsp;</td>
  140. </tr>
  141. <tr>
  142. <td class="off" id="a4" onclick="marca('a4');">&nbsp;</td>
  143. <td class="off" id="a5" onclick="marca('a5');">&nbsp;</td>
  144. <td class="off" id="a6" onclick="marca('a6');">&nbsp;</td>
  145. </tr>
  146. <tr>
  147. <td class="off" id="a7" onclick="marca('a7');">&nbsp;</td>
  148. <td class="off" id="a8" onclick="marca('a8');">&nbsp;</td>
  149. <td class="off" id="a9" onclick="marca('a9');">&nbsp;</td>
  150. </tr>
  151. </table>
  152. <p><input type="button" name="start" value="Start" id="start" onclick="start();interval();"></p>
  153. <p><input type="button" name="reset" value="Reset" id="reset" onclick="limpa()"></p>
  154. <h1 style="text-align: center;" id="cronometro">00 : 00 : 00 : 00</h1>
  155. <p>Jogador<br><input type="text" name="jg1" id="jg1" value="0"></p>
  156. <p>CPU<br><input type="text" name="jg2" id="jg2" value="0"></p>
  157. <p>Empate<br><input type="text" name="emp" id="emp" value="0"></p>
  158.  
  159. <script type="text/javascript">
  160. var j=0;
  161. var i,b,c,j,w;
  162. var win=0;
  163. var jogada=0;
  164. var k =0;
  165. var linhascpu;
  166. var linhasplayer;
  167. var board = [0, 0, 0, 0, 0, 0, 0, 0, 0];
  168.  
  169. var cs = 0;
  170. var s = 0;
  171. var m = 0;
  172. var h = 0;
  173. var mcs = 0;
  174. var ms = 0;
  175. var mm = 0;
  176. var mh = 0;
  177. var form=document.getElementById('form');
  178.  
  179.  
  180.  
  181. function interval() {
  182. intervalo= setInterval(cron,10);
  183. }
  184.  
  185. function start(){
  186. document.getElementById('vitoria').className= "naoganhou";
  187. for(i=1;i<=9;i++){
  188. if(document.getElementById('a' +i).className= "off"){
  189. document.getElementById('a' +i).className= "on"
  190. }
  191. }
  192. }
  193.  
  194. function cron() {
  195.  
  196. cs++;
  197.  
  198. if (cs == 100 ) {
  199. s++; cs=0;
  200. }
  201. if (s == 60) {
  202. m++; s = 0;
  203. }
  204. if (m == 60) {
  205. h++; s = 0; m = 0;
  206. }
  207.  
  208.  
  209. if (cs<10) {
  210. mcs= "0" + cs
  211. }
  212. else{
  213. mcs= cs
  214. }
  215.  
  216. if (s<10) {
  217. ms= "0" + s
  218. }
  219. else{
  220. ms=s
  221. }
  222.  
  223. if (m<10) {
  224. mm= "0" + m
  225. }
  226. else{
  227. mm=m
  228. }
  229.  
  230. if (h<10) {
  231. mh= "0" + h
  232. }
  233. else{
  234. mh=h
  235. }
  236.  
  237.  
  238. document.getElementById('cronometro').innerHTML= mh + " : " + mm + " : " + ms + " : " + mcs;
  239.  
  240. }
  241.  
  242. function recomeçar(){
  243. s=0;
  244. cs=0;
  245. m=0;
  246. h=0;
  247. document.getElementById('cronometro').innerHTML= "00 : 00 : 00 : 00"
  248. clearInterval(intervalo);
  249. }
  250.  
  251.  
  252. function marca(x){
  253. if (win==0 && k==0) {
  254. if(document.getElementById(x).innerHTML=='&nbsp;' && document.getElementById(x).className== "on"){
  255. document.getElementById(x).innerHTML='X';
  256. for (i=1;i<=9;i++){
  257. if(document.getElementById('a' +i).innerHTML=='X'){
  258. board[i-1]=1;
  259. }
  260. }
  261. jogada++;
  262. k=1;
  263. verifica();
  264. }
  265.  
  266. else{
  267. alert('Não pode clickar nesta casa.')
  268. }
  269.  
  270.  
  271.  
  272.  
  273.  
  274. if (jogada<9 && win==0 && k==1 /*&& modojogo==2*/) {
  275.  
  276. if (jogada==1 && k==1) {
  277. if (board[4]==1) {
  278. board[6]=2;
  279. console.log(board);
  280. jogada++;
  281. document.getElementById('a7').innerHTML='O';
  282. k=0;
  283. verifica();
  284. }
  285. else{
  286. board[4]=2;
  287. console.log(board);
  288. jogada++;
  289. document.getElementById('a5').innerHTML='O';
  290. k=0;
  291. verifica();
  292. }
  293. }
  294.  
  295. if (jogada==3 && k==1) {
  296. if (board[2]==1 && board[6]==1 || board[0]==1 && board[8]==1) {
  297. board[7]=2;
  298. console.log(board);
  299. jogada++;
  300. document.getElementById('a8').innerHTML='O';
  301. k=0;
  302. verifica();
  303. }
  304. else if(board[4]==1 && board[2]==1 || board[4]==1 && board[0]==1 || board[4]==1 && board[8]==1){
  305. if (board[8]==0) {
  306. board[8]=2;
  307. console.log(board);
  308. jogada++;
  309. document.getElementById('a9').innerHTML='O';
  310. k=0;
  311. verifica();
  312. }
  313. else if (board[0]==0) {
  314. board[0]=2;
  315. console.log(board);
  316. jogada++;
  317. document.getElementById('a1').innerHTML='O';
  318. k=0;
  319. verifica();
  320. }
  321.  
  322. }
  323.  
  324. }
  325.  
  326.  
  327. if (k==1) {
  328. for(i=0,b=3,c=6;i<=3;i++,b++,c++){
  329. if(board[i]==board[b] && board[i]!=0 || board[i]==board[c] && board[i]!=0 || board[b]==board[c] && board[b]!=0){
  330. if (board[i]==0) {
  331. board[i]=2;
  332. console.log(board);
  333. jogada++;
  334. document.getElementById('a'+(i+1)).innerHTML='O';
  335. k=0;
  336. verifica();
  337. }
  338. else if (board[b]==0) {
  339. board[b]=2;
  340. console.log(board);
  341. jogada++;
  342. document.getElementById('a'+(b+1)).innerHTML='O';
  343. k=0;
  344. verifica();
  345. }
  346. else if (board[c]==0) {
  347. board[c]=2;
  348. console.log(board);
  349. jogada++;
  350. document.getElementById('a'+(c+1)).innerHTML='O';
  351. k=0;
  352. verifica();
  353. }
  354. }
  355. }
  356. }
  357.  
  358. if (k==1) {
  359. for(i=0,b=1,c=2;i<=6;i=i+3,b=b+3,c=c+3){
  360. if(board[i]==board[b] && board[i]!=0 || board[i]==board[c] && board[i]!=0 || board[b]==board[c] && board[b]!=0){
  361. if (board[i]==0) {
  362. board[i]=2;
  363. console.log(board);
  364. jogada++;
  365. document.getElementById('a'+(i+1)).innerHTML='O';
  366. k=0;
  367. verifica();
  368. }
  369. else if (board[b]==0) {
  370. board[b]=2;
  371. console.log(board);
  372. jogada++;
  373. document.getElementById('a'+(b+1)).innerHTML='O';
  374. k=0;
  375. verifica();
  376. }
  377. else if (board[c]==0) {
  378. board[c]=2;
  379. console.log(board);
  380. jogada++;
  381. document.getElementById('a'+(c+1)).innerHTML='O';
  382. k=0;
  383. verifica();
  384. }
  385. }
  386. }
  387. }
  388.  
  389. if (k==1) {
  390. if (board[0]==board[4] && board[0]!=0 || board[0]==board[8] && board[0]!=0 || board[4]==board[8] && board[4]!=0){
  391. if (board[0]==0) {
  392. board[0]=2;
  393. console.log(board);
  394. jogada++;
  395. document.getElementById('a1').innerHTML='O';
  396. k=0;
  397. verifica();
  398. }
  399. else if (board[4]==0) {
  400. board[4]=2;
  401. console.log(board);
  402. jogada++;
  403. document.getElementById('a5').innerHTML='O';
  404. k=0;
  405. verifica();
  406. }
  407. else if (board[8]==0) {
  408. board[8]=2;
  409. console.log(board);
  410. jogada++;
  411. document.getElementById('a9').innerHTML='O';
  412. k=0;
  413. verifica();
  414. }
  415. }
  416. }
  417.  
  418. if (k==1) {
  419. if (board[2]==board[4] && board[2]!=0 || board[2]==board[6] && board[2]!=0 || board[4]==board[6] && board[4]!=0){
  420. if (board[2]==0) {
  421. board[2]=2;
  422. console.log(board);
  423. jogada++;
  424. document.getElementById('a3').innerHTML='O';
  425. k=0;
  426. verifica();
  427. }
  428. else if (board[4]==0) {
  429. board[4]=2;
  430. console.log(board);
  431. jogada++;
  432. document.getElementById('a5').innerHTML='O';
  433. k=0;
  434. verifica();
  435. }
  436. else if (board[6]==0) {
  437. board[6]=2;
  438. console.log(board);
  439. jogada++;
  440. document.getElementById('a7').innerHTML='O';
  441. k=0;
  442. verifica();
  443. }
  444. }
  445. }
  446.  
  447. if(k==1){
  448. do{
  449. c=Math.floor((Math.random()*9)+1);
  450. }while (document.getElementById('a' + c ).innerHTML!='&nbsp;' && document.getElementById(x).className== "on");
  451. board[c-1]=2;
  452. console.log(board);
  453. jogada++;
  454. document.getElementById('a'+c).innerHTML='O';
  455. k=0;
  456. verifica();
  457. }
  458.  
  459.  
  460. }
  461.  
  462. }
  463. }
  464.  
  465. /*if (jogada<9 && win==0 && k==1 && modojogo==1){
  466. if(document.getElementById(x).innerHTML=='&nbsp;' && document.getElementById(x).className== "on"){
  467. document.getElementById(x).innerHTML='O';
  468. for (i=1;i<=9;i++){
  469. if(document.getElementById('a' +i).innerHTML=='O'){
  470. board[i-1]=1;
  471. }
  472. }
  473. jogada++;
  474. k=0;
  475. verifica();
  476. }
  477.  
  478. else{
  479. alert('Não pode clickar nesta casa.')
  480. }
  481. }*/
  482.  
  483.  
  484. function verifica(){
  485.  
  486. for(i=1,b=4,c=7;i<=3;i++,b++,c++){
  487. if(win==0){
  488. 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;') {
  489. if(document.getElementById('a'+i).innerHTML=='X'){
  490. alert('Jogador venceu!');
  491. document.getElementById('jg1').value=parseInt(document.getElementById('jg1').value) + 1;
  492. win=1;
  493. board = [0, 0, 0, 0, 0, 0, 0, 0, 0];
  494. for(i=1;i<=9;i++){
  495. if(document.getElementById('a' +i).className= "on"){
  496. document.getElementById('a' +i).className= "off";
  497. }
  498. }
  499. document.getElementById('vitoria').className= "ganhou";
  500. document.getElementById('tempo').value=mh + " : " + mm + " : " + ms + " : " + mcs;
  501. limpa();
  502. recomeçar();
  503.  
  504. }
  505. else
  506. if(document.getElementById('a'+i).innerHTML=='O'){
  507. alert('CPU venceu!');
  508. document.getElementById('jg2').value=parseInt(document.getElementById('jg2').value) + 1;
  509. win=1;
  510. board = [0, 0, 0, 0, 0, 0, 0, 0, 0];
  511. for(i=1;i<=9;i++){
  512. if(document.getElementById('a' +i).className= "on"){
  513. document.getElementById('a' +i).className= "off";
  514. }
  515. }
  516. limpa();
  517. recomeçar();
  518. }
  519. }
  520. }
  521. }
  522.  
  523. for(i=1,b=2,c=3;i<=7;i=i+3,b=b+3,c=c+3){
  524. if(win==0){
  525. 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;') {
  526. if(document.getElementById('a'+i).innerHTML=='X'){
  527. alert('Jogador venceu!');
  528. document.getElementById('jg1').value=parseInt(document.getElementById('jg1').value) + 1;
  529. win=1;
  530. board = [0, 0, 0, 0, 0, 0, 0, 0, 0];
  531. for(i=1;i<=9;i++){
  532. if(document.getElementById('a' +i).className= "on"){
  533. document.getElementById('a' +i).className= "off";
  534. }
  535. }
  536. document.getElementById('vitoria').className= "ganhou";
  537. document.getElementById('tempo').value=mh + " : " + mm + " : " + ms + " : " + mcs;
  538. limpa();
  539. recomeçar();
  540.  
  541. }
  542. else
  543. if(document.getElementById('a'+i).innerHTML=='O'){
  544. alert('CPU venceu!');
  545. document.getElementById('jg2').value=parseInt(document.getElementById('jg2').value) + 1;
  546. win=1;
  547. board = [0, 0, 0, 0, 0, 0, 0, 0, 0];
  548. for(i=1;i<=9;i++){
  549. if(document.getElementById('a' +i).className= "on"){
  550. document.getElementById('a' +i).className= "off";
  551. }
  552. }
  553. limpa();
  554. recomeçar();
  555. }
  556. }
  557.  
  558. }
  559. }
  560.  
  561. if(win==0){
  562. if(document.getElementById('a1').innerHTML== document.getElementById('a5').innerHTML && document.getElementById('a1').innerHTML==document.getElementById('a9').innerHTML && document.getElementById('a1').innerHTML!='&nbsp;'){
  563. if(document.getElementById('a1').innerHTML=='X' && document.getElementById('a5').innerHTML=='X' && document.getElementById('a9').innerHTML=='X' ){
  564. alert('Jogador venceu!');
  565. document.getElementById('jg1').value=parseInt(document.getElementById('jg1').value) + 1;
  566. win=1;
  567. board = [0, 0, 0, 0, 0, 0, 0, 0, 0];
  568. for(i=1;i<=9;i++){
  569. if(document.getElementById('a' +i).className= "on"){
  570. document.getElementById('a' +i).className= "off";
  571. }
  572. }
  573. document.getElementById('vitoria').className= "ganhou";
  574. document.getElementById('tempo').value=mh + " : " + mm + " : " + ms + " : " + mcs;
  575. limpa();
  576. recomeçar();
  577.  
  578. }
  579. else
  580. if(document.getElementById('a1').innerHTML=='O' && document.getElementById('a5').innerHTML=='O' && document.getElementById('a9').innerHTML=='O' ){
  581. alert('CPU venceu!');
  582. document.getElementById('jg2').value=parseInt(document.getElementById('jg2').value) + 1;
  583. win=1;
  584. board = [0, 0, 0, 0, 0, 0, 0, 0, 0];
  585. for(i=1;i<=9;i++){
  586. if(document.getElementById('a' +i).className= "on"){
  587. document.getElementById('a' +i).className= "off";
  588. }
  589. }
  590. limpa();
  591. recomeçar();
  592. }
  593.  
  594. }
  595. }
  596.  
  597. if(win==0){
  598. if(document.getElementById('a3').innerHTML== document.getElementById('a5').innerHTML && document.getElementById('a3').innerHTML==document.getElementById('a7').innerHTML && document.getElementById('a3').innerHTML!='&nbsp;'){
  599. if(document.getElementById('a3').innerHTML=='X' && document.getElementById('a5').innerHTML=='X' && document.getElementById('a7').innerHTML=='X' ){
  600. alert('Jogador venceu!');
  601. document.getElementById('jg1').value=parseInt(document.getElementById('jg1').value) + 1;
  602. win=1;
  603. board = [0, 0, 0, 0, 0, 0, 0, 0, 0];
  604. for(i=1;i<=9;i++){
  605. if(document.getElementById('a' +i).className= "on"){
  606. document.getElementById('a' +i).className= "off";
  607. }
  608. }
  609. document.getElementById('vitoria').className= "ganhou";
  610. document.getElementById('tempo').value=mh + " : " + mm + " : " + ms + " : " + mcs;
  611. limpa();
  612. recomeçar();
  613.  
  614. }
  615. else
  616. if(document.getElementById('a3').innerHTML=='O' && document.getElementById('a5').innerHTML=='O' && document.getElementById('a7').innerHTML=='O' ){
  617. alert('CPU venceu!');
  618. document.getElementById('jg2').value=parseInt(document.getElementById('jg2').value) + 1;
  619. win=1;
  620. board = [0, 0, 0, 0, 0, 0, 0, 0, 0];
  621. for(i=1;i<=9;i++){
  622. if(document.getElementById('a' +i).className= "on"){
  623. document.getElementById('a' +i).className= "off";
  624. }
  625. }
  626. limpa();
  627. recomeçar();
  628. }
  629. }
  630. }
  631.  
  632. if (win==0 && jogada==9) {
  633. alert('Empate.');
  634. document.getElementById('emp').value=parseInt(document.getElementById('emp').value) + 1;
  635. board = [0, 0, 0, 0, 0, 0, 0, 0, 0];
  636. for(i=1;i<=9;i++){
  637. if(document.getElementById('a' +i).className= "on"){
  638. document.getElementById('a' +i).className= "off";
  639. }
  640. }
  641. limpa();
  642. recomeçar();
  643.  
  644.  
  645. }
  646. }
  647. function limpa(){
  648. for(i=1;i<=9;i++){
  649. document.getElementById('a' + i).innerHTML='&nbsp;';
  650. }
  651. jogada=0;
  652. win=0;
  653. j=0;
  654. k=0;
  655. board = [0, 0, 0, 0, 0, 0, 0, 0, 0];
  656. s=0;
  657. cs=0;
  658. m=0;
  659. h=0;
  660. document.getElementById('cronometro').innerHTML= "00 : 00 : 00 : 00"
  661. }
  662.  
  663. </script>
  664. </body>
  665. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement