mirror of
https://github.com/FranP-code/Rock-Paper-and-Scissors-CLI-Game.git
synced 2025-10-13 00:32:38 +00:00
Play again option added
This commit is contained in:
95
index.js
95
index.js
@@ -68,29 +68,36 @@ const messagesList = {
|
|||||||
|
|
||||||
english: ' - Defeat count: ',
|
english: ' - Defeat count: ',
|
||||||
spanish: ' - Derrotas: ',
|
spanish: ' - Derrotas: ',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
playAgain: {
|
||||||
|
|
||||||
|
title: {
|
||||||
|
|
||||||
|
english: 'Do you wanna play again?',
|
||||||
|
spanish: '¿Quieres jugar otra vez?'
|
||||||
|
},
|
||||||
|
|
||||||
|
options: {
|
||||||
|
|
||||||
|
english: ['Yes', 'No'],
|
||||||
|
spanish: ['Sí', 'No']
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
thanksForPlay: {
|
||||||
|
|
||||||
|
english: 'Thanks for playing! Francisco Pessano',
|
||||||
|
spanish: 'Gracias por jugar! Francisco Pessano'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
victoryCount = 0
|
victoryCount = 0
|
||||||
consecutiveVictoryCount = 0
|
consecutiveVictoryCount = 0
|
||||||
defeatCount = 0
|
defeatCount = 0
|
||||||
|
|
||||||
inquirer.prompt({
|
function gameLogic(languageSelection) {
|
||||||
|
|
||||||
name: 'languageSelect',
|
|
||||||
message: 'Select language:',
|
|
||||||
default: 'English',
|
|
||||||
type: 'list',
|
|
||||||
|
|
||||||
choices: ['English', 'Spanish']
|
|
||||||
})
|
|
||||||
|
|
||||||
.then((answer) => {
|
|
||||||
|
|
||||||
const languageSelection = answer.languageSelect.toLowerCase()
|
|
||||||
|
|
||||||
function showStats() {
|
function showStats() {
|
||||||
|
|
||||||
@@ -122,9 +129,12 @@ inquirer.prompt({
|
|||||||
return messagesList.options[targetLanguage][index]
|
return messagesList.options[targetLanguage][index]
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('')
|
function translatePlayAgainOption(userSelection, actualLanguage, targetLanguage) {
|
||||||
console.log(messagesList.welcome[languageSelection])
|
|
||||||
console.log('')
|
const index = messagesList.playAgain.options[actualLanguage].findIndex((element) => element === userSelection)
|
||||||
|
|
||||||
|
return messagesList.playAgain.options[targetLanguage][index]
|
||||||
|
}
|
||||||
|
|
||||||
inquirer.prompt({
|
inquirer.prompt({
|
||||||
|
|
||||||
@@ -252,5 +262,58 @@ inquirer.prompt({
|
|||||||
|
|
||||||
showStats()
|
showStats()
|
||||||
|
|
||||||
|
console.log('')
|
||||||
|
|
||||||
|
inquirer.prompt({
|
||||||
|
|
||||||
|
name: 'playAgain',
|
||||||
|
message: messagesList.playAgain.title[languageSelection],
|
||||||
|
type: 'list',
|
||||||
|
|
||||||
|
choices: [...messagesList.playAgain.options[languageSelection]]
|
||||||
|
})
|
||||||
|
.then((answer) => {
|
||||||
|
|
||||||
|
const response = translatePlayAgainOption(answer.playAgain, languageSelection, 'english')
|
||||||
|
|
||||||
|
if (response === 'Yes') {
|
||||||
|
|
||||||
|
console.log('----------------')
|
||||||
|
console.log()
|
||||||
|
gameLogic(languageSelection)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response === 'No') {
|
||||||
|
|
||||||
|
console.log()
|
||||||
|
console.log(messagesList.thanksForPlay[languageSelection])
|
||||||
|
console.log()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
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('')
|
||||||
|
|
||||||
|
gameLogic(languageSelection)
|
||||||
|
|
||||||
|
})
|
||||||
@@ -4,7 +4,8 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
|
"game": "node index.js"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
|
|||||||
Reference in New Issue
Block a user