From b9e7341d1ee65ca911f9c9719d255df2bd637f8f Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 4 Apr 2016 11:02:58 -0700 Subject: [PATCH 01/15] 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 02/15] 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 03/15] 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 04/15] 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 05/15] 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 06/15] 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 07/15] 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 08/15] 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 09/15] 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() From a74232e523eedd9e1ff14786bee2324fd1344ae6 Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 6 Apr 2016 16:09:26 -0700 Subject: [PATCH 10/15] Made initial files for Spaceship exercise in JavaScript --- index.html | 43 +++++++++++++++++++++++++++++++++++++++++++ spaceship.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 index.html create mode 100644 spaceship.js diff --git a/index.html b/index.html new file mode 100644 index 0000000..38f0607 --- /dev/null +++ b/index.html @@ -0,0 +1,43 @@ + + + + + + Spaceships + + + +

Futuramalama

+

Welcome to Space! You must run your ship properly to survive!

+

+ This means feeding your crew, making sure they don't die of thirst, doing some accounting, + making deliveries, and other interesting things. +

+ + + + + + + + + + + + + + + + + +
Thing To Watch Out ForCurrent Status
Thirst Status
Hunger Status
Receipt Status
Treasure Status
+ +

Score

+ +

Click any of the below buttons to take action on the ship

+ + + + + + diff --git a/spaceship.js b/spaceship.js new file mode 100644 index 0000000..fdcd0ff --- /dev/null +++ b/spaceship.js @@ -0,0 +1,46 @@ +function SpaceShip(start, end) { + this.work = start; + this.horde = start; + this.hunger = start; + this.receipts = start; + this.stable = true; + this.end = end; + this.totalScore = 0; +} + +SpaceShip.prototype.drink = function(){ + this.thirst--; + this.work++; +}; + +SpaceShip.prototype.work = function(){ + this.thirst--; + this.work++; +}; + +SpaceShip.prototype.horde = function(){ + this.thirst--; + this.work++; +}; + +SpaceShip.prototype.receipts = function(){ + this.thirst--; + this.work++; +}; + +SpaceShip.protoype.score = function(){ + this.thirstLevel(); + this.hordeLevel(); + this.hordeLevel(); + this.receiptLevel(); + this.hungerLevel(); + return this.totalScore; +}; + +SpaceShip.protoype.receiptLevel = function(){ + if (this.receipts > 70) { + this.totalScore ++; + } else if (this.receipts <= 80) { + this.totalScore --; + } +}; From 45107e893b6fadd5aac96dd3a48345bc269f3269 Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 6 Apr 2016 16:20:37 -0700 Subject: [PATCH 11/15] Added css ids for different objects --- index.html | 4 ++++ spaceship.js | 27 ++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 38f0607..7e8f554 100644 --- a/index.html +++ b/index.html @@ -20,15 +20,19 @@

