-
Notifications
You must be signed in to change notification settings - Fork 16
Brittany Planet Express in Python and Java #3
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
base: master
Are you sure you want to change the base?
Changes from all commits
0aef5e9
4fed17d
c9007bb
a078aa7
5bf2db4
e4501bf
ac74703
65645e4
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,37 @@ | ||
| 41 0 637156 621361 652951 16.4 16.0 16.8 179110 171930 186290 21.3 20.4 22.2 117394 111176 123612 19.3 18.3 20.3 51088 50607 51569 56119 52798 59440 25.0 23.5 26.5 Oregon OR est14_OR.txt 06NOV2015 | ||
| 41 1 3232 2646 3818 20.6 16.9 24.3 897 706 1088 29.2 23.0 35.4 623 489 757 28.3 22.2 34.4 38966 35475 42457 Baker County OR est14_OR.txt 06NOV2015 | ||
| 41 3 15545 14152 16938 18.9 17.2 20.6 1864 1391 2337 13.0 9.7 16.3 1349 1001 1697 12.6 9.3 15.9 54089 49559 58619 Benton County OR est14_OR.txt 06NOV2015 | ||
| 41 5 37450 32707 42193 9.5 8.3 10.7 10896 8848 12944 12.6 10.2 15.0 7530 6063 8997 11.5 9.3 13.7 65555 62792 68318 Clackamas County OR est14_OR.txt 06NOV2015 | ||
| 41 7 5672 4567 6777 15.4 12.4 18.4 1621 1243 1999 22.7 17.4 28.0 1059 798 1320 20.6 15.5 25.7 45132 41123 49141 Clatsop County OR est14_OR.txt 06NOV2015 | ||
| 41 9 5880 4714 7046 12.0 9.6 14.4 1817 1396 2238 16.8 12.9 20.7 1222 925 1519 14.8 11.2 18.4 57517 52697 62337 Columbia County OR est14_OR.txt 06NOV2015 | ||
| 41 11 12144 10076 14212 19.8 16.4 23.2 3354 2614 4094 30.1 23.5 36.7 2322 1783 2861 28.9 22.2 35.6 39956 37328 42584 Coos County OR est14_OR.txt 06NOV2015 | ||
| 41 13 3809 3115 4503 18.3 15.0 21.6 1079 832 1326 27.2 21.0 33.4 721 549 893 23.6 18.0 29.2 38155 34688 41622 Crook County OR est14_OR.txt 06NOV2015 | ||
| 41 15 3780 3027 4533 17.1 13.7 20.5 858 643 1073 25.3 19.0 31.6 600 445 755 24.7 18.3 31.1 40524 37448 43600 Curry County OR est14_OR.txt 06NOV2015 | ||
| 41 17 22298 19233 25363 13.2 11.4 15.0 6345 4973 7717 17.8 14.0 21.6 4479 3445 5513 16.8 12.9 20.7 52387 49264 55510 Deschutes County OR est14_OR.txt 06NOV2015 | ||
| 41 19 21001 18102 23900 19.9 17.2 22.6 5769 4674 6864 28.5 23.1 33.9 3793 2976 4610 25.7 20.2 31.2 41504 39033 43975 Douglas County OR est14_OR.txt 06NOV2015 | ||
| 41 21 223 170 276 11.7 8.9 14.5 75 56 94 20.1 15.1 25.1 52 39 65 20.8 15.4 26.2 51978 46849 57107 Gilliam County OR est14_OR.txt 06NOV2015 | ||
| 41 23 1190 925 1455 16.8 13.1 20.5 355 268 442 27.1 20.4 33.8 241 179 303 24.8 18.4 31.2 41304 37034 45574 Grant County OR est14_OR.txt 06NOV2015 | ||
| 41 25 1489 1216 1762 21.3 17.4 25.2 434 347 521 31.6 25.3 37.9 270 205 335 26.9 20.4 33.4 36340 32642 40038 Harney County OR est14_OR.txt 06NOV2015 | ||
| 41 27 3298 2675 3921 14.6 11.8 17.4 1108 859 1357 20.1 15.6 24.6 727 551 903 18.1 13.7 22.5 54063 49516 58610 Hood River County OR est14_OR.txt 06NOV2015 | ||
| 41 29 37566 33104 42028 18.1 16.0 20.2 11174 9332 13016 25.9 21.6 30.2 6951 5552 8350 22.3 17.8 26.8 44835 42373 47297 Jackson County OR est14_OR.txt 06NOV2015 | ||
| 41 31 4513 3614 5412 21.2 17.0 25.4 1695 1319 2071 32.2 25.1 39.3 1138 872 1404 30.2 23.1 37.3 42753 39284 46222 Jefferson County OR est14_OR.txt 06NOV2015 | ||
| 41 33 16921 14086 19756 20.6 17.2 24.0 5188 4185 6191 33.3 26.9 39.7 3453 2723 4183 30.2 23.8 36.6 37230 34074 40386 Josephine County OR est14_OR.txt 06NOV2015 | ||
| 41 35 14092 12297 15887 21.9 19.1 24.7 4004 3246 4762 29.1 23.6 34.6 2613 2034 3192 26.6 20.7 32.5 39234 36331 42137 Klamath County OR est14_OR.txt 06NOV2015 | ||
| 41 37 1429 1105 1753 19.3 14.9 23.7 406 308 504 28.3 21.5 35.1 273 202 344 24.9 18.5 31.3 40328 36280 44376 Lake County OR est14_OR.txt 06NOV2015 | ||
| 41 39 64722 59856 69588 18.4 17.0 19.8 13379 10867 15891 20.1 16.3 23.9 8316 6528 10104 17.0 13.4 20.6 44976 42967 46985 Lane County OR est14_OR.txt 06NOV2015 | ||
| 41 41 8628 7219 10037 18.8 15.7 21.9 2320 1840 2800 30.3 24.0 36.6 1601 1262 1940 30.0 23.6 36.4 40226 37101 43351 Lincoln County OR est14_OR.txt 06NOV2015 | ||
| 41 43 22559 19999 25119 19.1 16.9 21.3 7215 6104 8326 26.8 22.7 30.9 4876 4083 5669 24.9 20.8 29.0 44358 41159 47557 Linn County OR est14_OR.txt 06NOV2015 | ||
| 41 45 7756 6587 8925 28.7 24.4 33.0 2891 2409 3373 38.3 31.9 44.7 2016 1666 2366 37.4 30.9 43.9 35094 31618 38570 Malheur County OR est14_OR.txt 06NOV2015 | ||
| 41 47 56064 49829 62299 17.7 15.7 19.7 20377 17489 23265 25.1 21.5 28.7 13302 11118 15486 22.6 18.9 26.3 48554 46347 50761 Marion County OR est14_OR.txt 06NOV2015 | ||
| 41 49 1824 1452 2196 16.3 13.0 19.6 694 532 856 22.3 17.1 27.5 465 349 581 20.2 15.2 25.2 51839 46569 57109 Morrow County OR est14_OR.txt 06NOV2015 | ||
| 41 51 141562 132955 150169 18.6 17.5 19.7 34845 30895 38795 23.2 20.6 25.8 21859 19012 24706 21.0 18.3 23.7 53519 51700 55338 Multnomah County OR est14_OR.txt 06NOV2015 | ||
| 41 53 10721 8883 12559 14.1 11.7 16.5 3052 2309 3795 17.2 13.0 21.4 2047 1526 2568 15.5 11.6 19.4 52626 49042 56210 Polk County OR est14_OR.txt 06NOV2015 | ||
| 41 55 241 184 298 14.2 10.8 17.6 70 53 87 23.4 17.6 29.2 48 35 61 20.3 15.0 25.6 53277 47661 58893 Sherman County OR est14_OR.txt 06NOV2015 | ||
| 41 57 4347 3567 5127 17.5 14.4 20.6 1213 946 1480 25.9 20.2 31.6 764 571 957 23.0 17.2 28.8 41662 38375 44949 Tillamook County OR est14_OR.txt 06NOV2015 | ||
| 41 59 13041 10920 15162 18.0 15.1 20.9 4894 3987 5801 25.2 20.5 29.9 3228 2583 3873 23.2 18.6 27.8 44780 41922 47638 Umatilla County OR est14_OR.txt 06NOV2015 | ||
| 41 61 4418 3706 5130 17.7 14.8 20.6 1219 956 1482 22.0 17.3 26.7 841 660 1022 21.1 16.6 25.6 44841 41885 47797 Union County OR est14_OR.txt 06NOV2015 | ||
| 41 63 1063 830 1296 15.8 12.3 19.3 319 245 393 26.1 20.0 32.2 215 164 266 24.6 18.7 30.5 39743 35852 43634 Wallowa County OR est14_OR.txt 06NOV2015 | ||
| 41 65 4192 3403 4981 16.8 13.6 20.0 1299 970 1628 23.4 17.5 29.3 912 675 1149 22.8 16.9 28.7 44010 39913 48107 Wasco County OR est14_OR.txt 06NOV2015 | ||
| 41 67 69403 63990 74816 12.5 11.5 13.5 21559 19144 23974 16.0 14.2 17.8 14247 12477 16017 14.5 12.7 16.3 66315 63653 68977 Washington County OR est14_OR.txt 06NOV2015 | ||
| 41 69 315 249 381 23.3 18.4 28.2 83 63 103 39.5 30.1 48.9 57 43 71 37.7 28.4 47.0 33387 29800 36974 Wheeler County OR est14_OR.txt 06NOV2015 | ||
| 41 71 14772 12562 16982 15.4 13.1 17.7 4744 3919 5569 20.5 16.9 24.1 3184 2576 3792 18.4 14.9 21.9 52903 49406 56400 Yamhill County OR est14_OR.txt 06NOV2015 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| class PlanetExpress: | ||
| def __init__(self): | ||
| self.thirst = 50 | ||
| 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") | ||
|
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. 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" | ||
| 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> |
| 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> |
| 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 |
| 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) { | ||
|
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 would make sense to have a separate file like |
||
| 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") | ||
|
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 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; | ||
| } | ||
|
|
||
| } | ||
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.
Might recommend using some constants for these 50 and the 4 values