/** * This class represents the Control within our game. */ public class Control { /** * CS 101/101E students: Add your comments here */ public static void printLocationCommands() { System.out.println ("Valid commands are (and 'x' means not yet implemented):"); System.out.println ("\tmove (to move to another location)"); System.out.println ("\tdepot (to enter the depot, if present)"); System.out.println ("\tworldmap (to print out the map)"); System.out.println ("\tinventory (to show your inventory)"); System.out.println ("\trest (to rest for a specified number of days)"); System.out.println ("x\thunt (to forage/hunt for food)"); System.out.println ("x\ttrade (to attempt to trade)"); System.out.println ("x\tpace (change pace)"); System.out.println ("x\tfood (change food rations)"); System.out.println ("\tcheck (check on your party's status)"); System.out.println ("\txcheat (enable cheat mode)"); System.out.println ("\tquit (to leave the game)"); System.out.println ("You can abbreviate any command by its first letter"); } /** * CS 101/101E students: Add your comments here */ public static void possiblyEndGame() { // if people are alive and the player is not at the destination, don't do anything if ( Game.player.getParty().isAnybodyAlive() && ( (Game.player.getLocation().getPosRow() != Game.FINISH_ROW_COORD) || (Game.player.getLocation().getPosCol() != Game.FINISH_COL_COORD) ) ) return; if ( Game.player.getParty().isAnybodyAlive() ) { System.out.println ("\nYou reached your destination!"); System.out.println ("\nYou are at: " + Game.player.getLocation()); System.out.println ("You have $" + Game.style.format(Game.player.getInventory().getMoney()) + " on hand"); System.out.println ("You have travelled " + Game.style.format(Game.player.getTotalDistanceTraveled()) + " " + Game.DISTANCE_UNIT + " over " + Game.style.format(Game.player.getTotalTimeTaken()) + " days"); Game.player.getParty().printPartyStatus(); } else { System.out.println ("I'm sorry, all the members in your party have died. Game over."); } System.exit(0); } /** * CS 101/101E students: Add your comments here. * * @param movementTime The amount of time to move. * @param numOxen The number of propulsion items (oxen, rockets, etc.) * @param isMoving boolean flag to indicate whether or not the Vehicle is moving */ public static void advanceTurn (double movementTime, int numOxen, boolean isMoving) { System.out.println ("advanceTurn() called"); // update total distance traveled if the vehicle is moving if ( isMoving ) Game.player.setTotalDistanceTraveled (Game.player.getTotalDistanceTraveled() + Game.DISTANCE_BETWEEN_SQUARES); // handle speed of movement double timeTaken = 1.0/(1.0 - 1.0/(numOxen+1)) * Game.DISTANCE_BETWEEN_SQUARES * movementTime * Game.OXEN_SPEED_FACTOR; System.out.println ("With " + numOxen + " " + Descriptions.getPropulsionName().toLowerCase() + ", it takes you " + Game.style.format(timeTaken) + " days to move one square." + movementTime ); Game.player.setTotalTimeTaken (Game.player.getTotalTimeTaken() + timeTaken); // handle eating of food int foodLeft = Game.player.getInventory().getFood(); int foodNeeded = Game.FOOD_CONSUMPTION_RATE * Game.player.getParty().getNumberAlive(); Game.player.getInventory().setFood(foodLeft-foodNeeded); boolean starving = false; if ( foodNeeded > foodLeft ) { System.out.println ("You don't have enough food! Your party is starving."); Game.player.getParty().starve(); starving = true; } // check for health problems if ( isMoving && !Game.cheatModeEnabled ) { if ( Game.random.nextDouble() < Game.HEALTH_PROBLEM_CHANCE ) { Person whoIsSick = Game.player.getParty().pickRandomPerson(); String affliction = Descriptions.generateRandomHealthEvent(); int affectedAmount = Descriptions.getCorrespondingHealthChange(affliction); whoIsSick.changeHealth(affectedAmount); System.out.println ("\n" + whoIsSick + " " + affliction + "\n"); } } else if ( !starving ) { for ( int i = 0; i < Game.player.getParty().getCurrentPartySize(); i++ ) if ( Game.player.getParty().getPerson(i) != null ) (Game.player.getParty().getPerson(i)).changeHealth((int) movementTime); } } /** * Add your comments here */ public static void takeTurn(){ while(true){ System.out.println ("\nYou are at: " + Game.player.getLocation()); System.out.println ("You have $" + Game.style.format(Game.player.getInventory().getMoney()) + " on hand"); System.out.println ("You have travelled " + Game.style.format(Game.player.getTotalDistanceTraveled()) + " " + Game.DISTANCE_UNIT + " over " + Game.style.format(Game.player.getTotalTimeTaken()) + " days"); printLocationCommands(); int command = Parser.parse(); System.out.println(); switch(command){ case Parser.MOVE: Game.player.move(); break; case Parser.WORLDMAP: MapPrinter.printMap(); break; case Parser.DEPOT: if ( Game.player.getLocation().getDepot() == null ) System.out.println ("There is no depot here!"); else Game.player.getLocation().getDepot().enterDepot(Game.player); break; case Parser.INVENTORY: Game.player.getInventory().printInventory(1.0); break; case Parser.QUIT: System.out.println ("\nYou ended the game with $" + Game.style.format(Game.player.getInventory().getMoney())); System.out.println ("Goodbye!"); return; case Parser.REST: System.out.println ("How many days would you like to rest?"); int restAmount = Parser.getInteger(); advanceTurn(restAmount, Game.player.getInventory().getOxen(), false); break; case Parser.HUNT: // FALL THRU case Parser.TRADE: // FALL THRU case Parser.PACE: // FALL THRU case Parser.FOOD: System.out.println ("That command not yet implemented."); break; case Parser.CHECK: Game.player.getParty().printPartyStatus(); break; case Parser.XCHEAT: Game.cheatModeEnabled = true; Game.player.getInventory().setMoney(1000000); Game.player.getInventory().setFood(1000000); Game.player.getInventory().setAmmunition(1000000); System.out.println ("Cheat mode enabled."); break; default: System.out.println ("I don't understand that input. Try again"); break; } } } }