Skip to content

Instantly share code, notes, and snippets.

@mhsenpc
Last active August 24, 2023 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhsenpc/e046166348f283538a1372134442d35c to your computer and use it in GitHub Desktop.
Save mhsenpc/e046166348f283538a1372134442d35c to your computer and use it in GitHub Desktop.
A game for practising words with their meaning. it is implemented as a laravel command. you just need to choose the right answer through the 3 items
<?php
class LanguageGameCommand extends BaseCommand {
/**
* The console command name.
*
* @var string
*/
protected $name = 'game:play';
protected array $words = [
'nehmen' => 'take',
'verstehen' => 'understand',
'treffen' => 'meet',
'einladen' => 'invite',
'flieBend' => 'fluently',
'nachste cafe' => 'nearest cafe',
'weiB' => 'know',
'wann' => 'when',
'wirst' => 'will',
'besuchen' => 'visit',
'will' => 'want',
'reisen' => 'travel',
'schild' => 'sign',
'stehn' => 'stand',
'regnen' => 'rain'
];
/**
* Execute the console command.
*/
public function handle(): void {
do{
$currentWord = array_rand($this->words);
$realAnswer = $this->words[$currentWord];
$twoMoreAnswerKeys = array_rand($this->words, 2);
$totalAnswers = [$realAnswer, $this->words[$twoMoreAnswerKeys[0]], $this->words[$twoMoreAnswerKeys[1]] ];
$totalAnswers = array_unique($totalAnswers);
shuffle($totalAnswers);
$userInput = $this->choice(
sprintf("What does %s mean?", $currentWord),
$totalAnswers,
);
if($userInput == $realAnswer){
$this->info("Correct!");
} else {
$this->error("Wrong!");
}
} while($userInput);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment