import java.util.Scanner; public class Game { public static void main(String[] args) { GameState g = new GameState(); while(true) { displayLocation(g); playerDecision(g); } } //==================================================== //==================================================== //==================================================== public static void displayLocation(GameState g) { String msg = ""; //=========================== //WELL //=========================== if (g.location == Loc.WELL) { if (g.firstTimeWell==true) { msg="You wake up with a sharp headache. You are confused. Uncertain of who or where you are. You see a well nearby. You consider taking a DRINK. There is also an OLDHOUSE in the north. To the south, you see a path that leads to a BRIDGE. To west, there seems to be a FARM. And to the east, a MINE."; g.firstTimeWell = false; } else if (g.firstTimeWell==false) { msg="You see a well nearby. You consider taking a DRINK. There is also an OLDHOUSE in the north. To the south, you see a path that leads to a BRIDGE. To west, there seems to be a FARM. And to the east, a MINE."; if (g.firstTimeOldHouse == false && Math.random() < 0.2) { msg = msg + " Strangely, despite being at least a kilometer from Sir William, you can hear his voice very clearly. You think to yourself that he must have special voice powers."; } } } //=========================== //OLD HOUSE //=========================== else if (g.location == Loc.OLDHOUSE) { if(g.firstTimeOldHouse==true) { msg="As you approach the old house, a suspicious looking individual approaches you. \"Hello, my name is Sir William. You seem lost. If ever you are looking for work, I am looking for someone to fetch a WATERMELON from the farm. Just tell them Willy sent you.\" Strangely, despite you wearing very different and uncommon shoes, Sir William has the exact same pair as you do. To the north, there is a large castle GATE. To south, there is a WELL off in the distance."; g.firstTimeOldHouse = false; } else if (g.hasWatermelon == false) { msg="Sir William is sitting on his old porch. He is clearly hoping that you fetch him a WATERMELON soon. The castle GATE is to the north and the WELL is to the south."; } else if (g.hasWatermelon==true && g.hasSword == false) { g.hasWatermelon = false; g.hasSword = true; msg="Well thank you for the melon! Here is my old sword to help you on your journey. Bring me another WATERMELON and I'll show you how to use that sword. The castle GATE is to the north and the WELL is to the south."; } else if (g.hasWatermelon==true && g.hasSword == true && g.hasSwordTraining == false) { msg="You arrive at the old house. Sir William: 'Well thank you for the WATERMELON! As they say, when life gives you melons, make melonaid! Now, for your payment, I can TRAIN you anytime to use the sword.' The castle GATE is to the north andther WELL is to the south."; g.hasWatermelon = false; g.canTrain = true; } else if (g.hasWatermelon==true && g.hasSword == true && g.hasSwordTraining == true) { msg="You arrive to the old house. Sir William: 'Thanks for the WATERMELON.' The castle GATE is to the north andther WELL is to the south."; g.hasWatermelon = false; g.canTrain = false; } else if(g.justSaidWatermelon==true) { g.justSaidWatermelon = false; msg="Sir William: 'Oh I love WATERMELON! "; if (Math.random() < 0.5) { msg = msg + "Here's a joke. Why do watermelons have fancy weddings? Because they cantaloupe!/n"; } else { msg = msg + "Here's a joke. When do you go at red and stop at green? When you're eating a watermelon!/n"; } msg = msg + "You can go to the castle GATE or to the WELL."; } } //=========================== //FARM //=========================== else if (g.location == Loc.FARM) { if (g.firstTimeOldHouse == true) { System.out.println("You arrive at the farm. A young woman asks you to LEAVE as she is occupied."); } else if (g.hasWatermelon == false) { System.out.println("You arrive at the farm. You are met by an old farmer that asks you to LEAVE. You mention Sir William and you are given a watermelon to go with."); g.hasWatermelon = true; } else if (g.hasWatermelon == true) { System.out.println("You arrive at the farm. You are met by a seemingly fatigued man. 'You really need to bring that watermelon to Sir Willy before it goes bad. Please LEAVE.'"); } } //=========================== //FARM //=========================== else if (g.location == Loc.MINE) { System.out.println("You arrive at the abandoned mine. If the creator of this world had more time, there would be a cool quest here. But there isn't. All you can do is go back to the WELL."); } //=========================== //BRIDGE //=========================== else if (g.location == Loc.BRIDGE) { if (g.justExplored == false && g.hasTrollClub==false) { System.out.println("You arrive at the bridge. It is baracaded. Somebody doesn't want others to pass. You hear noises coming from underneath the bridge. You can go EXPLORE them. You can also go back to the WELL."); } else if (g.hasTrollClub == true) { System.out.println("The bridge is no longer blocked. You should go inform the castle so the guards could come remove the baracade. Go back to the WELL."); } } //=========================== //GATE //=========================== else if (g.location == Loc.GATE) { if (g.hasTrollClub==true) { System.out.println("You arrive at the castle's gate. The guard immediately notices the troll's club and proclaims you the saviour of the land. You are welcomed into the castle."); System.out.println("*****YOU WIN!******"); System.exit(0); } else if (g.hasTrollClub==false) { System.out.println("You arrive at the castle's gate. The guard asks you to halt. 'What do you want? You think we let anybody in? We have enough trouble with that troll living under the bridge. Go away! Your only option is to go back to the OLDHOUSE."); } } System.out.println(msg); } //==================================================== //==================================================== //==================================================== //==================================================== //==================================================== //==================================================== //==================================================== //==================================================== //==================================================== //==================================================== //==================================================== //==================================================== public static void playerDecision(GameState g) { boolean done = false; while (!done) { System.out.print(">"); Scanner s = new Scanner(System.in); String option = s.next().toUpperCase(); done = true; //==================================================== //==================================================== if (g.location == Loc.WELL) { if (option.equals("DRINK")) { System.out.println("You drink from the well. It is poisoned. You die a painful death."); System.out.println("*****GAME OVER*****"); System.exit(0); } else if (option.equals("OLDHOUSE")) { System.out.println("You walk towards the old house."); System.out.println("***********"); g.location = Loc.OLDHOUSE; } else if (option.equals("FARM")) { System.out.println("You head over towards the farm."); System.out.println("***********"); g.location = Loc.FARM; } else if (option.equals("BRIDGE")) { System.out.println("You jog down the path to the bridge."); System.out.println("***********"); g.location = Loc.BRIDGE; } else if (option.equals("MINE")) { System.out.println("You hesitantly start walking towards the mine."); System.out.println("***********"); g.location = Loc.MINE; } else { System.out.println(""); done = false; } } //==================================================== //==================================================== else if (g.location == Loc.OLDHOUSE) { if (option.equals("GATE")) { g.location = Loc.GATE; System.out.println("You head out for the gate."); System.out.println("***********"); } else if(option.equals("WELL")) { System.out.println("To the well you go."); System.out.println("***********"); g.location = Loc.WELL; } else if(option.equals("WATERMELON")) { System.out.println("You ask about watermelons."); System.out.println("***********"); g.justSaidWatermelon = true; } else if(option.equals("TRAIN") && g.canTrain==true) { System.out.println("Sir William spends several hours training you how to use a sword."); System.out.println("***********"); g.canTrain = false; g.hasSwordTraining = true; } else { System.out.println(""); done = false; } } //==================================================== //==================================================== else if (g.location == Loc.FARM) { if (option.equals("LEAVE")) { System.out.println("You go back towards the well."); System.out.println("***********"); g.location = Loc.WELL; } else { System.out.println(""); done = false; } } //==================================================== //==================================================== else if (g.location == Loc.MINE) { if (option.equals("WELL")) { System.out.println("You go back towards the well."); System.out.println("***********"); g.location = Loc.WELL; } else { System.out.println(""); done = false; } } //==================================================== //==================================================== else if (g.location == Loc.BRIDGE) { if (option.equals("WELL")) { System.out.println("You go back towards the well."); System.out.println("***********"); g.location = Loc.WELL; } else if (option.equals("EXPLORE") && g.hasSword==false) { System.out.println("Being the fool that you are, you go under the bridge. A massive troll attacks you. You don't even have a sword. It's over."); System.out.println("*****GAME OVER******"); System.exit(0); } else if (option.equals("EXPLORE") && g.hasSwordTraining==false) { System.out.println("Being the fool that you are, you go under the bridge. A massive troll attacks you. You try to swing your sword but you cut your own ear off. The troll laughs, then feels bad for you, then finishes you off."); System.out.println("*****GAME OVER******"); System.exit(0); } else if (option.equals("EXPLORE") && g.hasSwordTraining==true) { System.out.println("Being the fool that you are, you go under the bridge. A massive troll attacks you. You are prepared with your sword and you slay your enemy. You pickup the troll's club and can now return to the WELL."); System.out.println("***********"); g.hasTrollClub = true; } else { System.out.println(""); done = false; } } //==================================================== //==================================================== else if (g.location == Loc.GATE) { if (option.equals("OLDHOUSE")) { System.out.println("You return to the old house."); System.out.println("***********"); g.location = Loc.OLDHOUSE; } else { System.out.println(""); done = false; } } //==================================================== //==================================================== else { done = false; } }//end while } }