Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions planet-express/PlanetExpress.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
class PlanetExpress:
def __init__(self):
self.thirst = 50

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might recommend using some constants for these 50 and the 4 values

self.work = 50
self.receipts = 50
self.horde = 50
self.hunger = 50
self.stable = True

def drink(self):
self.thirst -= 4
self.work += 4

def deliver(self):
self.receipts += 4
self.work -= 4

def steal(self):
self.horde += 4
self.work += 4

def eat(self):
self.hunger -= 4
self.work += 4

def account(self):
self.receipts -= 4
self.horde -= 4

def score(self):
horde_score = self.horde * 1000
thirst_score = self.thirst * -20
receipts_score = self.receipts * -30
work_score = self.work * -20
hunger_score = self.hunger * -15
return horde_score + thirst_score + receipts_score + work_score + hunger_score


def check(self):
if (self.thirst >= 90 and self.thirst < 100):
print "Warning! Fry is very thirsty and is in danger of crashing the ship."
if (self.work >= 90 and self.work < 100):
print "Warning! Leela has tons of work and is in danger of crashing the ship."
if (self.horde <= 10 and self.work > 0):
print "Warning! Bender's horde is very low and is in danger of crashing the ship."
if (self.hunger >= 90 and self.hunger < 100):
print "Warning! Zoidberg is very hungry and is in danger of crashing the ship."
if (self.receipts >= 90 and self.receipts < 100):
print "Warning! Hermes' backlog of receipts is huge and is in danger of crashing the ship."
if (self.thirst > 100 or self.work > 100 or self.hunger > 100 or self.horde <= 0 or self.receipts > 100):
self.stable = False
return self.stable

p = PlanetExpress()
print "Welcome to Planet Express!"
while p.stable:
action = raw_input("Type drink, deliver, steal, eat, or account to continue playing.\n")
while action.lower() != "drink" and action.lower() != "deliver" and action.lower() != "steal" and action.lower() != "eat" and action.lower() != "account":
print "That's not a valid choice. Try again."
action = raw_input("Type drink, deliver, steal, eat, or account to continue playing.\n")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don't have closing blocks in Python, it's important to use your whitespace to separate the blocks of code. After the while, after the if block, etc.

if action == "drink":
p.drink()
elif action == "deliver":
p.deliver()
elif action == "steal":
p.steal()
elif action == "eat":
p.eat()
elif action == "account":
p.account()
print "Score: {}".format(p.score())
if not p.check():
print "GAME OVER"
6 changes: 6 additions & 0 deletions planet-express/PlanetExpress/.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/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions planet-express/PlanetExpress/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>PlanetExpress</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>
11 changes: 11 additions & 0 deletions planet-express/PlanetExpress/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
Binary file not shown.
110 changes: 110 additions & 0 deletions planet-express/PlanetExpress/src/planet/PlanetExpress.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package planet;

import java.util.Scanner;

public class PlanetExpress {
int thirst;
int work;
int receipts;
int horde;
int hunger;
boolean stable;

PlanetExpress() {
thirst = 50;
work = 50;
receipts = 50;
horde = 50;
hunger = 50;
stable = true;

}

public static void main(String[] args) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make sense to have a separate file like Program that only contained the "runner" part of the program

PlanetExpress p = new PlanetExpress();
System.out.println("Welcome to Planet Express!");
while (p.stable) {
Scanner reader = new Scanner(System.in); // Reading from System.in
System.out.println("Type drink, deliver, steal, eat, or account to continue playing.");
String input = reader.next();
while (!input.toLowerCase().equals("drink") && !input.toLowerCase().equals("deliver") && !input.toLowerCase().equals("steal")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like you should be doing the lower case operation only once rather than in each of these equivalence checks

&& !input.toLowerCase().equals("eat") && !input.toLowerCase().equals("account")) {
System.out.println("That's not a valid choice. Try again.");
System.out.println("Type drink, deliver, steal, eat, or account to continue playing.");
input = reader.next();
}
if (input.equals("drink")) {
p.drink();
} else if (input.equals("deliver")) {
p.deliver();
} else if (input.equals("steal")) {
p.steal();
} else if (input.equals("eat")) {
p.eat();
} else if (input.equals("account")) {
p.account();
}
System.out.println("Score: " + p.score());
if (!p.check()) {
System.out.println("GAME OVER");
}
}
}

public void drink() {
thirst -= 4;
work += 4;
}

public void deliver() {
receipts += 4;
work += 4;
}

public void steal() {
horde += 4;
work += 4;
}

public void eat() {
hunger -= 4;
work += 4;
}

public void account() {
receipts -= 4;
horde -= 4;
}

public int score() {
int hordeScore = horde * 1000;
int thirstScore = thirst * -20;
int receiptsScore = receipts * -30;
int workScore = work * -20;
int hungerScore = hunger * -15;
return hordeScore + thirstScore + receiptsScore + workScore + hungerScore;
}

public boolean check() {
if (thirst >= 90 && thirst < 100) {
System.out.println("Warning! Fry is very thirsty and is in danger of crashing the ship.");
}
if (work >= 90 && work < 100) {
System.out.println("Warning! Leela has tons of work and is in danger of crashing the ship.");
}
if (horde <= 10 && work > 0) {
System.out.println("Warning! Bender's horde is very low and is in danger of crashing the ship.");
}
if (hunger >= 90 && hunger < 100) {
System.out.println("Warning! Zoidberg is very hungry and is in danger of crashing the ship.");
}
if (receipts >= 90 && receipts < 100) {
System.out.println("Warning! Hermes' backlog of receipts is huge and is in danger of crashing the ship.");
}
if (thirst > 100 || work > 100 || hunger > 100 || horde <= 0 || receipts > 100) {
stable = false;
}
return stable;
}

}