mirror of
https://github.com/FranP-code/Rock-Paper-and-Scissors-CLI-Game.git
synced 2025-10-13 00:32:38 +00:00
Game logic started
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/node_modules
|
||||
/package-lock.json
|
||||
81
index.js
Normal file
81
index.js
Normal 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
15
package.json
Normal 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"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user