Game logic started

This commit is contained in:
2021-11-23 18:54:50 -03:00
commit b3d77158b6
3 changed files with 98 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/node_modules
/package-lock.json

81
index.js Normal file
View File

@@ -0,0 +1,81 @@
const inquirer = require('inquirer')
const messagesList = {
welcome: {
english: 'Welcome to the Rock Paper and Scissors CLI game!',
spanish: '¡Bienvenido al juego de Piedra Papel o Tijeras desde la consola!'
},
play: {
english: 'Select one option:',
spanish: 'Selecciona una opción'
},
options: {
english: ['Rock', 'Paper', 'Scissors'],
spanish: ['Piedra', 'Papel', 'Tijeras']
},
tie: {
english: 'The result is a draw! GG',
spanish: 'Empate! Bien Jugado.'
}
}
function victoryMessage() {
console.log(' ' + messagesList.victory[languageSelection])
}
// function translateOption() {
// }
inquirer.prompt({
name: 'languageSelect',
message: 'Select language:',
default: 'English',
type: 'list',
choices: ['English', 'Spanish']
})
.then((answer) => {
const languageSelection = answer.languageSelect.toLowerCase()
console.log('')
console.log(' ' + messagesList.welcome[languageSelection])
console.log('')
const options = [...messagesList.options[languageSelection]]
inquirer.prompt({
name: 'userSelecction',
message: messagesList.play[languageSelection],
type: 'list',
choices: options
})
.then((answer) => {
const computerSelection = options[Math.floor(Math.random() * options.length)]
const userSelection = answer.userSelecction
if (computerSelection === userSelection) {
console.log(' ' + messagesList.tie[languageSelection])
return
}
})
})

15
package.json Normal file
View File

@@ -0,0 +1,15 @@
{
"name": "py-42-rock-paper-and-scissors-cli-game",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"inquirer": "^8.2.0"
}
}