Exemplo n.º 1
0
 static void play(Player player) {
   String playerInput;
   boolean gameOn = true;
   boolean start = true;
   boolean goblinAlive = true;
   playerInput = "help";
   while (gameOn == true) {
     Scanner input = new Scanner(System.in);
     if (!start) {
       playerInput = input.next();
     }
     start = false;
     switch (playerInput.toLowerCase()) {
       case "north":
         player.moveTo(player.getLocation().north());
         break;
       case "south":
         player.moveTo(player.getLocation().south());
         break;
       case "east":
         player.moveTo(player.getLocation().east());
         break;
       case "west":
         player.moveTo(player.getLocation().west());
         break;
       case "look":
         player.look();
         break;
       case "drop":
         player.drop(input.next());
         break;
       case "pickup":
         player.pickup(input.next());
         break;
       case "inventory":
         player.inventory();
         break;
       case "quit":
         gameOn = false;
         break;
       case "xyzzy":
         if (player.getLocation().getName().equals("Room 5")) {
           System.out.println(
               "A red portal opens in front of you, and you walk into it without thinking. \nYou are still inside the cave. You see a chest in the center of the room.");
           player.moveTo(player.getLocation().xyzzy());
         } else {
           System.out.println("Nothing happens.");
         }
         break;
       case "help":
         printInstructions();
         break;
       case "use":
         switch (input.next()) {
           case "man":
             if (player.getLocation().getName().equals("Room 1")) {
               player.use();
             }
           case "well":
             if (player.getLocation().getName().equals("Room 7")) {
               player.use();
             }
           case "skeleton":
             if (player.getLocation().getName().equals("Room 2")) {
               player.use();
             }
           case "writing":
             if (player.getLocation().getName().equals("Room 8")) {
               player.use();
             }
           case "ears":
             if (player.getLocation().getName().equals("Room 3")) {
               player.use();
             }
           case "chest":
             if (player.getLocation().getName().equals("Room 6")) {
               player.use();
             }
         }
         break;
       default:
         System.out.println("What?");
     }
     if (player.getLocation().getName().equals("Room 4") && goblinAlive) {
       gameOn = goblinChase(player);
       goblinAlive = false;
     }
   }
   System.out.println("Game Over");
 }
Exemplo n.º 2
0
 static boolean goblinChase(Player player) {
   String playerInput = "";
   System.out.println("As you enter the room a goblin jumps out of the darkness and runs at you.");
   System.out.println("You feel the urge to either fight or run.");
   for (int i = 5; i > 0; i--) {
     Scanner input = new Scanner(System.in);
     playerInput = input.next();
     switch (playerInput.toLowerCase()) {
       case "north":
         player.moveTo(player.getLocation().north());
         break;
       case "south":
         player.moveTo(player.getLocation().south());
         break;
       case "east":
         player.moveTo(player.getLocation().east());
         break;
       case "west":
         player.moveTo(player.getLocation().west());
         break;
       case "look":
         player.look();
         break;
       case "drop":
         player.drop(input.next());
         break;
       case "pickup":
         player.pickup(input.next());
         break;
       case "inventory":
         player.inventory();
         break;
       case "quit":
         return false;
       case "xyzzy":
         if (player.getLocation().getName().equals("Room 5")) {
           System.out.println(
               "A red portal opens in front of you, and you walk into it without thinking. \n You are still inside the cave. You see a chest in the center of the room.");
           player.moveTo(player.getLocation().xyzzy());
         } else {
           System.out.println("Nothing happens.");
         }
         break;
       case "help":
         printInstructions();
         break;
       case "use":
         switch (input.next()) {
           case "man":
             if (player.getLocation().getName().equals("Room 1")) {
               player.use();
             }
           case "well":
             if (player.getLocation().getName().equals("Room 7")) {
               player.use();
             }
           case "skeleton":
             if (player.getLocation().getName().equals("Room 2")) {
               player.use();
             }
           case "writing":
             if (player.getLocation().getName().equals("Room 8")) {
               player.use();
             }
           case "ears":
             if (player.getLocation().getName().equals("Room 3")) {
               player.use();
             }
           case "chest":
             if (player.getLocation().getName().equals("Room 6")) {
               player.use();
             }
         }
       case "fight":
         if (player.getInventory().contains("sword")) {
           System.out.println("You decide to turn and fight.");
           System.out.println(
               "You pull out the sword you picked up earlier, the only weapon you have.");
           System.out.println(
               "As the goblin charges, you stand your ground and take a fighting stance.");
           System.out.println(
               "You plunge your sword into the goblin's chest with one decisive thrust.");
           System.out.println(
               "The goblin falls to the ground in front of you as you pull out the bloody sword.");
           System.out.println("You examine the body. The goblin is dead.");
           player.getLocation().drop("goblin");
           return true;
         } else {
           if (player.getLocation().getName().equals("Room 7")) {
             System.out.println("You decide to turn and fight.");
             System.out.println("As the goblin charges, you swing at him with all of your might.");
             System.out.println("The goblin is knocked back slightly and trips over a rock.");
             System.out.println(
                 "The goblin falls into the well situated in the center of the room.");
             System.out.println("As he falls you hear him screech, and eventually a loud THUNK!");
             System.out.println(
                 "You approach the well and look inside it, but you can't see anything, even with the lamp.");
             return true;
           } else {
             if (1 == 1) {
               System.out.println("The goblin grabs you and tears your arm off.");
               System.out.println(
                   "Wounded, you slowly bleed out as you watch the goblin eat your severed arm.");
               return false;
             }
           }
         }
         break;
       default:
         System.out.println("What?");
     }
     switch (i) {
       case 5:
         System.out.println(
             "The goblin seems dazed by the light of the lantern and trips over a rock.");
         break;
       case 4:
         System.out.println("The goblin gets up and persues you.");
         break;
       case 3:
         System.out.println(
             "You try to escape the goblin's pursuit, but he is slowly getting closer.");
         ;
         break;
       case 2:
         System.out.println("The goblin has nearly caught up to you.");
         break;
       case 1:
         System.out.println("The goblin is right behind you, there is no hope for escape.");
         break;
     }
   }
   System.out.println("The goblin grabs you and tears your arm off.");
   System.out.println(
       "Wounded, you slowly bleed out as you watch the goblin eat your severed arm.");
   return false;
 }