From 88a90ac558702a84321290f4a99144f7f308e69a Mon Sep 17 00:00:00 2001 From: silviabarrientos Date: Thu, 10 Sep 2020 18:16:00 -0400 Subject: [PATCH] add js-e004 --- css/styles.css | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ js/javaScript.js | 225 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ js/javaScript2.js | 281 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tateti.html | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 617 insertions(+) create mode 100644 css/styles.css create mode 100644 js/javaScript.js create mode 100644 js/javaScript2.js create mode 100644 tateti.html diff --git a/css/styles.css b/css/styles.css new file mode 100644 index 0000000..863003e --- /dev/null +++ b/css/styles.css @@ -0,0 +1,62 @@ +header { + height: 100px; + background-color: dodgerblue; + margin: 0; + display: flex; + justify-content: space-between; +} + +h1 { + margin-top: 30px; + margin-left: 90px; + color: white; +} + + +table { + display: grid; + grid-template-columns: repeat(2,1fr); + justify-content: center; + padding-top: 50px; + padding-left: 100px ; +} + + + + +button { + width: 70px; + height: 70px; + font-size: xx-large; + color: dodgerblue; +} + + + + +.com { + margin-left: 100px; + width: 200px; +} + +.estboton { + width: 150px; + margin-right: 20px; + margin-top: 50px; + background-color: dodgerblue; + color: white; + border-radius: 10px; + font-size: x-large; +} + +.com { + margin-left: 120px; + width: 200px; +} + +.XO { + margin-top: 50px; + background-color: white; + color: dodgerblue; + border-radius: 10px; +} diff --git a/js/javaScript.js b/js/javaScript.js new file mode 100644 index 0000000..19e4d18 --- /dev/null +++ b/js/javaScript.js @@ -0,0 +1,225 @@ +function init(){ + + var turno = 1; + var filas = [0,0,0]; + var columnas = [0,0,0]; + var diagonales = [0,0,0]; + + + + jug1.onclick = function(){ + var nombre = prompt("Ingresa nombre"); + while(nombre == ""){ + nombre = prompt("Debe ingresa nombre"); + } + jug1.textContent = nombre; + } + jug2.onclick = function(){ + var nombre = prompt("Ingresa nombre"); + while(nombre == ""){ + nombre = prompt("Debe ingresa nombre"); + } + jug2.textContent = nombre; + } + xo1.onclick = function (){ + if(xo1.textContent !== 'X' && xo1.textContent !== 'O'){ + textContent = 'X'; + } + if(xo1.textContent == 'X'){ + xo1.textContent = 'O'; + }else{ + xo1.textContent = 'X'; + } + } + xo2.onclick = function (){ + if(xo2.textContent !== 'X' && xo2.textContent !== 'O'){ + xo2.textContent = 'X'; + } + if(xo2.textContent == 'X'){ + xo2.textContent = 'O'; + }else{ + xo2.textContent = 'X'; + } + } + comenzar.onclick = function(){ + var val = true; + while(jug1.textContent == ""){ + alert("Jugador 1 debe ingresar un nombre"); + val = false; + break; + } + while(jug2.textContent == ""){ + alert("Jugador 2 debe ingresar un nombre"); + val = false; + break; + } + while(xo1.textContent !== 'X' && xo1.textContent !== 'O'){ + alert("Jugador 1 debe escoger X o O"); + val = false; + break; + } + while(xo2.textContent !== 'X' && xo2.textContent !== 'O'){ + alert("Jugador 2 debe escoger X o O"); + val = false; + break; + } + while(xo1.textContent == xo2.textContent ){ + alert("Jugador 2 debe escoger distinta opcion a jugador 1"); + val = false; + break; + } + if(val == true){ + inicio(); + } + } + function inicio(){ + var i = 0; + A1.onclick = function(){ + + if(turno == 1){ + A1.textContent = 'X' + }else { + A1.textContent = 'O' + } + analizar(); + cambiarTurno(); + i++; + } + A2.onclick = function(){ + if(turno == 1){ + A2.textContent = 'X' + }else { + A2.textContent = 'O' + } + analizar(); + cambiarTurno(); + i++; + } + A3.onclick = function(){ + if(turno == 1){ + A3.textContent = 'X' + }else { + A3.textContent = 'O' + } + analizar(); + cambiarTurno(); + i++; + } + B1.onclick = function(){ + if(turno == 1){ + B1.textContent = 'X' + }else { + B1.textContent = 'O' + } + analizar(); + cambiarTurno(); + i++; + } + B2.onclick = function(){ + if(turno == 1){ + B2.textContent = 'X' + }else { + B2.textContent = 'O' + } + analizar(); + cambiarTurno(); + i++; + } + B3.onclick = function(){ + if(turno == 1){ + B3.textContent = 'X' + }else { + B3.textContent = 'O' + } + analizar(); + cambiarTurno(); + i++; + } + C1.onclick = function(){ + if(turno == 1){ + C1.textContent = 'X' + }else { + C1.textContent = 'O' + } + analizar(); + cambiarTurno(); + i++; + } + C2.onclick = function(){ + if(turno == 1){ + C2.textContent = 'X' + }else { + C2.textContent = 'O' + } + analizar(); + cambiarTurno(); + i++; + } + C3.onclick = function(){ + if(turno == 1){ + C3.textContent = 'X' + }else { + C3.textContent = 'O' + } + analizar(); + cambiarTurno(); + i++; + } + + function cambiarTurno(){ + if(turno == 1){ + turno = 0; + }else{ + turno = 1; + } + } + alert("EMPATE"); + } + + function analizar(){ + + if((A1.textContent == 'X') && (A2.textContent == 'X') && (A3.textContent == 'X')){ + alert("EL GANADOR ES: X"); + }else if((A1.textContent == 'O') && (A2.textContent == 'O') && (A3.textContent == 'O')){ + alert("EL GANADOR ES: O"); + } + if((B1.textContent == 'X') && (B2.textContent == 'X') && (B3.textContent == 'X')){ + alert("EL GANADOR ES: X"); + }else if((B1.textContent == 'O') && (B2.textContent == 'O') && (B3.textContent == 'O')){ + alert("EL GANADOR ES: O"); + } + if((C1.textContent == 'X') && (C2.textContent == 'X') && (C3.textContent == 'X')){ + alert("EL GANADOR ES: X"); + }else if((C1.textContent == 'O') && (C2.textContent == 'O') && (C3.textContent == 'O')){ + alert("EL GANADOR ES: O"); + } + if((A1.textContent == 'X') && (B1.textContent == 'X') && (C1.textContent == 'X')){ + alert("EL GANADOR ES: X"); + }else if((A1.textContent == 'O') && (B1.textContent == 'O') && (C1.textContent == 'O')){ + alert("EL GANADOR ES: O"); + } + if((A2.textContent == 'X') && (B2.textContent == 'X') && (C2.textContent == 'X')){ + alert("EL GANADOR ES: X"); + }else if((A2.textContent == 'O') && (B2.textContent == 'O') && (C2.textContent == 'O')){ + alert("EL GANADOR ES: O"); + } + if((A3.textContent == 'X') && (B3.textContent == 'X') && (C3.textContent == 'X')){ + alert("EL GANADOR ES: X"); + }else if((A3.textContent == 'O') && (B3.textContent == 'O') && (C3.textContent == 'O')){ + alert("EL GANADOR ES: O"); + } + if((A1.textContent == 'X') && (B2.textContent == 'X') && (C3.textContent == 'X')){ + alert("EL GANADOR ES: X"); + }else if((A1.textContent == 'O') && (B2.textContent == 'O') && (C3.textContent == 'O')){ + alert("EL GANADOR ES: O"); + } + if((A3.textContent == 'X') && (B2.textContent == 'X') && (C1.textContent == 'X')){ + alert("EL GANADOR ES: X"); + }else if((A3.textContent == 'O') && (B2.textContent == 'O') && (C1.textContent == 'O')){ + alert("EL GANADOR ES: O"); + } + } + + + +} \ No newline at end of file diff --git a/js/javaScript2.js b/js/javaScript2.js new file mode 100644 index 0000000..142568b --- /dev/null +++ b/js/javaScript2.js @@ -0,0 +1,281 @@ +function init(){ + + var turno = 1; + var array = Array(3); + for(var i = 0; i < array.length; i++){ + array[i] = Array(3); + } + for(var i = 0; i < array.length; i++){ + for(var k = 0; k < array.length; k++){ + array[i][k] = -1; + } + } + + + jug1.onclick = function(){ + var nombre = prompt("Ingresa nombre"); + while(nombre == ""){ + nombre = prompt("Debe ingresa nombre"); + } + jug1.textContent = nombre; + } + jug2.onclick = function(){ + var nombre = prompt("Ingresa nombre"); + while(nombre == ""){ + nombre = prompt("Debe ingresa nombre"); + } + jug2.textContent = nombre; + } + xo1.onclick = function (){ + if(xo1.textContent !== 'X' && xo1.textContent !== 'O'){ + textContent = 'X'; + } + if(xo1.textContent == 'X'){ + xo1.textContent = 'O'; + }else{ + xo1.textContent = 'X'; + } + } + xo2.onclick = function (){ + if(xo2.textContent !== 'X' && xo2.textContent !== 'O'){ + xo2.textContent = 'X'; + } + if(xo2.textContent == 'X'){ + xo2.textContent = 'O'; + }else{ + xo2.textContent = 'X'; + } + } + comenzar.onclick = function(){ + var val = true; + while(jug1.textContent == ""){ + alert("Jugador 1 debe ingresar un nombre"); + val = false; + break; + } + while(jug2.textContent == ""){ + alert("Jugador 2 debe ingresar un nombre"); + val = false; + break; + } + while(xo1.textContent !== 'X' && xo1.textContent !== 'O'){ + alert("Jugador 1 debe escoger X o O"); + val = false; + break; + } + while(xo2.textContent !== 'X' && xo2.textContent !== 'O'){ + alert("Jugador 2 debe escoger X o O"); + val = false; + break; + } + while(xo1.textContent == xo2.textContent ){ + alert("Jugador 2 debe escoger distinta opcion a jugador 1"); + val = false; + break; + } + if(val == true){ + inicio(); + } + } + function inicio(){ + A1.onclick = function(){ + if(turno == 1){ + A1.textContent = 'X'; + array[0][0] = 1; + }else { + A1.textContent = 'O'; + array[0][0] = 2; + } + analizar(); + cambiarTurno(); + } + A2.onclick = function(){ + if(turno == 1){ + A2.textContent = 'X'; + array[0][1] = 1; + }else { + A2.textContent = 'O'; + array[0][1] = 2; + } + analizar(); + cambiarTurno(); + } + A3.onclick = function(){ + if(turno == 1){ + A3.textContent = 'X'; + array[0][2] = 1; + }else { + A3.textContent = 'O'; + array[0][2] = 2; + } + analizar(); + cambiarTurno(); + } + B1.onclick = function(){ + if(turno == 1){ + B1.textContent = 'X'; + array[1][0] = 1; + }else { + B1.textContent = 'O'; + array[1][0] = 2; + } + analizar(); + cambiarTurno(); + } + B2.onclick = function(){ + if(turno == 1){ + B2.textContent = 'X'; + array[1][1] = 1; + }else { + B2.textContent = 'O'; + array[1][1] = 2; + } + analizar(); + cambiarTurno(); + } + B3.onclick = function(){ + if(turno == 1){ + B3.textContent = 'X'; + array[1][2] = 1; + }else { + B3.textContent = 'O'; + array[1][2] = 2; + } + analizar(); + cambiarTurno(); + } + C1.onclick = function(){ + if(turno == 1){ + C1.textContent = 'X'; + array[2][0] = 1; + }else { + C1.textContent = 'O' + array[2][0] = 2; + } + analizar(); + cambiarTurno(); + } + C2.onclick = function(){ + if(turno == 1){ + C2.textContent = 'X'; + array[2][1] = 1; + }else { + C2.textContent = 'O'; + array[2][1] = 2; + } + analizar(); + cambiarTurno(); + } + C3.onclick = function(){ + if(turno == 1){ + C3.textContent = 'X'; + array[2][2] = 1; + }else { + C3.textContent = 'O'; + array[2][2] = 2; + } + analizar(); + cambiarTurno(); + } + + function cambiarTurno(){ + if(turno == 1){ + turno = 0; + }else{ + turno = 1; + } + } + + } + function analizar(){ + var puntos = 0; + var ganador; + if(turno == 1){ + puntos = 3; + ganador = 'X'; + }else{ + puntos = 6; + ganador = 'O'; + } + if(filas()){ + alert("EL GANADOR ES: " + ganador); + } + if(columnas()){ + alert("EL GANADOR ES: " + ganador); + } + if(diagonales()){ + alert("EL GANADOR ES: " + ganador); + } + if(empate()){ + alert("EMPATE"); + } + function empate(){ + for(var i = 0; i < array.length; i++){ + for(var k = 0; k < array.length; k++){ + if(array[i][k] == -1){ + return false; + } + } + } + return true; + } + function filas(){ + var sum1 = 0; + var sum2 = 0; + var sum3 = 0; + for(var i = 0; i < array.length; i++){ + sum1 += array[0][i]; + sum2 += array[1][i]; + sum3 += array[2][i]; + } + if(sum1 == puntos){ + return true; + }else if(sum2 == puntos){ + return true; + }else if(sum3 == puntos){ + return true; + }else { + return false; + } + } + function columnas(){ + var sum1 = 0; + var sum2 = 0; + var sum3 = 0; + for(var i = 0; i < array.length; i++){ + sum1 += array[i][0]; + sum2 += array[i][1]; + sum3 += array[i][2]; + } + if(sum1 == puntos){ + return true; + }else if(sum2 == puntos){ + return true; + }else if(sum3 == puntos){ + return true; + }else { + return false; + } + } + function diagonales(){ + var sum1 = 0; + var sum2 = 0; + for(var i = 0; i < array.length; i++){ + sum1 += array[i][i]; + } + for(var i = 0; i < array.length; i++){ + sum2 += array[i][(array.length - 1) - i]; + } + if(sum1 == puntos){ + return true; + }else if(sum2 == puntos){ + return true; + }else{ + return false; + } + } + } + + + +} \ No newline at end of file diff --git a/tateti.html b/tateti.html new file mode 100644 index 0000000..a402ede --- /dev/null +++ b/tateti.html @@ -0,0 +1,49 @@ + + + + + + TATETI + + + + +
+

TA-TE-TI

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + \ No newline at end of file -- libgit2 0.26.0