Thirst Status + Hunger Status + Receipt Status + Treasure Status + diff --git a/spaceship.js b/spaceship.js index fdcd0ff..0a26ab8 100644 --- a/spaceship.js +++ b/spaceship.js @@ -1,5 +1,6 @@ function SpaceShip(start, end) { this.work = start; + this.thirst = start; this.horde = start; this.hunger = start; this.receipts = start; @@ -13,6 +14,11 @@ SpaceShip.prototype.drink = function(){ this.work++; }; +SpaceShip.prototype.eat = function(){ + this.thirst--; + this.work++; +}; + SpaceShip.prototype.work = function(){ this.thirst--; this.work++; @@ -28,19 +34,34 @@ SpaceShip.prototype.receipts = function(){ this.work++; }; -SpaceShip.protoype.score = function(){ +SpaceShip.prototype.score = function(){ this.thirstLevel(); - this.hordeLevel(); + this.workLevel(); this.hordeLevel(); this.receiptLevel(); this.hungerLevel(); return this.totalScore; }; -SpaceShip.protoype.receiptLevel = function(){ +SpaceShip.prototype.receiptLevel = function(){ if (this.receipts > 70) { this.totalScore ++; } else if (this.receipts <= 80) { this.totalScore --; } }; + +// clicking on this will update the text in the drink id +SpaceShip.prototype.makeMoves = function(){ + $("#drink").text(crew.thirst); + $("#eat").text(crew.hunger); + $("#treasures").text(crew.horde); + + +} + +var crew = new SpaceShip(); + +$(document).ready( function (){ + +}); From 6eeeec8ce5cded08fb76966efcc0f6e1ca2ce298 Mon Sep 17 00:00:00 2001 From: Sarah Date: Thu, 7 Apr 2016 11:12:47 -0700 Subject: [PATCH 12/15] Created a 'status' method that will run each time an action happens --- index.html | 14 +++++-- spaceship.js | 101 ++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 85 insertions(+), 30 deletions(-) diff --git a/index.html b/index.html index 7e8f554..b63dfef 100644 --- a/index.html +++ b/index.html @@ -22,7 +22,15 @@

Thirst Status + + Work Status + + + + Horde Status + + Hunger Status @@ -30,13 +38,11 @@

Receipt Status - - Treasure Status - - +

Score

+

Click any of the below buttons to take action on the ship

diff --git a/spaceship.js b/spaceship.js index 0a26ab8..32566c2 100644 --- a/spaceship.js +++ b/spaceship.js @@ -1,6 +1,6 @@ function SpaceShip(start, end) { - this.work = start; this.thirst = start; + this.work = start; this.horde = start; this.hunger = start; this.receipts = start; @@ -14,33 +14,57 @@ SpaceShip.prototype.drink = function(){ this.work++; }; -SpaceShip.prototype.eat = function(){ - this.thirst--; - this.work++; +SpaceShip.prototype.deliver = function(){ + this.work--; + this.receipts ++; }; -SpaceShip.prototype.work = function(){ - this.thirst--; +SpaceShip.prototype.steal = function(){ + this.horde++; this.work++; }; -SpaceShip.prototype.horde = function(){ - this.thirst--; +SpaceShip.prototype.eat = function(){ + this.hunger--; this.work++; }; -SpaceShip.prototype.receipts = function(){ - this.thirst--; - this.work++; +SpaceShip.prototype.account = function(){ + this.receipts--; + this.horde--; + $("#receipts").text(crew.receipts); }; -SpaceShip.prototype.score = function(){ - this.thirstLevel(); - this.workLevel(); - this.hordeLevel(); - this.receiptLevel(); - this.hungerLevel(); - return this.totalScore; +SpaceShip.prototype.status = function(){ + $("#thirst").text(this.thirst); + $("#work").text(this.work); + $("#horde").text(this.horde); + $("#hunger").text(this.hunger); + $("#receipts").text(this.receipts); +} + +SpaceShip.prototype.thirstLevel = function(){ + if (this.thirst > 70) { + this.totalScore --; + } else if (this.thirst <= 70) { + this.totalScore ++; + } +}; + +SpaceShip.prototype.workLevel = function(){ + if (this.work > 70) { + this.totalScore --; + } else if (this.work <= 70) { + this.totalScore ++; + } +}; + +SpaceShip.prototype.hordeLevel = function(){ + if (this.horde > 70) { + this.totalScore ++; + } else if (this.horde <= 70) { + this.totalScore ++; + } }; SpaceShip.prototype.receiptLevel = function(){ @@ -51,17 +75,42 @@ SpaceShip.prototype.receiptLevel = function(){ } }; -// clicking on this will update the text in the drink id -SpaceShip.prototype.makeMoves = function(){ - $("#drink").text(crew.thirst); - $("#eat").text(crew.hunger); - $("#treasures").text(crew.horde); +SpaceShip.prototype.hungerLevel = function(){ + if (this.work > 70) { + this.totalScore --; + } else if (this.work <= 70) { + this.totalScore ++; + } +}; + +SpaceShip.prototype.score = function(){ + console.log(this); + this.thirstLevel(); + this.workLevel(); + this.hordeLevel(); + this.receiptLevel(); + this.hungerLevel(); + $("#score").text(crew.score); +}; +var crew = new SpaceShip(50, 100); -} +$(document).ready(function(){ + crew.status(); + crew.score(); -var crew = new SpaceShip(); + $("#drink").click(function(){ + crew.drink(); + alert("You drank something!"); + crew.status(); + crew.score(); + }); -$(document).ready( function (){ + $("#eat").click(function(){ + crew.eat(); + alert("You eat something!"); + crew.status(); + crew.score(); + }); }); From d9e321e38e0b0eed6ee96e226c78248f05cc648a Mon Sep 17 00:00:00 2001 From: Sarah Date: Thu, 7 Apr 2016 12:00:11 -0700 Subject: [PATCH 13/15] All methods for spaceship actions now work --- index.html | 6 ++-- spaceship.js | 86 +++++++++++++++++++++++++++------------------------- 2 files changed, 47 insertions(+), 45 deletions(-) diff --git a/index.html b/index.html index b63dfef..61701cd 100644 --- a/index.html +++ b/index.html @@ -41,8 +41,8 @@

-

Score

- +

Score:

+ 0

Click any of the below buttons to take action on the ship

@@ -50,4 +50,4 @@

Click any of the below buttons to take action on the ship

- + diff --git a/spaceship.js b/spaceship.js index 32566c2..848f980 100644 --- a/spaceship.js +++ b/spaceship.js @@ -1,4 +1,4 @@ -function SpaceShip(start, end) { +var SpaceShip = function(start, end) { this.thirst = start; this.work = start; this.horde = start; @@ -41,76 +41,78 @@ SpaceShip.prototype.status = function(){ $("#horde").text(this.horde); $("#hunger").text(this.hunger); $("#receipts").text(this.receipts); -} - -SpaceShip.prototype.thirstLevel = function(){ - if (this.thirst > 70) { - this.totalScore --; - } else if (this.thirst <= 70) { - this.totalScore ++; - } }; -SpaceShip.prototype.workLevel = function(){ - if (this.work > 70) { - this.totalScore --; - } else if (this.work <= 70) { - this.totalScore ++; - } -}; +SpaceShip.prototype.score = function(){ + if (this.thirst > 70) { + this.totalScore --; + } else if (this.thirst <= 70) { + this.totalScore ++; + } + + if (this.work > 70) { + this.totalScore --; + } else if (this.work <= 70) { + this.totalScore ++; + } + + if (this.receipts > 70) { + this.totalScore ++; + } else if (this.receipts <= 80) { + this.totalScore --; + } -SpaceShip.prototype.hordeLevel = function(){ if (this.horde > 70) { this.totalScore ++; } else if (this.horde <= 70) { this.totalScore ++; } -}; - -SpaceShip.prototype.receiptLevel = function(){ - if (this.receipts > 70) { - this.totalScore ++; - } else if (this.receipts <= 80) { - this.totalScore --; - } -}; -SpaceShip.prototype.hungerLevel = function(){ - if (this.work > 70) { + if (this.thirst > 70) { this.totalScore --; - } else if (this.work <= 70) { + } else if (this.thirst <= 70) { this.totalScore ++; } -}; - -SpaceShip.prototype.score = function(){ - console.log(this); - this.thirstLevel(); - this.workLevel(); - this.hordeLevel(); - this.receiptLevel(); - this.hungerLevel(); - $("#score").text(crew.score); + $("#score").text(this.totalScore); }; var crew = new SpaceShip(50, 100); $(document).ready(function(){ crew.status(); - crew.score(); $("#drink").click(function(){ crew.drink(); alert("You drank something!"); - crew.status(); crew.score(); + crew.status(); }); $("#eat").click(function(){ crew.eat(); - alert("You eat something!"); + alert("You ate something!"); + crew.score(); + crew.status(); + }); + + $("#deliver").click(function(){ + crew.deliver(); + alert("You delivered something!"); + crew.score(); crew.status(); + }); + + $("#account").click(function(){ + crew.account(); + alert("You did some accounting!"); crew.score(); + crew.status(); }); + $("#steal").click(function(){ + crew.steal(); + alert("You stole some treasure!"); + crew.score(); + crew.status(); + }); }); From 16ba271727b024f71401673a3aab57b9ab1fecbf Mon Sep 17 00:00:00 2001 From: Sarah Date: Thu, 7 Apr 2016 12:22:31 -0700 Subject: [PATCH 14/15] Added case for ending game --- index.html | 14 ++++---- spaceship.js | 95 +++++++++++++++++++++++++++++----------------------- 2 files changed, 60 insertions(+), 49 deletions(-) diff --git a/index.html b/index.html index 61701cd..71ba4a7 100644 --- a/index.html +++ b/index.html @@ -15,27 +15,27 @@

- - + + - + - + - + - + - + diff --git a/spaceship.js b/spaceship.js index 848f980..05616e8 100644 --- a/spaceship.js +++ b/spaceship.js @@ -1,38 +1,38 @@ var SpaceShip = function(start, end) { - this.thirst = start; - this.work = start; - this.horde = start; - this.hunger = start; - this.receipts = start; - this.stable = true; - this.end = end; - this.totalScore = 0; + this.thirst = start; + this.work = start; + this.horde = start; + this.hunger = start; + this.receipts = start; + this.stable = true; + this.end = end; + this.totalScore = 0; } SpaceShip.prototype.drink = function(){ - this.thirst--; - this.work++; + this.thirst--; + this.work++; }; SpaceShip.prototype.deliver = function(){ - this.work--; - this.receipts ++; + this.work--; + this.receipts ++; }; SpaceShip.prototype.steal = function(){ - this.horde++; - this.work++; + this.horde++; + this.work++; }; SpaceShip.prototype.eat = function(){ - this.hunger--; - this.work++; + this.hunger--; + this.work++; }; SpaceShip.prototype.account = function(){ - this.receipts--; - this.horde--; - $("#receipts").text(crew.receipts); + this.receipts--; + this.horde--; + $("#receipts").text(crew.receipts); }; SpaceShip.prototype.status = function(){ @@ -44,39 +44,50 @@ SpaceShip.prototype.status = function(){ }; SpaceShip.prototype.score = function(){ - if (this.thirst > 70) { - this.totalScore --; - } else if (this.thirst <= 70) { - this.totalScore ++; - } - - if (this.work > 70) { - this.totalScore --; - } else if (this.work <= 70) { - this.totalScore ++; - } - - if (this.receipts > 70) { - this.totalScore ++; - } else if (this.receipts <= 80) { - this.totalScore --; - } + if (this.totalScore < 0) { + alert("You lost! Try again."); + location.reload(); + } - if (this.horde > 70) { - this.totalScore ++; - } else if (this.horde <= 70) { + if (this.thirst > 70 && this.thirst < this.end) { + this.totalScore --; + } else if (this.thirst <= 70) { this.totalScore ++; + } else if (this.thirst >= this.end) { + alert("Your crew got too thirsty! You lose - try again."); + location.reload(); } - if (this.thirst > 70) { + if (this.work > 70) { this.totalScore --; - } else if (this.thirst <= 70) { + } else if (this.work <= 70 && this.work < this.end) { this.totalScore ++; + } else if (this.work >= this.end) { + alert("Your crew got too hungry! You lose - try again."); + location.reload(); } + + if (this.receipts > 70) { + this.totalScore ++; + } else if (this.receipts <= 80 && this.receipts < this.end) { + this.totalScore --; + } else if (this.receipts >= this.end) { + alert("Your crew got too behind on receipts! You lose - try again."); + location.reload(); +} + + if (this.horde > 70) { + this.totalScore ++; + } else if (this.horde <= 70 && this.horde < this.end) { + this.totalScore ++; + } else if (this.horde >= this.end) { + alert("Your crew got too behind on receipts! You lose - try again."); + location.reload(); +} $("#score").text(this.totalScore); }; -var crew = new SpaceShip(50, 100); +var crew = new SpaceShip(0, 3); $(document).ready(function(){ crew.status(); From 7e0e8f6edc938870d8e19c3bb9a019e77d3aa43f Mon Sep 17 00:00:00 2001 From: Sarah Date: Thu, 7 Apr 2016 14:02:45 -0700 Subject: [PATCH 15/15] Finalized conditions for losing game --- spaceship.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/spaceship.js b/spaceship.js index 05616e8..b7595a3 100644 --- a/spaceship.js +++ b/spaceship.js @@ -67,22 +67,22 @@ SpaceShip.prototype.score = function(){ location.reload(); } - if (this.receipts > 70) { + if (this.receipts < 70) { this.totalScore ++; - } else if (this.receipts <= 80 && this.receipts < this.end) { + } else if (this.receipts >= 70 && this.receipts > this.end) { this.totalScore --; - } else if (this.receipts >= this.end) { + } else if (this.receipts > this.end) { alert("Your crew got too behind on receipts! You lose - try again."); location.reload(); } - if (this.horde > 70) { - this.totalScore ++; - } else if (this.horde <= 70 && this.horde < this.end) { - this.totalScore ++; - } else if (this.horde >= this.end) { - alert("Your crew got too behind on receipts! You lose - try again."); - location.reload(); +if (this.horde < 70) { + this.totalScore ++; +} else if (this.horde >= 70 && this.horde > this.end) { + this.totalScore --; +} else if (this.horde > this.end) { + alert("You didn't find enough treasure! You lose - try again."); + location.reload(); } $("#score").text(this.totalScore); };
Thing To Watch Out ForCurrent StatusStatus of ShipCurrent Level
Thirst StatusThirst
Work StatusWork
Horde StatusHorde
Hunger StatusHunger
Receipt StatusReceipt