Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  A description
Language: JAVA
Code:
// Capstone Program
// 
// Created and Written by: Corey Phetteplace
// "Escape the Mansion" (Working Title)

import java.util.*;



public class CapstoneProgram
{
     public static void main(String[] args)
     {
          // **********************************************************
          // Declare Variables and Objects
          // **********************************************************
          int counter    = 0;
          int lives      = 3;
          int useCounter = 0;
          
          Scanner userInput = new Scanner(System.in);
          
          
          String userName        = null;
          String userCommand     = null;
          String userProgression = null;
          String nextStandard    = null;
          String lookStandard    = null;
          String getStandard     = null;
          String useStandard     = null;
          
          String tutorialItem = "KNIFE";
          
          String itemOne     = "--NO ITEM--";
          String itemTwo     = "--NO ITEM--";
          String itemThree   = "--NO ITEM--";
          String itemFour    = "--NO ITEM--";
          String itemFive    = "--NO ITEM--";
          String itemSix     = "--NO ITEM--";
          String itemSeven   = "--NO ITEM--";
          String itemEight   = "--NO ITEM--";
          
          String[] itemArray = new String[8];
          itemArray[0] = itemOne  ;
          itemArray[1] = itemTwo  ;
          itemArray[2] = itemThree;
          itemArray[3] = itemFour ;
          itemArray[4] = itemFive ;
          itemArray[5] = itemSix  ;
          itemArray[6] = itemSeven;
          itemArray[7] = itemEight;
          
          
          // **********************************************************
          // START MENU
          // **********************************************************
          System.out.println("Hello player. Welcome to 'Escape the Mansion'");
          System.out.println("What is your name?");
          userName = userInput.nextLine();
          System.out.println("Irrelevant. I don't care about your name.");
          System.out.println("Let's begin " + userName + ":");
          System.out.println("*****************************************************");
          
          
          // **********************************************************
          // INSTRUCTIONS
          // **********************************************************
          // **********************************************************
          // NEXT
          // **********************************************************
          System.out.println("This game progresses by you typing in commands into the keyboard.");
          System.out.println("When you see '--NEXT--' press 'Enter' to progress.");
          System.out.println("--NEXT--");
          userProgression = userInput.nextLine();
          nextStandard = "NEXT";
          
          System.out.println("Very good.");
          System.out.println("");
                    
          // **********************************************************
          // LOOK
          // **********************************************************
          System.out.println("When you enter a new room you might want to LOOK around.");
          System.out.print  ("Typing 'LOOK' in will let you look at your surroundings and ");
          System.out.println("possibly find something that could help you.");
          System.out.println("Why don't you LOOK around?");
          userCommand = userInput.nextLine();
          lookStandard = "LOOK";
          
          if (userCommand.equalsIgnoreCase(lookStandard))
          {
               System.out.println("You looked around. There's nothing going on because the story hasn't started yet.");
               
          }
          else
          {
               do
               {
                    System.out.println("Woah, that's not right. Type 'LOOK.'");
                    userCommand = userInput.nextLine();
                    if (userCommand.equalsIgnoreCase(lookStandard))
                    {
                         System.out.print  ("You looked around. There's nothing going on ");
                         System.out.println("because the story hasn't started yet.");
                         counter++;
                    }
               }
               while (counter == 0);
          }
          counter = 0;
          
          System.out.println("--NEXT--");
          userProgression = userInput.nextLine();
          
          // **********************************************************
          // GET
          // **********************************************************
          System.out.println("Oh wait. There's a KNIFE on the ground.");
          System.out.println("You can type in 'GET' in order to get something.");
          userCommand = userInput.nextLine();
          getStandard = "GET";
          
          if (userCommand.equalsIgnoreCase(getStandard))
          {
               System.out.println("You got the knife!");
               System.out.println("Too bad there's no-one to use it on.");
               
          }
          else
          {
               do
               {
                    System.out.println("Hold on, that's not right. Type 'GET.'");
                    userCommand = userInput.nextLine();
                    if (userCommand.equalsIgnoreCase(getStandard))
                    {
                         System.out.println("You got the knife!");
                         System.out.println("Too bad there's no-one to use it on.");
                         counter++;
                    }
               }
               while (counter == 0);
          }
          counter = 0;
          
          System.out.println("--NEXT--");
          userProgression = userInput.nextLine();
          
          // **********************************************************
          // USE
          // **********************************************************
          System.out.println("Oh no! A mugger! You have no way to defend yourself!");
          System.out.println("Oh wait, you have the knife you just grabbed! You can type 'USE' to use an object.");
          userCommand = userInput.nextLine();
          useStandard = "USE";
          
          
          if (userCommand.equalsIgnoreCase(useStandard))
          {
               System.out.println("Type in which of these items you would you like to use.");
               System.out.println("Knife");
               userCommand = userInput.nextLine();
               
               if (userCommand.equalsIgnoreCase(tutorialItem))
               {
                    System.out.println("You pulled out the knife!");
                    System.out.println("The mugger got scared and ran away like a baby to his mommy.");
                    System.out.println("(He's not very good at his job.)");
               }
               else
               {
                    do
                    {
                         System.out.print  ("You just got stabbed. ");
                         System.out.println("If this were really part of the game, you would have lost a life");
                         System.out.println("Try typing in knife again");
                         userCommand = userInput.nextLine();
                         if (userCommand.equalsIgnoreCase(itemOne))
                         {
                              System.out.println("You pulled out the knife!");
                              System.out.println("The mugger got scared and ran away like a baby to his mommy.");
                              System.out.println("(He's not very good at his job.)");
                              counter++;
                         }
                    }
                    while (counter == 0);
               }
          }
          counter = 0;
          
          System.out.println("--NEXT--");
          userCommand = userInput.nextLine();
          
          // **********************************************************
          // TRANSITION
          // **********************************************************
          System.out.println("Okay, you seem to be pretty good at this by now.");
          System.out.print  ("But I know what you're thinking. You're thinking: ");
          userCommand = userInput.nextLine();
          System.out.println("Nope. That's not right.");
          System.out.println("You were thinking 'Where's the mansion that I'm supposed to escape from?'");
          System.out.println("The answer. Right here: ");
          System.out.println("*punch*");
          System.out.println("That's right, I just knocked you out and now I'm taking you to the mansion.");
          System.out.print  ("Any last words? ");
          userCommand = userInput.nextLine();
          
          System.out.println("");
          System.out.println("");
          System.out.println("");
          System.out.println("");
          System.out.println("");
          System.out.println("");
          System.out.println("");
          
          // **********************************************************
          // Begin Story
          // **********************************************************
          System.out.println("You wake up in a bed that isn't yours, in a house you've never been in before.");
          System.out.println("(And no, this is not just another Friday night for you, hotshot)");
          System.out.println("--NEXT--");
          userProgression = userInput.nextLine();
          
          // **********************************************************
          // PUZZLE ONE
          // **********************************************************
          System.out.println("You're in a brand new room, so you should probably LOOK around.");
          
          do
          {
               userCommand = userInput.nextLine();
               if (userCommand.equalsIgnoreCase(lookStandard) && useCounter == 0)
               {
                    System.out.println("The room is completely deserted and empty. There's just a wood table in the corner.");
                    System.out.print  ("Upon closer inspection, the table appears to have drawers that could have something ");
                    System.out.println("that could help you. Perhaps something you could USE (hint hint).");
                    
               }
               else
               {
                    
               }

          }
          while (counter == 0);
          counter = 0;
          
          
          
          
     }

}
Comments: