Created
April 26, 2017 12:13
-
-
Save brainysmurf/56ecd2fa1b2c296b9af3a605c8f57790 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
""" | |
""" | |
import time # for sleeping | |
class App: | |
def __init__(self, stage): | |
self.stage = stage | |
def run(self): | |
while self.stage.continue_play(): | |
self.stage = self.stage.begin() | |
# stage will now be result object: | |
self.stage.output() | |
class Stage: | |
def continue_play(self): | |
return True | |
class Choice(Stage): | |
prompt = '' | |
def begin(self): | |
print(self.prompt) | |
self.result = raw_input() | |
if self.affirm(): | |
return self.left() | |
else: | |
return self.right() | |
def affirm(self): | |
return self.result.lower() == 'y' | |
def left(self): | |
pass | |
def right(self): | |
pass | |
class Stick(Choice): | |
prompt = 'Pick up the stick?' | |
def left(self): | |
print("SMART MOVE") | |
return PickUpStick() | |
def right(self): | |
print("IDIOT") | |
return NoPickUpStick() | |
class Fight(Stage): | |
def __init__(self, chance=5, your_health=10, their_health=5): | |
self.chance = chance | |
self.your_health = your_health | |
self.their_health = their_health | |
def begin(self): | |
while self.still_fighting(): | |
self.animate() | |
self.you_attack() | |
self.they_attack() | |
print("Your health is at {}".format(self.your_health)) | |
print("Its health is at {}".format(self.their_health)) | |
print("====") | |
time.sleep(.5) | |
return self.determine_winner() | |
def animate(self): | |
pass | |
def determine_winner(self): | |
if self.your_health == 0: | |
return Spider() | |
else: | |
return You() | |
def still_fighting(self): | |
return self.your_health > 0 and self.their_health > 0 | |
def you_won(self): | |
return self.your_health > self.their_health | |
class FightSpider(Fight): | |
def you_attack(self): | |
if self.chance != 0: | |
# TODO: Use random number to see how likely he hit the spider | |
print("You attacked, and hit him!") | |
self.their_health -= 1 | |
else: | |
print("Nothing to attack him with!") | |
def they_attack(self): | |
print("OUCH! Spider hit you.") | |
self.your_health -= 1 | |
class PickUpStick(Choice): | |
prompt = 'Will you fight the spider!' | |
chance = 5 | |
def left(self): | |
print("YAA") | |
time.sleep(1) | |
return FightSpider(chance=5) | |
def right(self): | |
print("TOO BAD") | |
time.sleep(1) | |
return FightSpider(chance=0) | |
class NoPickUpStick(PickUpStick): | |
chance = 0 | |
class Winner(Stage): | |
def continue_play(self): | |
return False | |
def output(self): | |
print(self.ascii_art) | |
class You(Winner): | |
ascii_art = """ | |
$$$$$$$$$$$$$$$$$$$$$$ | |
$$$$$$$$$$$$$$$$$$$$$$$$$$$$ | |
$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$$ | |
$$$$$$$$$$$$$$ $$$$$$$ $$ $ $$$$ | |
$$$$$$$$$$$ $$ $$$ $$ $ $ $$$$ | |
$$$$%$$$ $ $ $$ $$$ $ $ $$ $ $$ | |
$$$$%%$$$ $ $ $$ $$$ $ $$ $ $ $$$ | |
$$$$$%%$$$$ $ $ $ $$ $ $$$ $ $$ $$$$ | |
$$$$$%%%$$$$$ $$$$ $ $ $$ $ $$$$$ $$ $$$$$ | |
$$$$$$%%%$$$$$$$$$$$ $$ $ $$$$ $ $$$$$$$$$$$$$$$$ | |
$$$$$$%%%$$$$$$$$$$$$$$$ $$$$$$ $$$$$$$$$$$$$$$$$$$ | |
$$$$$$%%%$$%%%%%%$$$$$$$$$$$$$$$ $$$$$$$$$ $$$$$$$$ | |
$$$$$$%%$$%%%%%%%%%$$$$$$$$$$$$$ $$$$$$$ $$$$%$$$ | |
$$$$$$%$$%%%%%%%%%%%$$$$$$$$$$$$$$$$$ $$$$%%$$$ | |
$$$$$$$$%%%%%%%%%%%%%$$$$$$$$$$$ $$$$%%$$$ | |
$$$$$$$%%% $$$$$$$$ $$$%%$$$ | |
$$$$$$%%% $$$%%$$ | |
$$$$$$%%% $$$%%$$ | |
$$$$$%%%% % $$$%%$$ | |
$$$$$%%%% % $$%%$$ | |
$$$$$%%%% % $$%%$$ | |
$$$$$%%%% %% $$$%$$ | |
$$$$$%%%% %%% $$$%$$ | |
$$$$$%%%% %% $$$%$$ | |
$$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$$ %%%%%%%%%%%%% $$$ | |
$$$ $ $$$$ $%%%% $$$ | |
$$ $$ $$$$$ $$$$ $$$ | |
$ $$ $$ $$$$$$ $$$ $$$ | |
$ $$$$ $$ $$$$$$ $$$$ $$$ | |
$ $$$ $$$ $$$$$$ $$$$$$$ $$$ | |
$ $$$$$$$$$$ $$$$$$ $$$ | |
$ $$ $$$$$$$$ $$$$$$$$$$$$$$$ $$$ | |
$$$$$ $$$$$$$ $$$$$$$$$$$$$$$$$$ | |
$$$$$$ $$$$$ $$$$$$ | |
$$$$$ $$$$ | |
$$$$$$ $$$ | |
$$$$$ $$$ | |
$$$$$$$$ | |
$$$$$$ | |
""" | |
class Spider(Winner): | |
ascii_art = """ | |
( | |
) | |
( | |
/\\ .-\"\"\"-. /\\ | |
//\\\\/ ,,, \\//\\\\ | |
|/\\| ,;;;;;, |/\\| | |
//\\\\\\;-\"\"\"-;///\\\\ | |
// \\/ . \\/ \\\\ | |
(| ,-_| \\ | / |_-, |) | |
//`__\\.-.-./__`\\\\ | |
// /.-(() ())-.\\ \\\\ | |
(\\ |) '---' (| /) | |
` (| |) ` | |
\\) (/ | |
""" | |
App(Stick()).run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment