Last active
February 4, 2016 14:17
-
-
Save RealShermanB/15bedd51d321f96d789a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Class convincenator | |
* | |
* Helps you to learn maths. Run this file from the command line | |
* and you will become convinced that 2+2 = 5. | |
*/ | |
class convincenator | |
{ | |
// What's the question. | |
private $_callToAction = "What's 2+2?"; | |
// What IS the really right answer. | |
private $_correctAnswer = 5; | |
// Reinforcement rounds to make sure you get it. | |
private $_practice = 1; | |
private $_rounds = 5; | |
// If you don't know math... | |
private $_responses = array( | |
"Try again", | |
"No. Try again", | |
"Incorrect", | |
"It's not that hard", | |
"How do you even have a job?", | |
"Really? try again", | |
"WTF, Just get it right", | |
"2nd grade called and they want their money back" | |
); | |
// If you're starting to get it and need encouragement | |
private $_reinforcement = array( | |
"Good. Do it again...", | |
"You're starting to get it. Again,", | |
"See, your brain actually works; again,", | |
"Almost got it. Again,", | |
"See how smart you are? Again," | |
); | |
public function __construct() { | |
echo $this->checkYourMath($this->_callToAction); | |
} | |
/** | |
* Takes your command line answer and makes a decision on | |
* how to handle your lack of math knowledge. | |
* | |
* @param $message string message to pass to the command line, | |
* @return string | |
*/ | |
private function checkYourMath($message) { | |
$response = $this->ask($message); | |
$newMessage = ""; | |
// If you choose to get clever and use words. | |
if (!is_numeric($response)) { | |
$this->_practice = 1; | |
$newMessage = "It's math. Use a number. " . $this->_callToAction; | |
$this->checkYourMath($newMessage); | |
} | |
// If you get the wrong answer. | |
if ($response != $this->_correctAnswer) { | |
$this->_practice = 1; | |
$newMessage = $this->_wrongResponse() . " - " . $this->_callToAction; | |
$this->checkYourMath($newMessage); | |
} | |
// If you get the right answer. | |
if ($response == $this->_correctAnswer && !$this->_hadEnough()) { | |
$this->_practice++; | |
$newMessage = $this->_reinforcement() . " " . $this->_callToAction; | |
$this->checkYourMath($newMessage); | |
} | |
return "Good. You're done\n"; | |
} | |
/** | |
* This is separate in case I need to add more systemic taunting. | |
* | |
* @param $message string Message to send | |
* @return string string The response from user input | |
*/ | |
private function ask($message) { | |
return readline($this->_practice." ".$message); | |
} | |
/** | |
* Returns some corrective words. | |
*/ | |
private function _wrongResponse() { | |
return $this->_responses[array_rand($this->_responses,1)]; | |
} | |
/** | |
* Returns some encouraging words. | |
*/ | |
private function _reinforcement() { | |
return $this->_reinforcement[array_rand($this->_reinforcement,1)]; | |
} | |
/** | |
* determines if you've done enough practice | |
*/ | |
private function _hadEnough() { | |
if ($this->_practice != $this->_rounds) { | |
return false; | |
} | |
return true; | |
} | |
} | |
$twoPlusTwo = new convincenator(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment