Advertisement
Guest User

Sam's java thing

a guest
Jun 30th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.90 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.Scanner;
  3. public class TheAdventure {
  4.  
  5.     public static String pClass;
  6.     public static int Level = 1;
  7.     public static double Health = 100.0;
  8.  
  9.     public static void main(String[] args) {
  10.         // TODO Auto-generated method stub
  11.         Random randomGenerator = new Random();
  12.         Scanner playerInput = new Scanner(System.in);
  13.  
  14.         System.out.println("Welcome, welcome, young and old, to the Mines of Mystery.");
  15.         System.out.println("You may just strike it rich, or you will find yourself stuck here forever.");
  16.  
  17.         // Telling the player what his or her name is, and that they start out as level 1.
  18.         boolean Alive = true;
  19.         String Name = "Professor Oak";
  20.  
  21.         System.out.println("Choose a class:\n1 - Soldier\n2 - Athlete\n3 - Genius");
  22.  
  23.         int playerClass = playerInput.nextInt();
  24.         if((playerClass == 1)|| (playerClass == 2) ||(playerClass == 3)){
  25.             System.out.println("Nice!");
  26.         }
  27.  
  28.         else{
  29.             System.out.println("Oops! You did not follow directions! Please restart the game!");
  30.             playerInput.close();
  31.         }
  32.  
  33.  
  34.         if(playerClass == 1){
  35.             pClass = "Soldier";
  36.         }
  37.  
  38.         else if(playerClass == 2){
  39.             pClass = "Athlete";
  40.         }
  41.  
  42.         else{
  43.             pClass = "Genius";
  44.         }
  45.  
  46.         System.out.println("What is your name, fine " + pClass + "?");
  47.         playerInput.nextLine();
  48.         Name = playerInput.nextLine();
  49.         System.out.println("You are " + Name + ", a level " + Level + " " + pClass +"!");
  50.  
  51.         System.out.println("Would you like to enter the mine? (Y/N)");
  52.         String Enter = playerInput.nextLine();
  53.         if(!Enter.equalsIgnoreCase("Y")&&!Enter.equalsIgnoreCase("Yes")){
  54.             System.out.println("You suddenly remember why you wanted to explore the mine in the first place." +
  55.                     "\nSuddenly, a large horde of zombies peaks over the mountain. You are spotted." +
  56.                     "\nWith nowhere to go, you close your eyes as your flesh is eaten. You are dead.");
  57.             System.exit(0);
  58.         }
  59.  
  60.         //Entering the mine
  61.         System.out.println("You have entered the mine!");
  62.         Level = Level + 1;
  63.         System.out.println("Congratulations on levelling up! You are now a Level " + Level + " " + pClass + "!");
  64.  
  65.         //A rock hits the player
  66.         double rockDamage = 10.0;
  67.         Health -= rockDamage;
  68.  
  69.         System.out.println("Oof! A rock just hit you! You have learned how bad rocks are!");
  70.         System.out.println("You took " + rockDamage + " damage! Now your health is " + Health + ".");
  71.  
  72.         //Is the player dead yet?
  73.         if( Health <= 0 ){
  74.  
  75.             System.out.println("Oh noooooooo, "
  76.                     + Name + " died They were level "
  77.                     + Level);
  78.         }
  79.  
  80.         //Fountain of Youth?
  81.         System.out.println("You find a fountain. Is this the Fountain of Youth you've been looking for?");
  82.         System.out.println("If you would like to drink, please type 'drink'! If not, write 'ignore'.");
  83.  
  84.         String playerAnswer = "?";
  85.         playerAnswer = playerInput.nextLine();
  86.  
  87.         if(playerAnswer.equalsIgnoreCase("drink")){
  88.             Health--;
  89.             Level++;
  90.             System.out.println("That was some yucky water. Definitely not what you were looking for. At least you've levelled up!");
  91.             System.out.println("Congratulations on levelling up! You are now a Level " + Level + " " + pClass + "!");
  92.             System.out.println("You took 1 damage point. Your health is now " + Health + ".");
  93.         }
  94.         else if(playerAnswer.equalsIgnoreCase("ignore")){
  95.             Health = Health + 5;
  96.             Level = Level + 2;
  97.             System.out.println("Smart choice! That water would have made you VERY sick!"
  98.                     + "\nInstead you decided to eat an apple, filling you with some precious vitamins!"
  99.                     + "\nCongratulations on levelling up! You are now a Level " + Level + " " + pClass + "!"
  100.                     + "\nYour apple gave you 5 health. Your health is now " + Health + ".");
  101.         }
  102.         else{
  103.             System.out.println("You are horrible at following directions! For your stupidity, you will lose 20 health.");
  104.             Health = Health - 20;
  105.             System.out.println("Your health is now " + Health + ".");
  106.  
  107.         }
  108.  
  109.         //Is the player dead yet?
  110.         if( Health <= 0 ){
  111.  
  112.             System.out.println("Oh noooooooo, "
  113.                     + Name + " died They were level "
  114.                     + Level);
  115.         }
  116.  
  117.  
  118.         //Math Teacher Appears!
  119.         System.out.println("You see a figure mumbling to itself."
  120.                 +"\nDo you go to discover who it is? (Y/N)");
  121.         String Investigation;
  122.         Investigation = playerInput.nextLine();
  123.  
  124.  
  125.         //Addition Question
  126.         if(Investigation.equalsIgnoreCase("Y") || Investigation.equalsIgnoreCase("Yes")){
  127.             System.out.println("Upon closer investigation, you discover the person is your math teacher!"
  128.                     +"\nYour teacher decides to make a deal with you. Answer math questions correctly, you get level-ups."
  129.                     +"\nHowever, if you get the question wrong, you get Fs, and you will become sicker!");
  130.             int mathFirst = randomGenerator.nextInt(51);
  131.             int mathSecond = randomGenerator.nextInt(51);
  132.             int mathThird = mathFirst + mathSecond;
  133.             System.out.println("First question: What is " + mathFirst + " + " + mathSecond + "? \nYOU MUST ONLY WRITE DIGITS OR THE GAME WILL CRASH");
  134.             int firstAnswer;
  135.             firstAnswer = playerInput.nextInt();
  136.             if(firstAnswer == mathThird){
  137.                 questionCorrect();
  138.             }
  139.  
  140.             //But What if the player #GotItWrong?
  141.             else{
  142.                 questionIncorrect();
  143.             }  
  144.             //Multiplication Question
  145.             int mathFourth = randomGenerator.nextInt(21);
  146.             int mathFifth = randomGenerator.nextInt(21);
  147.             int mathSixth = mathFourth * mathFifth;
  148.             System.out.println("Second question: What is " + mathFourth + " * " + mathFifth + "?\nYOU MUST ONLY WRITE DIGITS OR THE GAME WILL CRASH");
  149.             int secondAnswer;
  150.             secondAnswer = playerInput.nextInt();
  151.             if(secondAnswer == mathSixth){
  152.                 questionCorrect();
  153.             }
  154.  
  155.             //But What if the player #GotItWrong?
  156.             else{
  157.                 questionIncorrect();
  158.             }
  159.  
  160.             //Subtraction Question
  161.             int mathSeventh = randomGenerator.nextInt(51) + 50;
  162.             int mathEighth = randomGenerator.nextInt(51);
  163.             int mathNinth = mathSeventh - mathEighth;
  164.             System.out.println("Third question: What is " + mathSeventh + " - " + mathEighth + "?\nYOU MUST ONLY WRITE DIGITS OR THE GAME WILL CRASH");
  165.             int thirdAnswer;
  166.             thirdAnswer = playerInput.nextInt();
  167.             if(thirdAnswer == mathNinth){
  168.                 questionCorrect();
  169.             }
  170.  
  171.             //But What if the player #GotItWrong?
  172.             else{
  173.                 questionIncorrect();
  174.             }
  175.  
  176.             //Division Question
  177.             int mathTenth = randomGenerator.nextInt(10) + 1;
  178.             int mathEleventh = randomGenerator.nextInt(21) * mathTenth;
  179.             int mathTwelfth = mathEleventh / mathTenth;
  180.             System.out.println("Fourth question: What is " + mathEleventh + " / " + mathTenth + "?\nYOU MUST ONLY WRITE DIGITS OR THE GAME WILL CRASH");
  181.             int fourthAnswer;
  182.             fourthAnswer = playerInput.nextInt();
  183.             if(fourthAnswer == mathTwelfth){
  184.                 questionCorrect();
  185.             }
  186.  
  187.             //But What if the player #GotItWrong?
  188.             else{
  189.                 questionIncorrect();
  190.             }
  191.             playerInput.nextLine();
  192.         }
  193.  
  194.         //Making Your Third Choice
  195.         System.out.println("You realize that you are now in some sort of large cavern."
  196.                 +"\nIf you go left, you will probably die. If you go right, you might get your first riches.");
  197.         System.out.println("You need to make a choice. Will you go left or right?");
  198.         System.out.println("So, will you go left or right? Please type your answer below.");
  199.  
  200.         String playerAnswer2 = playerInput.nextLine();
  201.  
  202.         //If the player makes the smart choice
  203.         if(playerAnswer2.equalsIgnoreCase("right")){
  204.             System.out.println("You found a gold nugget! Great job!");
  205.             Level = Level + 1;
  206.             System.out.println("Congratulations on levelling up! You are now a Level " + Level + " " + pClass + "!");
  207.         }
  208.         //If the player is very stupid and doesn't listen
  209.         else if(playerAnswer2.equalsIgnoreCase("left")){
  210.             System.out.println("The path gets very dark. Another cunning rock ambushes you.");
  211.             rockDamage = randomGenerator.nextInt(40);
  212.             Health -= rockDamage;
  213.             System.out.println("You took " + rockDamage
  214.                     + " damage. You have " + Health
  215.                     + " health remaining.");
  216.         }
  217.         else{
  218.             System.out.println("You are horrible at following directions! For your stupidity, you will lose 20 health.");
  219.             Health = Health - 20;
  220.             System.out.println("Your health is now " + Health + ".");
  221.  
  222.         }
  223.         //Is the player dead yet?
  224.         if( Health <= 0 ){
  225.  
  226.             System.out.println("Oh noooooooo, "
  227.                     + Name + " died They were level "
  228.                     + Level);
  229.         }
  230.         //Endgame
  231.         else{
  232.             System.out.println(Name +" survived the Mines of Mystery! You made it to level "+ Level + "." + "\nFinal health: " + Health);
  233.         }
  234.  
  235.         playerInput.close();
  236.  
  237.  
  238.     }
  239.     //Add some more choices here later!
  240.     //Remember to fix non-math teacher bug
  241.     public static void questionCorrect(){
  242.         System.out.println("Nice job! You got that question right and you get a level-up!");
  243.         Level = Level + 1;
  244.         System.out.println("Congratulations on levelling up! You are now a Level " + Level + " " + pClass + "!");
  245.     }
  246.     public static void questionIncorrect(){
  247.         System.out.println("FAIL! You got that math question wrong! You are beginning to feel a bit sick.");
  248.         Health = Health - 10;
  249.         System.out.println("Your health is now " + Health + ".");
  250.     }
  251. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement