Skip to content

Instantly share code, notes, and snippets.

@LukeTowers
Last active December 27, 2018 16:38
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 LukeTowers/e8e6163f530f3ed5815d726dcae000d4 to your computer and use it in GitHub Desktop.
Save LukeTowers/e8e6163f530f3ed5815d726dcae000d4 to your computer and use it in GitHub Desktop.
christmas:gift console command
<?php namespace System\Console;
use Illuminate\Console\Command;
/**
* Console command to tear down the database.
*/
class ChristmasGift extends Command
{
/**
* The console command name.
*/
protected $name = 'christmas:gift';
/**
* The console command description.
*/
protected $description = 'Get the location of your gift';
/**
* Execute the console command.
*/
public function handle()
{
$this->info('');
$this->info('');
$this->info('');
$this->info('Provide your answers to the 12 puzzles. Answers must be given IN ORDER. Once all answers are received and verified you will receive the location of the final clue. If you\'re stuck on a puzzle, try making a guess - there\'ll be a hint if you get it wrong.');
$questions = [
'first' => 'military|An eight letter word',
'second' => '365|The answer to the scrambled question + 1, should be a 3 digit number',
'third' => 'kris kringle|The answer is two words',
'fourth' => 'reindeer|The answer is an 8 letter word',
'fifth' => '439|Tick tock, time\'s counting down!',
'sixth' => 'moment|Use the answer from the second puzzle to find a 6 letter word',
'seventh' => 'three wise men|Three words, not numbers, and you better spell good',
'eighth' => 'turning|Use the answer from the fifth puzzle to find a 7 letter word',
'ninth' => 'turkey|The odd one out will tell you what you need to know',
'tenth' => 'chestnuts|It\'s pretty straightforwards, run the numbers',
'eleventh' => 'no silent night|The key is in the key',
'last' => 'red|The answer is a colour',
];
$incorrectCounter = 0;
foreach ($questions as $question => $answer) {
list($answer, $hint) = explode('|', $answer);
do {
$guess = strtolower($this->ask("What is the answer to the $question puzzle?"));
if ($guess !== $answer) {
$incorrectCounter++;
$this->error("Incorrect answer, try again!");
$this->comment("Hint: $hint");
} else {
$this->info('');
}
} while ($guess !== $answer);
}
$this->info('');
if ($incorrectCounter) {
$this->info("You entered incorrect answers $incorrectCounter times - now you must wait $incorrectCounter seconds to see the final clue is");
$progress = $this->output->createProgressBar($incorrectCounter);
for ($i = 0; $i < $incorrectCounter; $i++) {
$progress->advance();
sleep(1);
}
$this->info('');
$progress->finish();
$this->info('');
} else {
$this->info('You got every answer correct! Congrats, the final clue is available to you right now!');
}
$this->info("In the freezer!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment