From b9e7341d1ee65ca911f9c9719d255df2bd637f8f Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 4 Apr 2016 11:02:58 -0700 Subject: [PATCH 1/9] Added default values and initial logic for Spaceship exercise --- spaceship.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 spaceship.py diff --git a/spaceship.py b/spaceship.py new file mode 100644 index 0000000..82bccd6 --- /dev/null +++ b/spaceship.py @@ -0,0 +1,54 @@ +class Spaceship: + + def __init__(self): + self.thirst = 50 + self.work = 50 + self.horde = 50 + self.hunger = 50 + self.receipts = 50 + self.stable = True + + def drink(self): + self.thirst -= 10 + self.work += 2 + + def deliver(self): + self.work += 8 + self.receipts += 4 + + def steal(self): + self.horde += 10 + self.work += 7 + + def eat(self): + self.hunger -= 10 + self.work += 2 + + def account(self): + self.receipts -= 10 + self.horder -= 10 + + # the lower the thirst, work, and hunger, and the higher the horde + # and receipts, the better the score. + # as thirst, work, and hunger decrease + # and as horde and receipts increase, the score increases + # def score(self): + + def stable(self): + if score < 30: + return false + else: + return true + + def check(self): + self.alert() + # It also needs to print out a warning for each value if it is + # getting too high (or too low), such as if Hermes has too many + # receipts (but not enough to crash the company). If it was enough + # to crash the company (perhaps more than 100), then the function + # would return false. + + # how to get this to string interpolate which value is greater than 90. + def alert(self): + if any( [self.thirst > 90, self.work > 90, self.horde > 90, self.hunger > 90, self.receipts > 90] ): + print "Uh oh! Somethings off! Check the status!" From c67f9e370134c6a5998614ebd5217a5fd6172215 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 4 Apr 2016 11:22:19 -0700 Subject: [PATCH 2/9] Wrote a method for alerting user when game about to end --- spaceship.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/spaceship.py b/spaceship.py index 82bccd6..ff95871 100644 --- a/spaceship.py +++ b/spaceship.py @@ -50,5 +50,18 @@ def check(self): # how to get this to string interpolate which value is greater than 90. def alert(self): - if any( [self.thirst > 90, self.work > 90, self.horde > 90, self.hunger > 90, self.receipts > 90] ): - print "Uh oh! Somethings off! Check the status!" + if any( [self.thirst > 60, self.work > 60, self.horde > 60, self.hunger > 60, self.receipts > 60] ): + print "Uh oh! Your ship is about to sink. Here's your current status of the boat. Remember, if any value reaches 100, you're DOOMED!" + self.thirst + print "Current thirst level: " + print self.thirst + print "Current work level:" + print self.work + print "Current hording level: " + print self.horde + print "Current hunger level: " + print self.hunger + print "Current receipt level: " + print self.receipts + # put all things in an array + # iterate through the array and for only the values that have a value great than 90 have it print out a statement From 92a7455f36cdb9e5e99890fd9cfd7be3d0659cf8 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 4 Apr 2016 12:27:20 -0700 Subject: [PATCH 3/9] Draft check method for checking status of game created --- spaceship.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/spaceship.py b/spaceship.py index ff95871..231b825 100644 --- a/spaceship.py +++ b/spaceship.py @@ -35,13 +35,17 @@ def account(self): # def score(self): def stable(self): - if score < 30: - return false + if any( [self.thirst > 99, self.work > 99, self.horde < 1, self.hunger > 99, self.receipts < 1] ): + return False else: - return true + return True def check(self): self.alert() + if self.stable: + return True + else: + return False # It also needs to print out a warning for each value if it is # getting too high (or too low), such as if Hermes has too many # receipts (but not enough to crash the company). If it was enough From c5441c394d0bcd2f2a2ab9d862cb4a1037432112 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 4 Apr 2016 14:04:53 -0700 Subject: [PATCH 4/9] Wrote inital logic for scoring method --- spaceship.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/spaceship.py b/spaceship.py index 231b825..24b50ab 100644 --- a/spaceship.py +++ b/spaceship.py @@ -7,6 +7,7 @@ def __init__(self): self.hunger = 50 self.receipts = 50 self.stable = True + self.total = 0 def drink(self): self.thirst -= 10 @@ -26,13 +27,17 @@ def eat(self): def account(self): self.receipts -= 10 - self.horder -= 10 + self.horde -= 10 # the lower the thirst, work, and hunger, and the higher the horde # and receipts, the better the score. # as thirst, work, and hunger decrease # and as horde and receipts increase, the score increases - # def score(self): + # if thirst decreases, score increases + def score(self): + if self.thirst < 30: + self.total += 1 + return self.total def stable(self): if any( [self.thirst > 99, self.work > 99, self.horde < 1, self.hunger > 99, self.receipts < 1] ): @@ -46,11 +51,7 @@ def check(self): return True else: return False - # It also needs to print out a warning for each value if it is - # getting too high (or too low), such as if Hermes has too many - # receipts (but not enough to crash the company). If it was enough - # to crash the company (perhaps more than 100), then the function - # would return false. + print "You lose! Try again!" # how to get this to string interpolate which value is greater than 90. def alert(self): From 5b0109ab341c6eb6b68d5a3cb857c4fc01367a81 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 4 Apr 2016 14:34:48 -0700 Subject: [PATCH 5/9] Added additional logic for scoring --- spaceship.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/spaceship.py b/spaceship.py index 24b50ab..0553f76 100644 --- a/spaceship.py +++ b/spaceship.py @@ -29,15 +29,28 @@ def account(self): self.receipts -= 10 self.horde -= 10 - # the lower the thirst, work, and hunger, and the higher the horde - # and receipts, the better the score. - # as thirst, work, and hunger decrease - # and as horde and receipts increase, the score increases - # if thirst decreases, score increases def score(self): - if self.thirst < 30: + if self.thirst < 60: + self.total += 7 + elif self.thirst >= 60: + self.total -= 7 + + if self.work < 70: self.total += 1 - return self.total + elif self.work >= 70: + self.total -= 1 + + if self.horde > 80: + self.total += 5 + elif self.horde <= 80: + self.total -= 1 + + if self.receipts > 70: + self.total += 3 + elif self.receipts <= 70: + self.total -= 3 + + return self.total def stable(self): if any( [self.thirst > 99, self.work > 99, self.horde < 1, self.hunger > 99, self.receipts < 1] ): From 07afeda6c3a056ac14c235ed6823db782d223446 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 4 Apr 2016 15:20:02 -0700 Subject: [PATCH 6/9] Added playGame method --- spaceship.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spaceship.py b/spaceship.py index 0553f76..1ee7259 100644 --- a/spaceship.py +++ b/spaceship.py @@ -66,7 +66,6 @@ def check(self): return False print "You lose! Try again!" - # how to get this to string interpolate which value is greater than 90. def alert(self): if any( [self.thirst > 60, self.work > 60, self.horde > 60, self.hunger > 60, self.receipts > 60] ): print "Uh oh! Your ship is about to sink. Here's your current status of the boat. Remember, if any value reaches 100, you're DOOMED!" @@ -81,5 +80,8 @@ def alert(self): print self.hunger print "Current receipt level: " print self.receipts - # put all things in an array - # iterate through the array and for only the values that have a value great than 90 have it print out a statement + +def playGame(): + ship = Spaceship() + +playGame From 814006e81d31b766a159ed9e2b4325fb1f56b576 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 4 Apr 2016 16:21:23 -0700 Subject: [PATCH 7/9] PlayGame method working --- spaceship.py | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/spaceship.py b/spaceship.py index 1ee7259..69c8b60 100644 --- a/spaceship.py +++ b/spaceship.py @@ -82,6 +82,36 @@ def alert(self): print self.receipts def playGame(): - ship = Spaceship() + game = Spaceship() -playGame + print "All Aboard the Planet Express!" + print "What would you like to do?" + + stop = False + + while stop != True: + action = raw_input("What would you like to do aboard the ship? You can type 'eat', 'drink', 'accounting', 'deliver', or 'steal'. Or you can click 'bye' to end this pain! ") + + if action == "bye": + stop = True + print "Laterz." + else: + if action == "eat": + game.eat() + print "You ate something! Your belly is fuller, but it required work!" + print game.total + elif action == "drink": + game.drink() + print "You drank something! You're less thirsty, but it required some work!" + elif action == "accounting": + game.account() + print game.total + print "You did some accounting! Boring! That was a lot of work!" + elif action == "deliver": + print "You did some work for once! That required some work!" + elif action == "steal": + print "You stole some stuff! That's awkward." + else: + "I don't understand that command! Try again!" + +playGame() From a596a8bf74965392fe111435eccc5b8f95ffe4b0 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 4 Apr 2016 16:40:40 -0700 Subject: [PATCH 8/9] Updated playGame method --- spaceship.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/spaceship.py b/spaceship.py index 69c8b60..8eddc56 100644 --- a/spaceship.py +++ b/spaceship.py @@ -67,7 +67,7 @@ def check(self): print "You lose! Try again!" def alert(self): - if any( [self.thirst > 60, self.work > 60, self.horde > 60, self.hunger > 60, self.receipts > 60] ): + if any( [self.thirst > 90, self.work > 90, self.horde > 90, self.hunger > 90, self.receipts > 90] ): print "Uh oh! Your ship is about to sink. Here's your current status of the boat. Remember, if any value reaches 100, you're DOOMED!" self.thirst print "Current thirst level: " @@ -86,12 +86,13 @@ def playGame(): print "All Aboard the Planet Express!" print "What would you like to do?" + print "You can also type 'bye' at any time to leave this game :(." stop = False while stop != True: - action = raw_input("What would you like to do aboard the ship? You can type 'eat', 'drink', 'accounting', 'deliver', or 'steal'. Or you can click 'bye' to end this pain! ") - + print "What would you like to do aboard the ship?" + action = raw_input("You can type 'eat', 'drink', 'accounting', 'deliver', or 'steal'. ") if action == "bye": stop = True print "Laterz." @@ -109,9 +110,14 @@ def playGame(): print "You did some accounting! Boring! That was a lot of work!" elif action == "deliver": print "You did some work for once! That required some work!" + print game.total elif action == "steal": + game.steal() print "You stole some stuff! That's awkward." + print game.total + print game.work else: "I don't understand that command! Try again!" + game.check() playGame() From e7bbd8cda5518ad39f8446495f366cc4f7d210a1 Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 6 Apr 2016 14:10:02 -0700 Subject: [PATCH 9/9] Spaceship working smoothly --- spaceship.py | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/spaceship.py b/spaceship.py index 8eddc56..0e03006 100644 --- a/spaceship.py +++ b/spaceship.py @@ -29,27 +29,42 @@ def account(self): self.receipts -= 10 self.horde -= 10 - def score(self): - if self.thirst < 60: + def thirst_level(self): + if self.thirst < 50: self.total += 7 elif self.thirst >= 60: self.total -= 7 + def horde_level(self): + if self.horde > 80: + self.total += 5 + elif self.horde <= 80: + self.total -= 1 + + def work_level(self): if self.work < 70: self.total += 1 elif self.work >= 70: self.total -= 1 - if self.horde > 80: - self.total += 5 - elif self.horde <= 80: + def hunger_level(self): + if self.hunger > 60: + self.total -= 1 + elif self.hunger <= 60: self.total -= 1 + def receipt_level(self): if self.receipts > 70: self.total += 3 elif self.receipts <= 70: self.total -= 3 + def total_score(self): + self.thirst_level + self.horde_level + self.work_level + self.receipt_level + self.hunger_level return self.total def stable(self): @@ -68,7 +83,7 @@ def check(self): def alert(self): if any( [self.thirst > 90, self.work > 90, self.horde > 90, self.hunger > 90, self.receipts > 90] ): - print "Uh oh! Your ship is about to sink. Here's your current status of the boat. Remember, if any value reaches 100, you're DOOMED!" + print "Uh oh! Your ship is about to sink. Here's what you need to watch out for. Remember, if any value reaches 100, you're DOOMED!" self.thirst print "Current thirst level: " print self.thirst @@ -86,6 +101,7 @@ def playGame(): print "All Aboard the Planet Express!" print "What would you like to do?" + print "Keep track of your score by typing \"score\" at any time." print "You can also type 'bye' at any time to leave this game :(." stop = False @@ -100,22 +116,20 @@ def playGame(): if action == "eat": game.eat() print "You ate something! Your belly is fuller, but it required work!" - print game.total elif action == "drink": game.drink() print "You drank something! You're less thirsty, but it required some work!" elif action == "accounting": game.account() - print game.total print "You did some accounting! Boring! That was a lot of work!" elif action == "deliver": print "You did some work for once! That required some work!" - print game.total elif action == "steal": game.steal() print "You stole some stuff! That's awkward." - print game.total - print game.work + elif action == "score": + print "Your total score is: " + print game.total_score() else: "I don't understand that command! Try again!" game.check()