diff --git b/main.css a/main.css new file mode 100644 index 0000000..4793333 --- /dev/null +++ a/main.css @@ -0,0 +1,17 @@ +table +{ + width: 200px; + height: 200px; + text-align: center; + border: 2px solid black; +} + +td +{ + background-color: black; + color:white; + width: 32px; + height: 32px; + font-size: 28px; + align: center; +} \ No newline at end of file diff --git b/main.js a/main.js new file mode 100644 index 0000000..a402782 --- /dev/null +++ a/main.js @@ -0,0 +1,79 @@ +var jugador = 1; + +function resetearJugador(){ + jugador = 1; +} + +//Cambia el HTML de la celda clickeada a X o O, dependiendo del turno del jugador +function escribirCelda(celdaElegida){ + if(celdaElegida.innerHTML.length > 0){ + alert("La celda ya fue elegida"); + return false; + }if(jugador === 1){ + celdaElegida.innerHTML = "X"; + jugador = 2; + }else if(jugador === 2){ + celdaElegida.innerHTML = "O"; + jugador = 1; + } + verGanador(); +} +//Crea una matriz del tateti, y analiza todas las posiblidades, para saber si hay un ganador. +//Avisa que hay un ganador, si hay +function verGanador(){ + var celda1 = document.getElementById("celda1"); + var celda2 = document.getElementById("celda2"); + var celda3 = document.getElementById("celda3"); + var celda4 = document.getElementById("celda4"); + var celda5 = document.getElementById("celda5"); + var celda6 = document.getElementById("celda6"); + var celda7 = document.getElementById("celda7"); + var celda8 = document.getElementById("celda8"); + var celda9 = document.getElementById("celda9"); + + var valoresTateti = [[celda1.innerHTML, celda2.innerHTML, celda3.innerHTML], + [celda4.innerHTML, celda5.innerHTML, celda6.innerHTML], + [celda7.innerHTML, celda8.innerHTML, celda9.innerHTML]] + + + //HORIZONTALES + for (var i = 0; i < 3; i++) { + if(valoresTateti[i][0] === valoresTateti[i][1] && valoresTateti[i][0] === valoresTateti[i][2]){ + if(valoresTateti[i][0] === "X"){ + var ban = 1; + alert("Gano el jugador 1"); + }else if (valoresTateti[i][0] === "O"){ + var ban = 1; + alert("Gano el jugador 2"); + } + } + //VERTICALES + else if(valoresTateti[0][i] === valoresTateti[1][i] && valoresTateti[0][i] === valoresTateti[2][i]){ + if(valoresTateti[0][i] === "X"){ + var ban = 1; + alert("Gano el jugador 1"); + }else if (valoresTateti[0][i] === "O"){ + var ban = 1; + alert("Gano el jugador 2"); + } + } + + } + //DIAGONALES + if(ban != 1){ + if (valoresTateti[0][0] === valoresTateti[1][1] && valoresTateti[0][0] === valoresTateti[2][2]) { + if(valoresTateti[0][0] === "X"){ + alert("Gano el jugador 1"); + }else if (valoresTateti[0][0] === "O"){ + alert("Gano el jugador 2"); + } + }else if (valoresTateti[0][2] === valoresTateti[1][1] && valoresTateti[0][2] === valoresTateti[2][0]) { + if(valoresTateti[0][2] === "X"){ + alert("Gano el jugador 1"); + }else if (valoresTateti[0][2] === "O"){ + alert("Gano el jugador 2"); + } + } + } + +} \ No newline at end of file diff --git b/tateti.html a/tateti.html new file mode 100644 index 0000000..dfa0754 --- /dev/null +++ a/tateti.html @@ -0,0 +1,45 @@ + + Tateti + + + + +

Enzo's Tateti

+ + + + + + + + + + + + + + + + +
+
+ + + \ No newline at end of file