-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Planet Express in Ruby, Java and Python #8
base: master
Are you sure you want to change the base?
Changes from all commits
ba5ba76
be97125
fce060f
83e2a93
9a5f912
eb9bab6
0686486
f4ce702
1003c61
a61623e
c8e6939
379f7d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/bin/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>planet-express</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
|
||
public class Crew { | ||
int thirst = 50; | ||
int work = 50; | ||
int horde = 50; | ||
int hunger = 50; | ||
int receipts = 50; | ||
boolean stable = true; | ||
int score = 50; | ||
|
||
public void drink() { | ||
thirst -= 5; | ||
work += 5; | ||
} | ||
|
||
public void deliver() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm i'm curious if the indentation that is showing here is how it looks in your IDE? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't look like that in the IDE! I noticed that on the PR as well but I have no idea why it's doing that :( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK - no worries, just curious |
||
work -= 5; | ||
receipts += 5; | ||
} | ||
|
||
public void steal() { | ||
horde += 5; | ||
work += 5; | ||
} | ||
|
||
public void eat() { | ||
hunger -= 5; | ||
work += 5; | ||
} | ||
|
||
public void account() { | ||
receipts -= 5; | ||
horde -= 5; | ||
} | ||
|
||
public int score() { | ||
if (thirst >= 100 || work >= 100 || horde <= 0 || hunger >= 100 || receipts <= 0) { | ||
score = 0; | ||
} | ||
return score; | ||
} | ||
|
||
public boolean check() { | ||
if (score <= 0) { | ||
stable = false; | ||
return false; | ||
} | ||
else { | ||
if (thirst >= 85) { | ||
System.out.println("Fry is scary-thirsty!"); | ||
} | ||
|
||
if (work >= 85) { | ||
System.out.println("Leela is exhausted from all this work!"); | ||
} | ||
|
||
if (horde <= 15) { | ||
System.out.println("Bender is sad because he doesn't have enough treasure!"); | ||
} | ||
|
||
if (hunger >= 85) { | ||
System.out.println("Zoidberg is going to eat something and it's not going to be pretty!"); | ||
} | ||
|
||
if (receipts <= 15) { | ||
System.out.println("Hermes doesn't have enough receipts!"); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Program { | ||
|
||
public static void main (String[] args) { | ||
Crew spaceship = new Crew(); | ||
System.out.println(spaceship.check()); | ||
System.out.println(spaceship.work); | ||
for (int i = 0; i < 7; i++) { | ||
spaceship.drink(); | ||
} | ||
System.out.println(spaceship.work); | ||
System.out.println(spaceship.check()); | ||
for (int j = 0; j < 3; j++) { | ||
spaceship.drink(); | ||
} | ||
System.out.println(spaceship.work); | ||
System.out.println(spaceship.score()); | ||
System.out.println(spaceship.check()); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
class Crew: | ||
'defines some properties about the crew of the spaceship' | ||
|
||
def __init__(self): | ||
self.thirst = 50 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment re: constants |
||
self.work = 50 | ||
self.horde = 50 | ||
self.hunger = 50 | ||
self.receipts = 50 | ||
self.stable = True | ||
self.score = 50 | ||
|
||
def drink(self): | ||
self.thirst -= 5 | ||
self.work += 5 | ||
|
||
def deliver(self): | ||
self.work -= 5 | ||
self.receipts += 5 | ||
|
||
def steal(self): | ||
self.horde += 5 | ||
self.work += 5 | ||
|
||
def eat(self): | ||
self.hunger -= 5 | ||
self.work += 5 | ||
|
||
def account(self): | ||
self.receipts -= 5 | ||
self.horde -= 5 | ||
|
||
def current_score(self): | ||
if self.thirst >= 100 or self.work >= 100 or self.horde <= 0 or self.hunger >= 100 or self.receipts <= 0: | ||
self.score = 0 | ||
return self.score | ||
|
||
def check(self): | ||
# if score is too low, end the game | ||
if self.score <= 0: | ||
self.stable = False | ||
return False | ||
else: | ||
# check to see if you need to print warnings | ||
if self.thirst >= 85: | ||
print "Fry is scary thirsty!" | ||
|
||
if self.work >= 85: | ||
print "Leela is exhausted from all this work!" | ||
|
||
if self.horde <= 15: | ||
print "Bender is sad because he doesn't have enough treasure!" | ||
|
||
if self.hunger >= 85: | ||
print "Zoidberg is going to eat something and it's not going to be pretty!" | ||
|
||
if self.receipts <= 15: | ||
print "Hermes doesn't have enough receipts!" | ||
|
||
return True |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import crew | ||
|
||
spaceship = crew.Crew() | ||
|
||
print spaceship.check() | ||
print spaceship.work | ||
for i in range(0,7): | ||
spaceship.drink() | ||
print spaceship.work | ||
print spaceship.check() | ||
for j in range(0,3): | ||
spaceship.drink() | ||
print spaceship.work | ||
print spaceship.current_score() | ||
print spaceship.check() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
class Crew | ||
attr_accessor :thirst, :work, :horde, :hunger, :receipts, :stable | ||
|
||
def initialize | ||
@thirst = 50 | ||
@work = 50 | ||
@horde = 50 | ||
@hunger = 50 | ||
@receipts = 50 | ||
@stable = true | ||
@score = 50 | ||
end | ||
|
||
def drink | ||
@thirst -= 5 | ||
@work += 5 | ||
end | ||
|
||
def deliver | ||
@work -= 5 | ||
@receipts += 5 | ||
end | ||
|
||
def steal | ||
@horde += 5 | ||
@work += 5 | ||
end | ||
|
||
def eat | ||
@hunger -= 5 | ||
@work += 5 | ||
end | ||
|
||
def account | ||
@receipts -= 5 | ||
@horde -= 5 | ||
end | ||
|
||
def score | ||
if @thirst >= 100 || @work >= 100 || @horde <= 0 || @hunger >= 100 || @receipts <= 0 | ||
@score = 0 | ||
end | ||
end | ||
|
||
def check | ||
# if score is too low, end game | ||
if @score <= 0 | ||
@stable = false | ||
return false | ||
else | ||
# check to see if you need to print warnings | ||
if @thirst >= 85 | ||
puts "Fry is scary-thirsty!" | ||
end | ||
|
||
if @work >= 85 | ||
puts "Leela is exhausted from all this work!" | ||
end | ||
|
||
if @horde <= 15 | ||
puts "Bender is sad because he doesn't have enough treasure!" | ||
end | ||
|
||
if @hunger >= 85 | ||
puts "Zoidberg is going to eat something and it's not going to be pretty!" | ||
end | ||
|
||
if @receipts <= 15 | ||
puts "Hermes doesn't have enough receipts!" | ||
end | ||
|
||
return true | ||
end | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require "./crew.rb" | ||
|
||
spaceship = Crew.new | ||
|
||
puts spaceship.check | ||
puts spaceship.work | ||
7.times do | ||
spaceship.drink | ||
end | ||
puts spaceship.work | ||
puts spaceship.check | ||
3.times do | ||
spaceship.drink | ||
end | ||
puts spaceship.work | ||
puts spaceship.score | ||
puts spaceship.check |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using constants for these values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand what you mean by using constants. Isn't the game supposed to change the value of the thirst, horde, etc? How can those values change if they're constants?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I mean for the
50
s. If you wanted to change the start value for all properties, you could just change the constant one time.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohhh I see, thanks for the clarification