JavaScript - Juego del gato (ayuda)

 
Vista:
sin imagen de perfil
Val: 4
Ha aumentado su posición en 29 puestos en JavaScript (en relación al último mes)
Gráfica de JavaScript

Juego del gato (ayuda)

Publicado por Agustin (3 intervenciones) el 13/10/2019 08:59:10
Soy principiante en programacion y en mi carrera me piden hacer un juego del gato (tic-tac-toe)

Ya lo tengo hecho, pero por alguna razon no funciona. Solo funciona visualmente la interfaz pero las funciones basicas y las advertencias no funcionan. Alguien puede tener tiempo para ver que hice mal y si es poslble pasarme todo el codigo como debería de estar escrito para que funcione? de esa forma podré aprender que es lo que me falta hacer bien y entregar el trabajo en condiciones (perdon por el desorden de abajo)

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
165
166
167
168
<html>
<head>
<title>Juego del Gato</title>
<style type="text/css">
section#principal{
  display: inline-block;
  margin: 0 auto;
  text-align: center;
  width: 100%;
}
article#comandos{
  border: 1px solid lightgray;
  display: inline-block;
  min-height: 300px;
  vertical-align: tap;
  width: 25%;
}
article#tablero{
  border: 1px solid lightblue;
  display: inline-block;
  margin: 0 auto;
  text-align: center;
  width: 50%;
}
article#tablero input{
  font-size: 3em;
  height: 80px;
  margin: 10px;
  width: 80px;
}
input[type="button"]#iniciar{
  font-size: 0.8em;
  margin-top: 2em;
  padding: 0.7em;
}
input[type="text"]{
  font-size: 1em;
  margin: 0.3em;
  padding: 0.1em;
}
label{
  font-size: 1em;
  font-weight: bold;
  text-align: center;
}
.botonInicial{
color: #77d;
background-color: #77d;
}
.botonJugador1{
  color: white;
  background-color: #d77;
}
.botonJugador2{
color: white;
background-color: #7d7;
}
</style>
<script type="text/javascript">
var bandera = false;//Indica si el juego inicio
var turno = 0; //Determina el turno
var tablero = new Array (); //Arreglo de botones
window.onload = function(){
  var iniciar = document.getelementById("iniciar");
  iniciar.addEventlistener("click",comenzar);
}
function comenzar(){
  bandera = true;
  var Jugador1 = document.getElementById("jugador1");
  var jugador2 = document.getElementById("jugador2");
  if(jugador1.value==""){
    alert("Falta el nombre del jugador 1");
    jugador1.focus();
  }else{
    if(jugador2.value==""){
      alert("Falta el nombre del jugador 2");
      jugador2.focus();
    }else{
      tab[0] = document.getElementById("b0");
      tab[1] = document.getElementById("b1");
      tab[2] = document.getElementById("b2");
      tab[3] = document.getElementById("b3");
      tab[4] = document.getElementById("b4");
      tab[5] = document.getElementById("b5");
      tab[6] = document.getElementById("b6");
      tab[7] = document.getElementById("b7");
      tab[8] = document.getElementById("b8");
      for(var i=0;i<9;i++){
        tab[i].className = "botonInicial";
        tab[i].value = "i";
      }
      turno = 1;
      document.getElementById("turnoJugador").innerHTML = "Adelante Jugador " + jugador1.value;
    }
  }
  revisar();
}
function colocar(boton){
  if(bandera==true){
    if(turno==1 && boton.value=="I")
    turno = 2;
    document.getElementById("turnoJugador").innerHTML = "Adelante Jugador " +jugador2.value;
    boton.value = "x";
    boton.className = "botonJugador1";
  }else{
    if(turno==2 && boton.value=="I"){
    turno = 1;
    document.getElementById("turnoJugador").innerHTML = "Adelante Jugador " +jugador1.value;
    boton.value = "O";
    boton.className = "botonJugador2";
    }
  }
}
function revisar(){
  if((tab[0].value =="x" && tab[1].value=="x" && tab[2].value=="X")
  || (tab[3].value =="x" && tab[4].value=="x" && tab[5].value=="X")
  || (tab[6].value =="x" && tab[7].value=="x" && tab[8].value=="X")
  || (tab[0].value =="x" && tab[3].value=="x" && tab[6].value=="X")
  ||(tab[1].value =="x" && tab[4].value=="x" && tab[7].value=="X")
  ||(tab[2].value =="x" && tab[5].value=="x" && tab[8].value=="X")
  || (tab[0].value =="x" && tab[4].value=="x" && tab[8].value=="X")
  ||(tab[2].value =="x" && tab[4].value=="x" && tab[6].value=="X")
  ){
    alert("Felicidades ganaste Jugador " + jugador1.value);
    bandera = false;
  }
  if((tab[0].value =="o" && tab[1].value=="o" && tab[2].value=="X")
  || (tab[3].value =="o" && tab[4].value=="o" && tab[5].value=="X")
  || (tab[6].value =="o" && tab[7].value=="o" && tab[8].value=="X")
  || (tab[0].value =="o" && tab[3].value=="o" && tab[6].value=="X")
  ||(tab[1].value =="o" && tab[4].value=="o" && tab[7].value=="X")
  ||(tab[2].value =="o" && tab[5].value=="o" && tab[8].value=="X")
  || (tab[0].value =="o" && tab[4].value=="o" && tab[8].value=="X")
  ||(tab[2].value =="o" && tab[4].value=="o" && tab[6].value=="X")
  ){
    alert("Felicidades ganaste Jugador " + jugador2.value);
    bandera = false;
  }
}
</script>
</head>
<body>
<section id="principal">
  <article id="comandos">
Jugador 1:
<input type="text" id="Jugador1"><br>
Jugador 2:
<input type="text" id="Jugador2"><br>
<input type="button" id="iniciar" value="Comenzar">
<label id="turnoJugador"></label>
  </article>
  <article id="tablero">
<input type="button" id="b0" onclick="colocar(this)">
<input type="button" id="b1" onclick="colocar(this)">
<input type="button" id="b2" onclick="colocar(this)"><br>
 
<input type="button" id="b3" onclick="colocar(this)">
<input type="button" id="b4" onclick="colocar(this)">
<input type="button" id="b5" onclick="colocar(this)"><br>
 
<input type="button" id="b6" onclick="colocar(this)">
<input type="button" id="b7" onclick="colocar(this)">
<input type="button" id="b8" onclick="colocar(this)"><br>
  </article>
 
</section>
</body>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de joel
Val: 3.506
Oro
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

Juego del gato (ayuda)

Publicado por joel (895 intervenciones) el 13/10/2019 20:53:58
Hola Agustin, si miras la consola del navegador, veras que tienes un error...
No es:
1
getelementById
es
1
getElementById

No es:
1
addEventlistener
es
1
addEventListener

No se si hay mas errores...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 4
Ha aumentado su posición en 29 puestos en JavaScript (en relación al último mes)
Gráfica de JavaScript

Juego del gato (ayuda)

Publicado por Agustin (3 intervenciones) el 14/10/2019 00:48:45
Corregí esos errores pero aun asi no funciona el juego

aun asi gracias por responder
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar