-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjogo da velha.html
164 lines (158 loc) · 3.96 KB
/
jogo da velha.html
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
</head>
<style type="text/css">
div{
width: 200px;
height: 200px;
background-color: grey;
color: white;
}
input{
background-color: white;
width: 64px;
height: 64px;
}
</style>
<body>
Jogo da velha cagado
<div>
<input id="1" type="button" name="1" value="1" onclick="clicou( value )">
<input id="2" type="button" name="1" value="2" onclick="clicou( value )">
<input id="3" type="button" name="1" value="3" onclick="clicou( value )">
<br>
<input id="4" type="button" name="1" value="4" onclick="clicou( value )">
<input id="5" type="button" name="1" value="5" onclick="clicou( value )">
<input id="6" type="button" name="1" value="6" onclick="clicou( value )">
<br>
<input id="7" type="button" name="1" value="7" onclick="clicou( value )">
<input id="8" type="button" name="1" value="8" onclick="clicou( value )">
<input id="9" type="button" name="1" value="9" onclick="clicou( value )">
</div>
<script type="text/javascript">
var b1 = document.getElementById("1")
var b2 = document.getElementById("2")
var b3 = document.getElementById("3")
var b4 = document.getElementById("4")
var b5 = document.getElementById("5")
var b6 = document.getElementById("6")
var b7 = document.getElementById("7")
var b8 = document.getElementById("8")
var b9 = document.getElementById("9")
var x = 'x'
var arrx = []
function clicou(n) {
if (n != x && n != '⚫'){
if (n==1){
console.log('1')
//body.style.background-color = 'red'
b1.value = '❌'
arrx.push(10)
}else if (n==2){
console.log('2')
//body.style.background-color = 'red'
b2.value = '❌'
arrx.push(11)
}else if (n==3){
console.log('3')
//body.style.background-color = 'red'
b3.value = '❌'
arrx.push(12)
}else if (n==4){
console.log('4')
//body.style.background-color = 'red'
b4.value = '❌'
arrx.push(4)
}else if (n==5){
console.log('5')
//body.style.background-color = 'red'
b5.value = '❌'
arrx.push(5)
}else if (n==6){
console.log('6')
//body.style.background-color = 'red'
b6.value = '❌'
arrx.push(6)
}else if (n==7){
console.log('7')
//body.style.background-color = 'red'
b7.value = '❌'
arrx.push(7)
}else if (n==8){
console.log('8')
//body.style.background-color = 'red'
b8.value = '❌'
arrx.push(8)
}else if (n==9){
console.log('9')
//body.style.background-color = 'red'
b9.value = '❌'
arrx.push(9)
}
timer()
}else {
window.alert('Já selecionado!')
}
}
var arr = []
function numeroAleatorio(){
return Math.floor(Math.random()*10)
}
function timer(){
var aleatorio = numeroAleatorio()
if (aleatorio == 0){
aleatorio+=1
}
console.log(aleatorio)
for(var n = 0 ; n < arrx.length; n++){
if (aleatorio == arrx[n]){
console.log('Recusado '+aleatorio)
aleatorio = numeroAleatorio()
//if (aleatorio == 0){aleatorio+=1}
n = 0
}
}
console.log('Passou no quadrado'+aleatorio)
for(var n = 0 ; n < arr.length; n++){
if (aleatorio == arr[n]){
console.log('Recusado '+aleatorio)
aleatorio = numeroAleatorio()
//if (aleatorio == 0){aleatorio+=1}
n = 0
}
}
console.log('Passou no bola'+aleatorio)
if(aleatorio == 1){
b1.value = '⚫'
arr.push(1)
}else if(aleatorio == 2){
b2.value = '⚫'
arr.push(2)
}else if(aleatorio == 3){
b3.value = '⚫'
arr.push(3)
}else if(aleatorio == 4){
b4.value = '⚫'
arr.push(4)
}else if(aleatorio == 5){
b5.value = '⚫'
arr.push(5)
}else if(aleatorio == 6){
b6.value = '⚫'
arr.push(6)
}else if(aleatorio == 7){
b7.value = '⚫'
arr.push(7)
}else if(aleatorio == 8){
b8.value = '⚫'
arr.push(8)
}else if(aleatorio == 9){
b9.value = '⚫'
arr.push(9)
}
}
</script>
</body>
</html>