You need to sign in or sign up before continuing.
Commit dfee21de by roshka

Tateti en js

parents
Para jugar es obligatorio ingresar nombres para los jugadores, asi se evita problemas. despues de eso se puede jugar sin problema.
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
</head>
<body onload="cargarJugadores()">
<center>
<h1 WIDTH=30% HEIGHT=40>TaTeTi</h1>
<table border="0">
<tr>
<td style="border-style:solid" width="96" Height="128" id="c0" onclick="box(0)"></td>
<td style="border-style:solid" width="96" Height="128" id="c1" onclick="box(1)"></td>
<td style="border-style:solid" width="96" Height="128" id="c2" onclick="box(2)"></td>
</tr>
<tr>
<td style="border-style:solid" width="96" Height="128" id="c3" onclick="box(3)"></td>
<td style="border-style:solid" width="96" Height="128" id="c4" onclick="box(4)"></td>
<td style="border-style:solid" width="96" Height="128" id="c5" onclick="box(5)"></td>
</tr>
<tr>
<td style="border-style:solid" width="96" Height="128" id="c6" onclick="box(6)"></td>
<td style="border-style:solid" width="96" Height="128" id="c7" onclick="box(7)"></td>
<td style="border-style:solid" width="96" Height="128" id="c8" onclick="box(8)"></td>
</tr>
<tr>
<th id="jugador1">Jugador 1</th>
<td></td>
<th id="jugador2">Jugador 2</th>
</tr>
<tr>
<td><img src="http://images.coveralia.com/audio/d/Def_Leppard-X-Frontal.jpg" width="80" Height="100"/></td>
<td></td>
<td><img src="https://steemitimages.com/0x0/https://s5.postimg.cc/5z0fqjfnr/redonda_1.jpg" width="80" Height="100"/></td>
</tr>
</table>
<br />
</center>
<script src="tateti.js"></script>
</body>
</html>
\ No newline at end of file
var img='http://images.coveralia.com/audio/d/Def_Leppard-X-Frontal.jpg' ;
var turno=1;
var arreglo = new Array();
var jug1=0;
var jug2=0;
var jugada = 0;
for(i=0; i<=8; i++){
arreglo[i]=-1;
}
function cargarJugadores(){
do {
jug1=prompt("ingrese el jugador1");
} while (jug1=="");
do {
jug2=prompt('ingrese el jugador2');
} while (jug2=="");
document.getElementById("jugador1").innerHTML=jug1;
document.getElementById("jugador2").innerHTML=jug2;
}
function box(pos){
if(arreglo[pos]==-1){
if(turno==1){
if(img=='http://images.coveralia.com/audio/d/Def_Leppard-X-Frontal.jpg'){
imagen=document.createElement("img");
imagen.src=img;
imagen.width=100;
document.getElementById('c'+pos).appendChild(imagen);
arreglo[pos]=1;
turno=2;
img='https://steemitimages.com/0x0/https://s5.postimg.cc/5z0fqjfnr/redonda_1.jpg';
jugada++;
}
}else if(turno==2){
if(img=='https://steemitimages.com/0x0/https://s5.postimg.cc/5z0fqjfnr/redonda_1.jpg'){
imagen=document.createElement("img");
imagen.src=img;
imagen.width=100;
document.getElementById('c'+pos).appendChild(imagen);
arreglo[pos]=0;
turno=1;
img='http://images.coveralia.com/audio/d/Def_Leppard-X-Frontal.jpg' ;
jugada++;
}
}
}else{ alert('Posicion ocupada!'); }
if(arreglo[0]==1 && arreglo[1]==1 && arreglo[2]==1){
alert('gano X');
jug1=jug1+1;
}
if(arreglo[0]==0 && arreglo[1]==0 && arreglo[2]==0){
alert('gano O');
jug2=jug2+1;
}
if(arreglo[3]==1 && arreglo[4]==1 && arreglo[5]==1){
alert('gano X');
jug1=jug1+1;
}
if(arreglo[3]==0 && arreglo[4]==0 && arreglo[5]==0){
alert('gano O');
jug2=jug2+1;
}
if(arreglo[6]==1 && arreglo[7]==1 && arreglo[8]==1){
alert('gano X');
jug1=jug1+1;
}
if(arreglo[6]==0 && arreglo[7]==0 && arreglo[8]==0){
alert('gano O');
jug2=jug2+1;
}
if(arreglo[0]==1 && arreglo[3]==1 && arreglo[6]==1){
alert('gano X');
jug1=jug1+1;
}
if(arreglo[0]==0 && arreglo[3]==0 && arreglo[6]==0){
alert('gano O');
jug2=jug2+1;
}
if(arreglo[1]==1 && arreglo[4]==1 && arreglo[7]==1){
alert('gano X');
jug1=jug1+1;
}
if(arreglo[1]==0 && arreglo[4]==0 && arreglo[7]==0){
alert('gano O');
jug2=jug2+1;
}
if(arreglo[2]==1 && arreglo[5]==1 && arreglo[8]==1){
alert('gano X');
jug1=jug1+1;
}
if(arreglo[2]==0 && arreglo[5]==0 && arreglo[8]==0){
alert('gano O');
jug2=jug2+1;
}
if(arreglo[0]==1 && arreglo[4]==1 && arreglo[8]==1){
alert('gano X');
jug1=jug1+1;
}
if(arreglo[0]==0 && arreglo[4]==0 && arreglo[8]==0){
alert('gano O');
jug2=jug2+1;
}
if(arreglo[2]==1 && arreglo[4]==1 && arreglo[6]==1){
alert('gano X');
jug1=jug1+1;
}
if(arreglo[2]==0 && arreglo[4]==0 && arreglo[6]==0){
alert('gano O');
jug2=jug2+1;
}
if (jugada == 9) {
alert("Empate")
}
}
\ 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