RyanAllarey

Fundamentals Project

Oct 26th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.89 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2. public class Project {
  3.     static boolean quit = false;
  4.     static String place = "start";
  5.  
  6.     public static String q(String m) {
  7.         String s = JOptionPane.showInputDialog(m);
  8.         return s;
  9.     }
  10.  
  11.     public static void m(String s) {
  12.         JOptionPane.showMessageDialog(null, s);
  13.     }
  14.  
  15.     public static void main(String [] args) {
  16.  
  17.         while(!quit) {
  18.             if (place.equals("start")) {
  19.                 start();
  20.             } else if (place.equals("dungeon")) {
  21.                 dungeon();
  22.             } else if (place.equals("forest")) {
  23.                 forest();
  24.             } else if (place.equals("school")) {
  25.                 school();
  26.             } else if (place.equals("cave")) {
  27.                 cave();
  28.             } else if (place.equals("dungeon2")) {
  29.                 dungeon2();
  30.             } else if (place.equals("forest2")) {
  31.                 forest2 ();
  32.             } else if (place.equals("forest3")) {
  33.                 forest3 ();
  34.             } else if (place.equals("house")) {
  35.                 house();
  36.             } else if (place.equals("dead")) {
  37.                 m("You are dead.");
  38.                 quit = true;
  39.             } else if (place.equals("win")) {
  40.                 m("You won! Congratulations!");
  41.                 quit = true;
  42.             }
  43.         }
  44.     }
  45.  
  46.     public static void start() {
  47.         String choice = q ("Welcome, you have reached the start of your adventure!\n"+
  48.                 "Which path would you like to take?\n"+
  49.                 "You may choose to go to the [d]ungeon, [f]orest, [s]chool, [h]ouse, or the [c]ave.");
  50.         if (choice.equals("d")) {
  51.             place = "dungeon";
  52.         } else if (choice.equals("f")) {
  53.             place = "forest";
  54.         } else if (choice.equals("s")) {
  55.             place = "school";
  56.         } else if (choice.equals("c")) {
  57.             place = "cave";
  58.         } else if (choice.equals("h")) {
  59.             place = "house";
  60.         }
  61.     }
  62.  
  63.     public static void house() {
  64.         String choice = q("Here you are at a scary house.\n"+
  65.         "There are 2 doors, 1 lead to death, and the other leads to money.\n"+
  66.         "Which door do you choose?\n[1], [2]");
  67.         if (choice.equals("1")) {
  68.             m("You open the door and walk in.\n"+
  69.             "Suddenly the floor disappears and you fall to your death.\n");
  70.             place = "dead";
  71.         } else if (choice.equals("2")) {
  72.             m("You open the door and the shiny gold and treasure is sitting in front of you!\n"+
  73.             "you grab as much as u can and get out.\n");
  74.             place = "win";
  75.         }
  76.     }
  77.        
  78.     public static void dungeon() {
  79.         String choice = q("You have arrived in the dungeon.\n"+
  80.                 "You walk in and see a scary monster!.\n"+
  81.                 "Fight the monster with your powers\n[y]es or [n]o");
  82.         if (choice.equals("y")) {
  83.             double fight = Math.random();
  84.             if (fight > 0.7) {
  85.                 m("The monster destroys you and you have died a painful death");
  86.                 place = "dead";
  87.             } else {
  88.                 m("A friend appears to help you kill the monster and you proceed onward");
  89.                 place = "dungeon2";
  90.             }
  91.         } else if (choice.equals("n")) {
  92.             m("you run away and pee your pants.");
  93.             place = "start";
  94.         }
  95.     }
  96.  
  97.     public static void dungeon2() {
  98.         String choice = q("You walk farther in the dungeon and notice the treasure.\n"+
  99.                 "You walk in to take the treasure when the protector of the treasure appears!\n"+
  100.                 "There is a dragon! Fight it?\n[y]es or [n]o");
  101.         if (choice.equals("y")) {
  102.             double fight = Math.random();
  103.             if (fight > 0.7) {
  104.                 m("The dragon burns you to a crisp");
  105.                 place = "dead";
  106.             } else {
  107.                 m("You're friend runs away, but you become a man and slay the dragon!\nYou grab the treasure!");
  108.                 place = "win";
  109.             }
  110.         } else if (choice.equals("n")) {
  111.             m("You run away and don't get any treasure.");
  112.             place = "start";
  113.         }
  114.     }
  115.  
  116.     public static void forest() {
  117.         String choice = q("It is dark in the forest, and a wild bear appears!\n"+
  118.                 "The bear wants some porridge.\n Will you make the bear food?\n[y]es or [n]o");
  119.         if (choice.equals("y")) {
  120.             double fight = Math.random();
  121.             if (fight > 0.5) {
  122.                 m("The porridge was just right, so the bear let's u go past.");
  123.                 place = "forest2";
  124.             } else {
  125.                 m("The porridge was too cold, the bear mauls you to death");
  126.                 place = "dead";
  127.             }
  128.         } else if (choice.equals("n")) {
  129.             m("The bear is hungry and mad, so he chases after you.");
  130.             place = "dead";
  131.         }
  132.     }
  133.  
  134.     public static void forest2() {
  135.         String choice = q("You pass the bear who is peacefully eating his porridge.\n"+
  136.                 "You continue on your journey through the haunted forest. While walking, a wild pepe appears!\n"+
  137.                 "The pepe wants to beat you up, do you allow this to happen?\n[y]es or [n]o");
  138.         if (choice.equals("y")) {
  139.             m("You become bruised badly, but you survive.");
  140.             place = "forest3";
  141.         } else if (choice.equals("n")) {
  142.             m("You attempt to run away, but pepe jumps towards you and beats you up anyways.");
  143.             place = "dead";
  144.         }
  145.     }
  146.  
  147.     public static void forest3() {
  148.         String choice = q("You've survived a pepe attack and passed a bear!\n"+
  149.                 "Congratulations, this is your final test.\n"+
  150.                 "You see the money in front of you, but there is a river in the way.\n"+
  151.                 "Do you try to pass the river, or give up?\n[y]es or [n]o");
  152.         if (choice.equals("y")) {
  153.             m("You think for a long time for a plan to cross.\n"+
  154.                 "You notice a large piece of wood and use it to build a boat.\n"+
  155.                 "You cross the large river with your boat and get all the money!");
  156.             place = "win";
  157.         } else if (choice.equals("n")) {
  158.             m("You decide not to try and cross because you don't want to risk drowning.\n"+
  159.                 "Suddenly, there is a strong wind that pushes you into the river, and you drown anyways.\n");
  160.             place = "dead";
  161.         }
  162.     }
  163.  
  164.     public static void school() {
  165.         String choice = q("You arrive at the Charter School of Wilmington!\n"+
  166.                 "Zombie Mr. Kramer appears and he wants your brains.\nHe asks you a question:\n"+
  167.                 "Who is the best teacher at CSW?");
  168.         if (choice.equals("Mr. Kramer")) {
  169.             m("Zombie Mr. Kramer allows you to go further into the school\n"+
  170.                 "In the computer science class, you find millions of dollars!\n"+
  171.                 "Victory!");
  172.             place = "win";
  173.         } else {
  174.             m("The zombie is mad and eats you!");
  175.             place = "dead";
  176.         }
  177.     }
  178.  
  179.     public static void cave() {
  180.         String choice = q("you arrive at a spooky cave!\n"+
  181.                 "There are ninja turtles guarding your girlfriend!\n"+
  182.                 "Save your girlfriend and fight?\n[y]es or [n]o");
  183.         if (choice.equals("y")) {
  184.             double fight = Math.random();
  185.             if (fight > 0.6) {
  186.                 m("The ninja turtles team up and slice you in half");
  187.                 place = "dead";
  188.             } else {
  189.                 m("You fight with all your might and beat the turtles!\nYou save your girlfriend!");
  190.                 place = "win";
  191.             }
  192.         } else if (choice.equals("n")) {
  193.             m("you run away and leave your girlfriend to die!");
  194.             place = "start";
  195.         }
  196.     }
  197. }
Add Comment
Please, Sign In to add comment