commit b3d77158b61b9b478217830a1d31cc5f0fb61877 Author: Francisco Pessano Date: Tue Nov 23 18:54:50 2021 -0300 Game logic started diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..49e0fc6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/node_modules +/package-lock.json \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..4a8ea69 --- /dev/null +++ b/index.js @@ -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 + } + + }) + }) \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..680c02b --- /dev/null +++ b/package.json @@ -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" + } +}