Skip to content
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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
6 changes: 6 additions & 0 deletions planet-express/java/.classpath
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>
1 change: 1 addition & 0 deletions planet-express/java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
17 changes: 17 additions & 0 deletions planet-express/java/.project
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>
Binary file added planet-express/java/src/Crew.class
Binary file not shown.
74 changes: 74 additions & 0 deletions planet-express/java/src/Crew.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

public class Crew {
int thirst = 50;

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

Copy link
Author

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?

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 50s. If you wanted to change the start value for all properties, you could just change the constant one time.

Copy link
Author

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

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() {

Choose a reason for hiding this comment

The 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?

Copy link
Author

Choose a reason for hiding this comment

The 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 :(

Choose a reason for hiding this comment

The 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;
}

}

}
Binary file added planet-express/java/src/Program.class
Binary file not shown.
20 changes: 20 additions & 0 deletions planet-express/java/src/Program.java
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());
}

}
60 changes: 60 additions & 0 deletions planet-express/python/crew.py
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

Choose a reason for hiding this comment

The 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
Binary file added planet-express/python/crew.pyc
Binary file not shown.
15 changes: 15 additions & 0 deletions planet-express/python/program.py
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()
76 changes: 76 additions & 0 deletions planet-express/ruby/crew.rb
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
17 changes: 17 additions & 0 deletions planet-express/ruby/program.rb
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