-
-
Save AndersonFlores2006/0f542be4fe5ef9714ca3f44a3b894726 to your computer and use it in GitHub Desktop.
desafio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ANTES DE EMPEZAR: | |
//Copia este código base completo en un nuevo archivo llamado desafio.js | |
//-----------------------------------------------------------------------// | |
//JUGADORES: | |
// NO MODIFICAR LOS NOMBRES DE ESTOS OBJETOS | |
// (El test automático les cambia los valores para probar que el resto | |
// de la lógica funcione bien) | |
const jugadorUno = { | |
nombre: "Marce", | |
habilidades: { | |
ataque: 70, | |
velocidad: 30, | |
vida: 60, | |
magia: 120, | |
}, | |
articulos: ["espada", "escudo", "varita"], | |
}; | |
const jugadorDos = { | |
nombre: "Flor", | |
habilidades: { | |
ataque: 73, | |
velocidad: 30, | |
vida: 80, | |
magia: 100, | |
}, | |
articulos: ["escudo", "varita", "capa", "pocion"], | |
}; | |
//-----------------------------------------------------------------------// | |
//PUNTOS INICIALES DEL JUEGO: | |
//Estas variables servirán para almacenar los puntos ganados por cada jugador. | |
//Cada vez que un jugador gana en una habilidad determinada se deberá | |
//sumar 1 punto en el contador correspondiente: | |
let contadorPuntosJug1 = 0; | |
let contadorPuntosJug2 = 0; | |
//Ganador: | |
let ganador; | |
//-----------------------------------------------------------------------// | |
//COMPARACIÓN POR PODER DE ATAQUE | |
const habilidadesACompararJugador1 = jugadorUno.habilidades.ataque; | |
const habilidadesACompararJugador2 = jugadorDos.habilidades.ataque; | |
if (habilidadesACompararJugador1 > habilidadesACompararJugador2) { | |
contadorPuntosJug1++; | |
} else if (habilidadesACompararJugador1 < habilidadesACompararJugador2) { | |
contadorPuntosJug2++; | |
} else { | |
contadorPuntosJug1++; | |
contadorPuntosJug2++; | |
} | |
//-----------------------------------------------------------------------// | |
//COMPARACIÓN POR VELOCIDAD: | |
const velocidadCompararJugador1 = jugadorUno.habilidades.velocidad; | |
const velocidadACompararJugador2 = jugadorDos.habilidades.velocidad; | |
if (velocidadCompararJugador1 > velocidadACompararJugador2) { | |
contadorPuntosJug1++; | |
} else if (velocidadCompararJugador1 < velocidadACompararJugador2) { | |
contadorPuntosJug2++; | |
} else { | |
contadorPuntosJug1++; | |
contadorPuntosJug2++; | |
} | |
//-----------------------------------------------------------------------// | |
//COMPARACIÓN POR NIVEL DE VIDA: | |
const vidaACompararJugador1 = jugadorUno.habilidades.vida; | |
const vidaACompararJugador2 = jugadorDos.habilidades.vida; | |
if (vidaACompararJugador1 > vidaACompararJugador2) { | |
contadorPuntosJug1++; | |
} else if (vidaACompararJugador1 < vidaACompararJugador2) { | |
contadorPuntosJug2++; | |
} else { | |
contadorPuntosJug1++; | |
contadorPuntosJug2++; | |
} | |
//-----------------------------------------------------------------------// | |
//COMPARACIÓN POR MAGIA: | |
const magiaACompararJugador1 = jugadorUno.habilidades.magia; | |
const magiaACompararJugador2 = jugadorDos.habilidades.magia; | |
if (magiaACompararJugador1 > magiaACompararJugador2) { | |
contadorPuntosJug1++; | |
} else if (magiaACompararJugador1 < magiaACompararJugador2) { | |
contadorPuntosJug2++; | |
} else { | |
contadorPuntosJug1++; | |
contadorPuntosJug2++; | |
} | |
//-----------------------------------------------------------------------// | |
//COMPARACIÓN POR CANTIDAD DE ARTÍCULOS | |
const articulosACompararJugador1 = jugadorUno.articulos.length; | |
const articulosACompararJugador2 = jugadorDos.articulos.length; | |
if (articulosACompararJugador1 > articulosACompararJugador2) { | |
contadorPuntosJug1++; | |
} else if (articulosACompararJugador1 < articulosACompararJugador2) { | |
contadorPuntosJug2++; | |
} else { | |
contadorPuntosJug1++; | |
contadorPuntosJug2++; | |
} | |
//-----------------------------------------------------------------------// | |
//DEFINIENDO EL GANADOR DE LA PARTIDA | |
//En este espacio deberás generar la comparación final de puntos | |
//que determine al ganador. Mostrar en la terminal el nombre del jugador que ganó la partida | |
let nombreDeJug1 = jugadorUno.nombre; | |
let nombreDeJug2 = jugadorDos.nombre; | |
if (contadorPuntosJug1 > contadorPuntosJug2) { | |
ganador = nombreDeJug1; | |
} else if (contadorPuntosJug1 < contadorPuntosJug2) { | |
ganador = nombreDeJug2; | |
} else { | |
ganador = "Empate"; | |
} | |
console.log("El ganador es:", ganador); | |
//-----------------------------------------------------------------------// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment