-
-
Save abimaelmartell/4746668 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
class FortuneTellerMachine | |
WELCOME = "Hola ¿Quiéres saber tu fortuna?" | |
REQUEST = "Fortuna por monedas, yo quiero yo quiero monedas (2): " | |
CHANGE_BACK = "Here is your change" | |
COST = 2 | |
def initialize | |
clear | |
end | |
def start | |
puts WELCOME | |
pending | |
end | |
def pending | |
puts REQUEST | |
self.coins += gets.to_i | |
if self.coins > COST | |
give_change | |
elsif self.coins == COST | |
finish | |
else | |
pending | |
end | |
end | |
def give_change | |
change = self.coins - COST | |
puts [CHANGE_BACK, change].join("") | |
puts | |
finish | |
end | |
def finish | |
puts fortune.shuffle.first | |
clear | |
end | |
def clear | |
self.coins = 0 | |
end | |
def coins= amount | |
@coins = amount | |
end | |
def coins | |
@coins | |
end | |
def fortune | |
[ | |
"You only need look to your own reflection for inspiration. Because you are Beautiful!", | |
"Rivers need springs.", | |
"Good news from afar may bring you a welcome visitor.", | |
"When all else seems to fail, smile for today and just love someone.", | |
"When you look down, all you see is dirt, so keep looking up.", | |
] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment