emoji-guess
Version:
Emoji Quest is an interactive command-line game designed for fun! ๐ Challenge yourself to decode emoji combinations while enjoying vibrant terminal animations. No pressureโjust pure fun! ๐
184 lines (166 loc) โข 5.59 kB
JavaScript
import chalk from "chalk";
import gradient, { rainbow } from "gradient-string";
import figlet from "figlet";
import inquirer from "inquirer";
import { createSpinner } from "nanospinner";
import chalkAnimation from "chalk-animation";
let PlayerName;
let Score = 0;
const TOTAL_QUESTIONS = 5; // Number of questions to ask per game
const sleep = (ms = 2000) => new Promise((resolve) => setTimeout(resolve, ms));
console.clear();
async function Welcome() {
const title = chalkAnimation.glitch("๐ EMOJI QUEST! ๐",0.5);
await sleep();
title.stop();
const gameTitle = chalkAnimation.rainbow("๐ฎ The Ultimate Emoji Challenge ๐ฎ\n");
await sleep();
gameTitle.stop();
console.log(`
${chalk.bgCyan.black(' HOW TO PLAY ')}
${chalk.cyan('โข')} You'll face ${TOTAL_QUESTIONS} random emoji combinations
${chalk.cyan('โข')} Each correct answer earns you ${chalk.green('20 points')}
${chalk.cyan('โข')} Get any question wrong and... ${chalk.bgRed(' GAME OVER ')}
${chalk.cyan('โข')} Reach ${chalk.yellow((TOTAL_QUESTIONS * 20))} points to win! ๐
`);
}
async function askName() {
const answer = await inquirer.prompt({
name: 'player_name',
type: 'input',
message: chalk.yellow('๐พ What shall we call you, brave challenger?'),
default() {
return 'Skibidi';
},
});
PlayerName = answer.player_name;
}
const questions = [
{
emoji: '๐ฅ๐ฅท',
choices: ['Fire Fighter', 'Dragon Ninja', 'Ninja Hatori'],
correct: 'Fire Fighter'
},
{
emoji: '๐๐',
choices: ['Wave Runner', 'Beach Sprint', 'Water Chase'],
correct: 'Wave Runner'
},
{
emoji: '๐ต๐ง ',
choices: ['Music Mind', 'Brain Beats', 'Sound Think'],
correct: 'Brain Beats'
},
{
emoji: '๐๐จโ๐',
choices: ['Star Walker', 'Space Captain', 'Cosmic Man'],
correct: 'Star Walker'
},
{
emoji: '๐จ๐ฆ',
choices: ['Art Flutter', 'Paint Wings', 'Butterfly Design'],
correct: 'Paint Wings'
},
{
emoji: '๐๐บ',
choices: ['Night Wolf', 'Moon Hunter', 'Lunar Howl'],
correct: 'Moon Hunter'
},
{
emoji: 'โก๐งโโ๏ธ',
choices: ['Lightning Wizard', 'Storm Mage', 'Thunder Spell'],
correct: 'Storm Mage'
},
{
emoji: '๐ฎ๐ง',
choices: ['Game Over', 'Zombie Player', 'Digital Undead'],
correct: 'Zombie Player'
},
{
emoji: '๐๐ฆ',
choices: ['Color Horse', 'Rainbow Unicorn', 'Magic Pony'],
correct: 'Rainbow Unicorn'
},
{
emoji: '๐๐ป',
choices: ['Noodle Spirit', 'Ramen Ghost', 'Haunted Bowl'],
correct: 'Ramen Ghost'
},
{
emoji: '๐ช๐ค',
choices: ['Circus Bot', 'Robot Show', 'Mechanical Carnival'],
correct: 'Circus Bot'
},
{
emoji: '๐ฐ๐',
choices: ['Castle Drake', 'Dragon Keep', 'Royal Wings'],
correct: 'Dragon Keep'
},
{
emoji: '๐ญ๐ช',
choices: ['Circus Drama', 'Theater Tent', 'Festival Mask'],
correct: 'Theater Tent'
},
{
emoji: '๐๐โโ๏ธ',
choices: ['Lava Runner', 'Volcano Escape', 'Heat Sprint'],
correct: 'Volcano Escape'
},
{
emoji: '๐ฉ๐ฐ',
choices: ['Magic Rabbit', 'Hat Trick', 'Wonder Bunny'],
correct: 'Hat Trick'
}
];
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
async function askQuestion(questionData) {
const answers = await inquirer.prompt({
name: 'question',
type: 'list',
message: chalk.cyan(`Question ${Score/20 + 1}/${TOTAL_QUESTIONS}: What does this emoji combo mean: ${questionData.emoji}`),
choices: shuffleArray([...questionData.choices]) // Shuffle the choices too
});
return handleAnswer(answers.question === questionData.correct);
}
async function handleAnswer(isCorrect) {
const spinner = createSpinner('๐ค Analyzing your answer...').start();
await sleep();
if (isCorrect) {
Score += 20;
spinner.success({
text: `${chalk.green('๐ฏ CORRECT!')} ${PlayerName}, you've earned 20 points! Total: ${chalk.yellow(Score)} points`
});
} else {
spinner.error({
text: `${chalk.red('๐ฅ GAME OVER!')} Sorry, ${PlayerName}! Final Score: ${chalk.yellow(Score)} points`
});
console.log("Ok bie ๐ ๐ ๐")
process.exit(1);
}
}
function Winner() {
console.clear();
const msg = `${PlayerName} WON!`;
figlet(msg, (err, data) => {
console.log(gradient.rainbow.multiline(data));
console.log(`\n${chalk.green('๐ Congratulations on conquering the Emoji Quest! ๐')}\n`);
console.log("Ok bie ๐ ๐ ๐")
});
}
// Main game flow
await Welcome();
await askName();
// Get random questions
const gameQuestions = shuffleArray([...questions]).slice(0, TOTAL_QUESTIONS);
for (const question of gameQuestions) {
await askQuestion(question);
await sleep(1000);
}
Winner();