This repository has been archived by the owner on Oct 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
velha.js
119 lines (96 loc) · 2.72 KB
/
velha.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
var vez = "x";
var tempo = 20;
var x;
function relogio(){
tempo = tempo - 1;
document.getElementById('timer').innerText = tempo;
if (tempo == 0) {
document.getElementById('gameover').innerText = 'VOCÊ PERDEU!!!!!';
clearInterval(x);
tempo = 0
var all = document.getElementsByTagName('button');
for (var i=0, max=all.length; i < max; i++) {
all[i].disabled = true;
}
}
}
var pontoO = 0;
var pontoX = 0;
var empate = 0;
var ultima;
function clicado(botao) {
if (botao.innerText != "")
return; // botão já clicado
if (vez == "x") {
tempo = 21;
botao.innerText = "x";
vez = "o";
} else {
tempo = 21;
botao.innerText = "o";
vez = "x";
}
ultima = botao;
if ( valor(0,0) != "" && valor(0,0) == valor(0,1) && valor(0,1) == valor(0,2) ||
valor(1,0) != "" && valor(1,0) == valor(1,1) && valor(1,1) == valor(1,2) ||
valor(2,0) != "" && valor(2,0) == valor(2,1) && valor(2,1) == valor(2,2) ||
valor(0,0) != "" && valor(0,0) == valor(1,0) && valor(1,0) == valor(2,0) ||
valor(0,1) != "" && valor(0,1) == valor(1,1) && valor(1,1) == valor(2,1) ||
valor(0,2) != "" && valor(0,2) == valor(1,2) && valor(1,2) == valor(2,2) ||
valor(0,0) != "" && valor(0,0) == valor(1,1) && valor(1,1) == valor(2,2) ||
valor(0,2) != "" && valor(0,2) == valor(1,1) && valor(1,1) == valor(2,0)) {
if (vez == "x")
marcarO();
else
marcarX();
} else {
var empatou = true;
for (var x = 0; x <= 2; x++)
for (var y = 0; y <= 2; y++)
if (valor(x,y) == "")
empatou = false;
if (empatou)
marcarE();
}
}
function valor(x, y) {
var botao = document.getElementById("bt_" + x + "_" + y);
return botao.innerText;
}
function marcarX () {
pontoX += 1;
document.getElementById("px").innerText = pontoX;
}
function marcarO () {
pontoO += 1;
document.getElementById("po").innerText = pontoO;
}
function marcarE () {
empate += 1;
document.getElementById("pe").innerText = empate;
}
function inicia(){
document.getElementById('jogo').style.display = "grid";
document.getElementById('boas-vindas').style.display = "none";
x = setInterval(relogio, 1000);
}
function depoisqueacabareinicia() {
vez = "x"
document.getElementById("bt_0_0").innerText = "";
document.getElementById("bt_0_1").innerText = "";
document.getElementById("bt_0_2").innerText = "";
document.getElementById("bt_1_0").innerText = "";
document.getElementById("bt_1_1").innerText = "";
document.getElementById("bt_1_2").innerText = "";
document.getElementById("bt_2_0").innerText = "";
document.getElementById("bt_2_1").innerText = "";
document.getElementById("bt_2_2").innerText = "";
}
function desfazendo(refazer){
ultima.innerText = "";
if(vez == "x"){
vez = "o"
} else {
vez = "x"
}
}