Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 17.11 KB | None | 0 0
  1. import java.io.FileInputStream;
  2. import java.io.FileOutputStream;
  3. import java.io.IOException;
  4. import java.io.ObjectInputStream;
  5. import java.io.ObjectOutputStream;
  6. import java.util.Random;
  7. import java.util.Scanner;
  8.  
  9. class SaveState implements java.io.Serializable {
  10.     private static final long serialVersionUID = 1L;
  11.     public String nick;
  12.     public String[] PC;
  13.     public int POKE;
  14.     public int PBalls;
  15.     public int potions;
  16.     public int actPkmn;
  17.     public int PCnum;
  18.     public int health;
  19.     public int loot;
  20.     public int hard;
  21. }
  22.  
  23. public class PKMNRoute1 {
  24.     static Random randomGenerator = new Random();
  25.     static Scanner playerInput = new Scanner(System.in);
  26.     static String[] pokes = new String[2];
  27.     static int randomIndex;
  28.     static int POKE = 1000;
  29.     static int PBalls = 0;
  30.     static int potions = 0;
  31.     static int choice;
  32.     static int actPkmn;
  33.     static String[] pkmn = new String[2];
  34.     static String nick;
  35.     static int health = 20;
  36.     static int rivHealth = 15;
  37.     static int att = 0;
  38.     static int def = 0;
  39.     static int Ratt = 0;
  40.     static int Rdef = 0;
  41.     static String Rpkmn;
  42.     static int number;
  43.     static int restore;
  44.     static int hard;
  45.     static String[] PC = new String[10000];
  46.     static int PCnum = 0;
  47.     static int loop = 0;
  48.     static int shiny = 0;
  49.     static int loot;
  50.     static int earn;
  51.  
  52.     public static void main(String[] args) {
  53.         pokes[0] = "Pidgey";
  54.         pokes[1] = "Rattata";
  55.         menu();
  56.     }
  57.  
  58.     public static void menu() {
  59.         System.out.println("1 - New Game\n2 - Load");
  60.         choice = playerInput.nextInt();
  61.         switch (choice) {
  62.         case 1:
  63.             starter();
  64.             break;
  65.         case 2:
  66.             loading();
  67.             break;
  68.         default:
  69.             System.out.println("That wasn't an option.");
  70.             playerInput.nextLine();
  71.             menu();
  72.             break;
  73.         }
  74.     }
  75.  
  76.     public static void saving() {
  77.         SaveState save = new SaveState();
  78.         save.PC = PC;
  79.         save.nick = nick;
  80.         save.POKE = POKE;
  81.         save.PBalls = PBalls;
  82.         save.potions = potions;
  83.         save.actPkmn = actPkmn;
  84.         save.PCnum = PCnum;
  85.         save.health = health;
  86.         save.loot = loot;
  87.         save.hard = hard;
  88.         try {
  89.             FileOutputStream fileOut = new FileOutputStream("save.dat");
  90.             ObjectOutputStream out = new ObjectOutputStream(fileOut);
  91.             out.writeObject(save);
  92.             out.close();
  93.             fileOut.close();
  94.             System.out.println("Your game has been saved!");
  95.             playerInput.nextLine();
  96.             playerInput.nextLine();
  97.         } catch (IOException i) {
  98.             i.printStackTrace();
  99.         }
  100.         start();
  101.     }
  102.  
  103.     public static void loading() {
  104.         SaveState save = null;
  105.         try {
  106.             FileInputStream fileIn = new FileInputStream("save.dat");
  107.             ObjectInputStream in = new ObjectInputStream(fileIn);
  108.             save = (SaveState) in.readObject();
  109.             in.close();
  110.             fileIn.close();
  111.         } catch (IOException i) {
  112.             i.printStackTrace();
  113.             return;
  114.         } catch (ClassNotFoundException c) {
  115.             c.printStackTrace();
  116.             return;
  117.         }
  118.  
  119.         PC = save.PC;
  120.         nick = save.nick;
  121.         POKE = save.POKE;
  122.         PBalls = save.PBalls;
  123.         potions = save.potions;
  124.         actPkmn = save.actPkmn;
  125.         PCnum = save.PCnum;
  126.         health = save.health;
  127.         loot = save.loot;
  128.         hard = save.hard;
  129.         System.out.println("Loaded successfully!");
  130.         playerInput.nextLine();
  131.         start();
  132.     }
  133.  
  134.     public static void starter() {
  135.         System.out.println(
  136.                 " Welcome to Pokemon - Route 1!\n In this text game, you can battle as many Pidgeys and Rattatas as you want!\n  You can also catch them!\n   However, they just go to your PC.\n    There is also no leveling.\n     Oh, yeah, there are also SHINIES!:D");
  137.         playerInput.nextLine();
  138.         System.out.println("Pick a difficulty.");
  139.         playerInput.nextLine();
  140.         System.out.println(
  141.                 "1 - Easy\n2 - Medium\n3 - Hard\n4 - IMPOSSIBLE\n(NOTE: the only difference between these is the POKEMON CENTER)");
  142.         choice = playerInput.nextInt();
  143.         hard = choice;
  144.         System.out.println("Pick a starting POKEMON!");
  145.         playerInput.nextLine();
  146.         System.out.println("1 - Charmander\n2 - Squirtle\n3 - Bulbasaur");
  147.         choice = playerInput.nextInt();
  148.         switch (choice) {
  149.         case 1:
  150.             // This will run if user types 1
  151.             System.out.println("You got a Charmander!");
  152.             pkmn[1] = "Charmander";
  153.             actPkmn = 0;
  154.             playerInput.nextLine();
  155.             System.out.println("Give your Charmander a nickname!");
  156.             nick = playerInput.nextLine();
  157.             start();
  158.             break;
  159.         case 2:
  160.             // This will run if user types 1
  161.             System.out.println("You got a Squirtle!");
  162.             pkmn[1] = "Squirtle";
  163.             actPkmn = 1;
  164.             playerInput.nextLine();
  165.             System.out.println("Give your Squirtle a nickname!");
  166.             nick = playerInput.nextLine();
  167.             start();
  168.             break;
  169.         case 3:
  170.             // This will run if user types 1
  171.             System.out.println("You got a Bulbasaur!");
  172.             pkmn[1] = "Bulbasaur!";
  173.             actPkmn = 2;
  174.             playerInput.nextLine();
  175.             System.out.println("Give your Bulbasaur a nickname!");
  176.             nick = playerInput.nextLine();
  177.             start();
  178.             break;
  179.         default:
  180.             // This will run if user types any other number
  181.             System.out.println("That wasn't an option.");
  182.             playerInput.nextLine();
  183.             starter();
  184.             break;
  185.         }
  186.     }
  187.  
  188.     public static void start() {
  189.         if (POKE < 0) {
  190.             POKE = 0;
  191.         }
  192.         System.out.println("You have " + POKE + " POKE, " + PBalls + " POKE BALL(s),\nand " + potions + " potion(s).");
  193.         playerInput.nextLine();
  194.         System.out.println(nick + " has " + health + "HP.");
  195.         playerInput.nextLine();
  196.         System.out.println("1 - Shop\n2 - Grass\n3 - POKEMON CENTER\n4 - Save\n5 - Menu");
  197.         choice = playerInput.nextInt();
  198.         switch (choice) {
  199.         case 1:
  200.             // This will run if user types 1
  201.             shop();
  202.             break;
  203.         case 2:
  204.             // This will run if user types 2
  205.             grass();
  206.             break;
  207.         case 3:
  208.             // This will run if user types 2
  209.             pkmnCent();
  210.             break;
  211.         case 4:
  212.             saving();
  213.             break;
  214.         case 5:
  215.             menu();
  216.             break;
  217.         default:
  218.             // This will run if user types any other number
  219.             System.out.println("That wasn't an option.");
  220.             playerInput.nextLine();
  221.             start();
  222.             break;
  223.         }
  224.         grass();
  225.     }
  226.  
  227.     public static void pkmnCent() {
  228.         System.out.println("1 - Talk to NURSE JOY\n2 - Use the PC\n3 - Leave");
  229.         choice = playerInput.nextInt();
  230.         switch (choice) {
  231.         case 1:
  232.             if (hard == 4) {
  233.                 System.out.println("Nurse Joy isn't here right now.");
  234.                 pkmnCent();
  235.             }
  236.             System.out.println("NURSE JOY: Welcome to our POKEMON CENTER!");
  237.             playerInput.nextLine();
  238.             System.out.println("Would you like me to heal your POKEMON back to perfect health?");
  239.             playerInput.nextLine();
  240.             System.out.println("1 - Yes\n2 - No");
  241.             choice = playerInput.nextInt();
  242.             switch (choice) {
  243.             case 1:
  244.                 System.out.println("Okay, I'll take your POKEMON for a few seconds.");
  245.                 playerInput.nextLine();
  246.                 System.out.println("DING DING DINGDING DING!");
  247.                 health = 20;
  248.                 playerInput.nextLine();
  249.                 System.out.println("Thank you for waiting. We've restored your POKEMON to full health.");
  250.                 if (hard == 3) {
  251.                     System.out.println("That'll be 40 POKE!.");
  252.                 }
  253.                 if (hard == 2) {
  254.                     System.out.println("That'll be 10 POKE!.");
  255.                 }
  256.                 playerInput.nextLine();
  257.                 pkmnCent();
  258.                 break;
  259.             case 2:
  260.                 playerInput.nextLine();
  261.                 pkmnCent();
  262.                 break;
  263.                
  264.             default:
  265.                 System.out.println("That wasn't an option.");
  266.                 playerInput.nextLine();
  267.                 pkmnCent();
  268.                 break;
  269.             }
  270.         case 2:
  271.             System.out.println("You boot up the PC.");
  272.             playerInput.nextLine();
  273.             loop = 0;
  274.             playerInput.nextLine();
  275.             System.out.println("You have " + PCnum + " POKEMON stored.");
  276.             playerInput.nextLine();
  277.             while (loop < PCnum) {
  278.                 loop++;
  279.                 System.out.println(PC[loop]);
  280.                 playerInput.nextLine();
  281.             }
  282.             pkmnCent();
  283.             break;
  284.         case 3:
  285.             System.out.println("We hope to see you again!");
  286.             playerInput.nextLine();
  287.             start();
  288.             break;
  289.         default:
  290.             System.out.println("That wasn't an option.");
  291.             playerInput.nextLine();
  292.             pkmnCent();
  293.             break;
  294.         }
  295.     }
  296.  
  297.     public static void shop() {
  298.         System.out.println("Hi, there! May I help you?");
  299.         playerInput.nextLine();
  300.         System.out.println("You have " + POKE + " POKE.");
  301.         playerInput.nextLine();
  302.         System.out.println("1 - POKE BALL (200P)\n2 - Potion (300P)\n3 - Leave");
  303.         choice = playerInput.nextInt();
  304.         switch (choice) {
  305.         case 1:
  306.             // This will run if user types 1
  307.             if (POKE >= 200) {
  308.                 System.out.println("POKE BALL? Certainly.");
  309.                 playerInput.nextLine();
  310.                 playerInput.nextLine();
  311.                 POKE -= 200;
  312.                 PBalls++;
  313.                 shop();
  314.             } else {
  315.                 System.out.println("You don't have enough money.");
  316.                 playerInput.nextLine();
  317.                 shop();
  318.             }
  319.             break;
  320.         case 2:
  321.             // This will run if user types 2
  322.             if (POKE >= 200) {
  323.                 System.out.println("Potion? Certainly.");
  324.                 playerInput.nextLine();
  325.                 playerInput.nextLine();
  326.                 POKE -= 300;
  327.                 potions++;
  328.                 shop();
  329.             } else {
  330.                 System.out.println("You don't have enough money.");
  331.                 playerInput.nextLine();
  332.                 shop();
  333.             }
  334.             break;
  335.         case 3:
  336.             System.out.println("Please come again!");
  337.             playerInput.nextLine();
  338.             start();
  339.             break;
  340.         default:
  341.             // This will run if user types any other number
  342.             System.out.println("That wasn't an option.");
  343.             playerInput.nextLine();
  344.             shop();
  345.             break;
  346.         }
  347.     }
  348.  
  349.     public static void grass() {
  350.         System.out.println("\nYou walk through the grass...");
  351.         playerInput.nextLine();
  352.         randomIndex = randomGenerator.nextInt(3);
  353.         if (randomIndex == 0 || randomIndex == 1) {
  354.             randomIndex = randomGenerator.nextInt(8192);
  355.             if (randomIndex == 0) {
  356.                 shiny = 1;
  357.             }
  358.             randomIndex = randomGenerator.nextInt(pokes.length);
  359.             if (shiny == 1) {
  360.                 System.out.println("SHINY " + pokes[randomIndex] + " appears!");
  361.             } else {
  362.                 System.out.println("Wild " + pokes[randomIndex] + " appears!");
  363.             }
  364.             Rpkmn = pokes[randomIndex];
  365.             rivHealth = 15;
  366.             playerInput.nextLine();
  367.             System.out.println("Go! " + nick + "!");
  368.             playerInput.nextLine();
  369.             battle();
  370.         } else {
  371.             System.out.println("Nothing happens");
  372.             playerInput.nextLine();
  373.             start();
  374.         }
  375.  
  376.     }
  377.  
  378.     public static void battle() {
  379.         System.out.println(nick + " has " + health + "HP.");
  380.         playerInput.nextLine();
  381.         if (shiny == 1) {
  382.             System.out.println("SHINY " + Rpkmn + " has " + rivHealth + "HP.");
  383.         } else {
  384.             System.out.println("Wild " + Rpkmn + " has " + rivHealth + "HP.");
  385.         }
  386.         playerInput.nextLine();
  387.         System.out.println("What will " + nick + " do?\n1 - Fight\n2 - Bag\n3 - Pokemon\n4 - Run");
  388.         choice = playerInput.nextInt();
  389.         switch (choice) {
  390.         case 1:
  391.             // This will run if user types 1
  392.             attack();
  393.             break;
  394.         case 2:
  395.             // This will run if user types 2
  396.             bag();
  397.             break;
  398.         case 3:
  399.             // This will run if user types 3
  400.             System.out.println("Sorry, but you can't do this!");
  401.             playerInput.nextLine();
  402.             battle();
  403.             break;
  404.         case 4:
  405.             randomIndex = randomGenerator.nextInt(3);
  406.             if (randomIndex == 0) {
  407.                 System.out.println("Got away safely!");
  408.                 start();
  409.             } else {
  410.                 System.out.println("Couldn't escape!");
  411.                 Rattack();
  412.             }
  413.             break;
  414.         default:
  415.             // This will run if user types any other number
  416.             System.out.println("That wasn't an option.");
  417.             playerInput.nextLine();
  418.             battle();
  419.             break;
  420.         }
  421.     }
  422.  
  423.     public static void attack() {
  424.         if (actPkmn == 0) {
  425.             System.out.println("1 - Scratch\n2 - Growl");
  426.             choice = playerInput.nextInt();
  427.             switch (choice) {
  428.             case 1:
  429.                 System.out.println(nick + " used Scratch!");
  430.                 number = randomGenerator.nextInt(3);
  431.                 rivHealth -= number + 3 - att + Rdef;
  432.                 playerInput.nextLine();
  433.                 check();
  434.                 break;
  435.             case 2:
  436.                 System.out.println(nick + " used Growl!");
  437.                 Ratt--;
  438.                 playerInput.nextLine();
  439.                 check();
  440.                 break;
  441.             default:
  442.                 // This will run if user types any other number
  443.                 System.out.println("That wasn't an option.");
  444.                 playerInput.nextLine();
  445.                 attack();
  446.                 break;
  447.             }
  448.         } else if (actPkmn == 1) {
  449.             System.out.println("1 - Tackle\n2 - Tail whip");
  450.             choice = playerInput.nextInt();
  451.             switch (choice) {
  452.             case 1:
  453.                 System.out.println(nick + " used Tackle!");
  454.                 number = randomGenerator.nextInt(3);
  455.                 rivHealth -= number + 3 - att + Rdef;
  456.                 playerInput.nextLine();
  457.                 check();
  458.                 break;
  459.             case 2:
  460.                 System.out.println(nick + "used Tail Whip!");
  461.                 Rdef--;
  462.                 playerInput.nextLine();
  463.                 check();
  464.                 break;
  465.             default:
  466.                 // This will run if user types any other number
  467.                 System.out.println("That wasn't an option.");
  468.                 playerInput.nextLine();
  469.                 playerInput.nextLine();
  470.                 attack();
  471.                 break;
  472.             }
  473.         } else {
  474.             System.out.println("1 - Tackle\n2 - Growl");
  475.             choice = playerInput.nextInt();
  476.             switch (choice) {
  477.             case 1:
  478.                 System.out.println(nick + " used Tackle!");
  479.                 number = randomGenerator.nextInt(3);
  480.                 rivHealth -= number + 3 - att + Rdef;
  481.                 playerInput.nextLine();
  482.                 check();
  483.                 break;
  484.             case 2:
  485.                 System.out.println(nick + " used Growl!");
  486.                 Ratt--;
  487.                 playerInput.nextLine();
  488.                 check();
  489.                 break;
  490.             default:
  491.                 // This will run if user types any other number
  492.                 System.out.println("That wasn't an option.");
  493.                 playerInput.nextLine();
  494.                 attack();
  495.                 break;
  496.             }
  497.         }
  498.     }
  499.  
  500.     public static void check() {
  501.         if (rivHealth <= 0) {
  502.             if (shiny == 1) {
  503.                 System.out.println("SHINY " + Rpkmn + " fainted!");
  504.             } else {
  505.                 System.out.println("Wild " + Rpkmn + " fainted!");
  506.             }
  507.             playerInput.nextLine();
  508.             earn = loot + 50;
  509.             System.out.println("You gained " + earn + " POKE!");
  510.             POKE += 50 + loot;
  511.             loot++;
  512.             playerInput.nextLine();
  513.             start();
  514.         } else {
  515.             Rattack();
  516.         }
  517.     }
  518.  
  519.     public static void Rattack() {
  520.         if (Rpkmn.equalsIgnoreCase("pidgey")) {
  521.             if (shiny == 1) {
  522.                 System.out.println("SHINY Pidgey used Tackle!");
  523.             } else {
  524.                 System.out.println("Wild Pidgey used Tackle!");
  525.             }
  526.             number = randomGenerator.nextInt(3);
  527.             health -= number + 3 - Ratt + def;
  528.             playerInput.nextLine();
  529.         } else if (Rpkmn.equalsIgnoreCase("rattata")) {
  530.             choice = randomGenerator.nextInt(2);
  531.             if (choice == 0) {
  532.                 if (shiny == 1) {
  533.                     System.out.println("SHINY Rattata used Tackle!");
  534.                 } else {
  535.                     System.out.println("Wild Rattata used Tackle!");
  536.                 }
  537.                 number = randomGenerator.nextInt(3);
  538.                 health -= number + 3 - Ratt + def;
  539.                 playerInput.nextLine();
  540.             } else {
  541.                 if (shiny == 1) {
  542.                     System.out.println("SHINY Rattata used Tail Whip!");
  543.                 } else {
  544.                     System.out.println("Wild Rattata used Tail Whip!");
  545.                 }
  546.                 def--;
  547.                 playerInput.nextLine();
  548.             }
  549.         }
  550.         if (health <= 0) {
  551.             System.out.println(nick + " fainted!");
  552.             playerInput.nextLine();
  553.             System.out.println("You are out of usable POKEMON!");
  554.             playerInput.nextLine();
  555.             System.out.println("You panick and lose 200P.");
  556.             POKE -= 200;
  557.             playerInput.nextLine();
  558.             System.out.println("... ... ... ...");
  559.             playerInput.nextLine();
  560.             System.out.println("You white out!");
  561.             playerInput.nextLine();
  562.             System.out.println("You scurry back home, protecting the exhausted and fainted POKEMON from further harm.");
  563.             playerInput.nextLine();
  564.             System.out.println("After resting for a bit, you and your POKEMON are ready to face the world again!");
  565.             playerInput.nextLine();
  566.             health = 20;
  567.             start();
  568.         } else {
  569.             battle();
  570.         }
  571.     }
  572.  
  573.     public static void bag() {
  574.         System.out.println("You have " + PBalls + " POKE BALL(s) and " + potions + " potion(s).");
  575.         playerInput.nextLine();
  576.         System.out.println(nick + " has " + health + "HP.");
  577.         playerInput.nextLine();
  578.         System.out.println("1 - Throw POKE BALL\n2 - Use potion (heals 10HP)\n3 - Back");
  579.         choice = playerInput.nextInt();
  580.         switch (choice) {
  581.         case 1:
  582.             if (PBalls == 0) {
  583.                 System.out.println("You don't have any POKE BALLS!");
  584.                 playerInput.nextLine();
  585.                 bag();
  586.             } else {
  587.                 System.out.println("You throw a POKEBALL!");
  588.                 playerInput.nextLine();
  589.                 number = randomGenerator.nextInt(rivHealth);
  590.                 if (number == 1 || number == 2 || number == 3 || number == 4) {
  591.                     if (shiny == 1) {
  592.                         System.out.println("Gotcha! SHINY " + Rpkmn + " was caught!");
  593.                     } else {
  594.                         System.out.println("Gotcha! " + Rpkmn + " was caught!");
  595.                     }
  596.                     playerInput.nextLine();
  597.                     System.out.println(Rpkmn + " was sent to the PC.");
  598.                     if (shiny == 1) {
  599.                         Rpkmn = "SHINY " + Rpkmn;
  600.                     }
  601.                     PCnum++;
  602.                     PC[PCnum] = Rpkmn;
  603.                     PBalls--;
  604.                     playerInput.nextLine();
  605.                     start();
  606.                 }
  607.                 else {
  608.                     System.out.println("Oh no! The POKEMON broke free!");
  609.                     PBalls--;
  610.                     Rattack();
  611.                 }
  612.             }
  613.             break;
  614.         case 2:
  615.             if (potions == 0) {
  616.                 System.out.println("You don't have any potions!");
  617.                 playerInput.nextLine();
  618.                 bag();
  619.             } else {
  620.                 System.out.println("You use a potion.");
  621.                 playerInput.nextLine();
  622.                 restore = 20 - health;
  623.                 health += 10;
  624.                 if (health > 20) {
  625.                     health = 20;
  626.                     System.out.println(nick + "'s HP was restored by " + restore + " point(s).");
  627.                     playerInput.nextLine();
  628.                     Rattack();
  629.                 } else {
  630.                     System.out.println(nick + "'s HP was restored by 10 point(s).");
  631.                     playerInput.nextLine();
  632.                     bag();
  633.                 }
  634.             }
  635.             break;
  636.         case 3:
  637.             battle();
  638.             break;
  639.         default:
  640.             // This will run if user types any other number
  641.             System.out.println("That wasn't an option.");
  642.             playerInput.nextLine();
  643.             bag();
  644.             break;
  645.         }
  646.  
  647.     }
  648. }
  649. /*
  650.  * STUPIDEST ERROR EVER Syntax error on token"}", { expected Syntax error,
  651.  * insert "}" to complete ClassBody
  652.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement