Commit 2a1fa4c7 by Jose Figueredo

Ultima subida

parent 47421b81
var contador=0;
var ganador=0;
var tablero = new Array(0,0,0,0,0,0,0,0,0);
function reiniciar(tabla){
document.getElementById(tabla).innerHTML="";
}
function insertar(n,event){
if(JuegoFin(tablero))
{
return;
}
casilla=event.target;
if(tablero[n-1]==0 && contador%2==0){
tablero[n-1]=1
contador++;
casilla.innerHTML = "X";
}
else if( tablero[n-1]==0 && contador%2==1)
{
tablero[n-1]=2
contador++;
casilla.innerHTML = "O";
}
if(JuegoFin(tablero) && ganador>0){
document.getElementById('resultado').innerHTML='El ganador es el jugador '+ganador;
}
}
function JuegoFin(tablero){
for(var i=0;i<9;i+=3)
{
if(tablero[i]===tablero[i+1] && tablero[i]===tablero[i+2] && tablero[i]!=0)
{
ganador=tablero[i];
return true;
}
}
for(var i=0;i<3;i++)
{
if(tablero[i]===tablero[i+3] && tablero[i]===tablero[i+6] && tablero[i]!=0) // compara el 0 con el 3 y 6 , simulando una matriz
{
ganador=tablero[i];
return true;
}
}
if(tablero[0]===tablero[4] && tablero[4]==tablero[8] && tablero[0]!=0)
{
ganador=tablero[0];
return true;
}
if(tablero[2]===tablero[4] && tablero[2]===tablero[6] && tablero[2]!=0){
ganador=tablero[2];
return true;
}
if(contador>8)
{
document.getElementById('resultado').innerHTML='EMPATE';
return true;
}
return false;
}
/*
function insertar(id){
miId= id;
contenido= document.getElementById(miId).value;
console.log(contenido);
}
function i(event) {
var casilla = event.target;
if(comprobar(casilla))
{
if(contador%2===0)
{
casilla.innerHTML = "X";
}
else{
casilla.innerHTML="O";
}
contador++;
}
}
function comprobar (casilla){
if(casilla==="X" || casilla==="O"){
return false;
}
return true;
}*/
\ No newline at end of file
h1{
text-align: center;
}
div{
text-align: center;
}
table {
margin: 0 auto;
height: 200px;
width: 200px;
text-align:center;
/* margin: 30px 0 0 100px;*/
}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="estilos.css">
<title>Document</title>
</head>
<body>
<h1>Tateti</h1>
<div>
<table id="tabla" border="1">
<tr>
<td onclick="insertar(1,event)" id="11"> *</td>
<td onclick="insertar(2,event)"id="12"> *</td>
<td onclick="insertar(3,event)" id="13"> *</td>
</tr>
<tr>
<td onclick="insertar(4,event)" id="21">*</td>
<td onclick="insertar(5,event)" id="22">*</td>
<td onclick="insertar(6,event)" id="23">*</td>
</tr>
<tr>
<td onclick="insertar(7,event)" id="31">*</td>
<td onclick="insertar(8,event)" id="32">*</td>
<td onclick="insertar(9,event)" id="33">*</td>
</tr>
</table>
<p>Los * representas casillas vacias</p>
<a href="javascript:location.reload()">
<button>Reiniciar</button></a>
<p id="resultado"></p>
</div>
<script src="app.js">
</script>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment