Skip to content

Commit

Permalink
Merge branch 'mouredev:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanb55 authored Mar 22, 2024
2 parents 52776a1 + 2bd7e99 commit f0838b7
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Crea un programa que calcule quien gana más partidas al piedra,
// papel, tijera, lagarto, spock.
// - El resultado puede ser: "Player 1", "Player 2", "Tie" (empate)
// - La función recibe un listado que contiene pares, representando cada jugada.
// - El par puede contener combinaciones de "🗿" (piedra), "📄" (papel),
// "✂️" (tijera), "🦎" (lagarto) o "🖖" (spock).
// - Ejemplo. Entrada: [("🗿","✂️"), ("✂️","🗿"), ("📄","✂️")]. Resultado: "Player 2".
// - Debes buscar información sobre cómo se juega con estas 5 posibilidades.

const winsAgainst = {
'🗿': ['✂️', '🦎'],
'📄': ['🗿', '🖖'],
'✂️': ['📄', '🦎'],
'🦎': ['📄', '🖖'],
'🖖': ['✂️', '🗿'],
};

function playGame(gameArray) {
let player1Score = 0;
let player2Score = 0;
for (let i = 0; i < gameArray.length; i++) {
const player1Emoji = gameArray[i][0];
const player2Emoji = gameArray[i][1];
console.log(`Game ${i + 1}:`);
console.log(`Player1: ${player1Emoji} | Player2: ${player2Emoji}`);
if (winsAgainst[player1Emoji].includes(player2Emoji)) {
console.log('Point for player 1');
player1Score++;
} else {
console.log('Point for player 2');
player2Score++;
}
console.log('---------------------------');
}
console.log('===========================');
if (player1Score > player2Score) {
console.log('🏆 Player 1 wins the game!');
} else if (player2Score > player1Score) {
console.log('🏆 Player 2 wins the game!');
} else {
console.log("It's a tie!");
}
}

const gameInput = [
['🗿', '✂️'],
['✂️', '🗿'],
['📄', '✂️'],
];

playGame(gameInput);

0 comments on commit f0838b7

Please sign in to comment.