Advertisement
Guest User

Untitled

a guest
Aug 13th, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.28 KB | None | 0 0
  1. import java.io.*;
  2.  
  3.  
  4. class player {
  5.     public static void main (String[] args) throws IOException { // <<<<<<<<<<<<<<<<<<<<< Need to have this get the value sent
  6.         String Name, cmd;
  7.         int gold, quit, spaces, weint, randGold;
  8.        
  9.         gold = 0;
  10.         cmd = "none";
  11.         quit = 0;
  12.         spaces = 0;
  13.         weint = 0;
  14.        
  15.         /* Ideas for new commands:
  16.         attack - Attacks monster you have run into. - 100%
  17.         eat - Heals you. - 0%
  18.         run - Gets you away from a battle. - 100%
  19.         walk - Moves you one space and you can: find something (gold, food, ect...) or run into a monster. - 50%
  20.         */
  21.        
  22.         while (quit == 0) {
  23.             gold += wgold; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< This is the setting of the gold after the battle >>>>>>>>>>>>>>>>>>>>>>>
  24.             wgold = 0;
  25.             if (cmd.equalsIgnoreCase("none")) {
  26.                 System.out.println("-------Commands-------\n");
  27.                 System.out.println("distance - Displays the amount of spaces you have walked.");
  28.                 System.out.println("gold - Shows the amount of gold you have.");
  29.                 System.out.println("quit - Exits the program.");
  30.                 System.out.println("walk - Moves you one space.\n");
  31.                 System.out.println("--End of command list--\n");
  32.                 cmd = "wait";
  33.                 BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));
  34.                 System.out.print("Command: ");
  35.                 System.out.flush();
  36.                 cmd = stdin.readLine();
  37.             }
  38.            
  39.             if (cmd.equalsIgnoreCase("gold")) {
  40.                 System.out.println("\nGold: " + gold + "\n");
  41.                 cmd = "none";
  42.             }else if (cmd.equalsIgnoreCase("walk")) {
  43.                 spaces += 1;
  44.                 weint = misc.random(1000); // Sets a random number out of 1000 for a percentage.
  45.                 if ((weint >= 0) & (weint < 300)) {
  46.                     enemies obj = new enemies();
  47.                     obj.main();
  48.                     cmd = "none";
  49.                 } else if ((weint >= 300) & (weint < 500)) {
  50.                     randGold = misc.random(10); // Sets the random amount of gold found while walking.
  51.                     if (randGold <= 0) {
  52.                         randGold = 1;
  53.                     }
  54.                     System.out.println("\nYou have walked one space and found " + randGold + " gold piece(s).\n");
  55.                     gold += randGold;
  56.                     cmd = "none";
  57.                 } else if ((weint >= 500) & (weint <= 1000)) {
  58.                     System.out.println("\nYou have walked one space.\n");
  59.                     cmd = "none";
  60.                 }
  61.             } else if (cmd.equalsIgnoreCase("distance")) {
  62.                 System.out.println("\nSpaces you have moved: " + spaces + ".\n");
  63.                 cmd = "none";
  64.             } else if (cmd.equalsIgnoreCase("quit")) {
  65.             System.out.println("Quitting the program...");
  66.             quit = 1;
  67.             } else {
  68.                 System.out.println("\nCommand not recognized.\n");
  69.                 cmd = "none";
  70.             }
  71.         }
  72.     }
  73. }
  74.  
  75. class battle {
  76.     public static void main(String monster, int level, int mhp, int drop) throws IOException { // (String monster) gets the return value of the monster sent by the enemies class.
  77.         int end, hp, str, smhp, exp;
  78.         Long hit;
  79.         String cmd;
  80.        
  81.         end = 0;
  82.         hp = 10;
  83.         str = 1;
  84.         exp = 0;
  85.         smhp = mhp;
  86.         cmd = "none";
  87.        
  88.         System.out.println("\n\n\n-------Battle!-------\n\n\n");
  89.         System.out.println("You've encountered a wild " + monster + " level " + level + "!\n\n");
  90.        
  91.         while(end == 0) {
  92.             if(cmd.equalsIgnoreCase("none")) {
  93.                 System.out.println("----Commands----\n");
  94.                 System.out.println("attack - Attacks the enemy.");
  95.                 System.out.println("run - Runs from battle.\n");
  96.                 System.out.println("--End of command list--\n\n\n");
  97.                 System.out.println("-----Status----\n");
  98.                 System.out.println("HP: " + hp + "/10");
  99.                 System.out.println("Strength: " + str + "\n");
  100.                 System.out.println("---Wild " + monster + " stats---");
  101.                 System.out.println("Wild " + monster + " HP: " + mhp + "/" + smhp + "\n");
  102.                 cmd = "wait";
  103.                
  104.                 BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
  105.                 System.out.print("Command: ");
  106.                 System.out.flush();
  107.                 cmd = stdin.readLine();
  108.             }
  109.            
  110.             if(cmd.equalsIgnoreCase("run")) {
  111.                 System.out.println("\nYou have escaped from the battle!\n");
  112.                 end = 1;
  113.             } else if(cmd.equalsIgnoreCase("attack")) {
  114.                 hit = Math.round(misc.random(str) * .7);
  115.                
  116.                 System.out.println("You hit: " + hit);
  117.                 mhp -= hit;
  118.                
  119.                 if(hit >= 1) {
  120.                     exp += hit * 12;
  121.                 }
  122.                
  123.                 cmd = "none";
  124.                 //Add HP for monsters / attack command. Not all here but you know where...
  125.             } else {
  126.                 System.out.println("\nCommand not recognized.\n");
  127.                 cmd = "none";
  128.             }
  129.            
  130.         if(mhp <= 0) {
  131.             System.out.println("You have won!");
  132.             System.out.println("You found: " + drop + " coins!");
  133.            
  134.             player obj = new player(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< This is where the value is sent to the player class
  135.             obj.main(drop);
  136.            
  137.             if(exp >= str * 80) {
  138.                 str += 1;
  139.                 System.out.println("Congradulations! You now have " + str + " strength.");
  140.             }
  141.             end = 1;
  142.         }
  143.        
  144.         }
  145.     }
  146. }
  147.  
  148. class enemies {
  149.     public static void main() throws IOException {
  150.         String monster;
  151.         int drop, level, mint, mhp;
  152.        
  153.         mint = misc.random(10);
  154.        
  155.         if (mint >= 7) {
  156.             monster = "Goblin";
  157.         } else {
  158.             monster = "Wizard";
  159.         }
  160.        
  161.         battle obj = new battle(); // calls the battle class
  162.        
  163.         level = misc.random(3); // Makes a random level for the enemy.
  164.        
  165.         mhp = level + 3;
  166.        
  167.         drop = misc.random(level);
  168.        
  169.         if(drop <= 0) {
  170.             drop = 1;
  171.         }
  172.        
  173.         drop = drop * 3;
  174.        
  175.         obj.main(monster, level, mhp, drop); // sends the String monster to the battle class.
  176.     }
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement