zopiac

Game Alpha

Oct 7th, 2010
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.79 KB | None | 0 0
  1. //NULL: How to compact: "while ((command.equals("n")) || (command...."
  2. //How to consolidate the intense number of  "if (x == 10 && y == 10) {" etc. groups cleanly
  3. import java.util.Scanner;
  4. public class Testing {
  5.     public static void name( String args[]) {
  6.         Scanner input = new Scanner(System.in);
  7.         System.out.println("What is your name, hero?");
  8.         String hero1Name = input.nextLine();
  9.         System.out.println("Welcome to Castle Alpha, " + hero1Name +"!");
  10.         System.out.println("What is the name of your companions?");
  11.         System.out.println("What is your companion's name?");
  12.         String hero2Name = input.nextLine ();
  13.         System.out.println("Welcome to the party, " + hero2Name + "!");
  14.     }
  15.     public static void main( String args[]) {
  16.         Scanner input = new Scanner(System.in);
  17.         int x = 10;
  18.         int y = 10;
  19.         int area = 1;
  20. //      int numCommand = 0;
  21.         String command = "";
  22.         while (area == 1) {
  23.             if (command.equals("quit")) {
  24.                 break;
  25.             }
  26.             if (x == 10 && y == 10) {
  27.                 System.out.println(x + ", " + y + "\nYou are in the town centre.\nYou may go north, east, south, or west.");
  28.                 System.out.println("Command?");
  29.                 command = input.nextLine();
  30.  
  31.                 while ((!command.equals("")) || (!command.equals("quit"))) {
  32.                     if (command.equals("n")) {
  33.                         y = y + 1;
  34.                         command = "";
  35.                     } else if (command.equals("s")) {
  36. //                      y = y - 1;
  37.                         System.out.println("Unavailable at this time.");
  38.                         command = "";
  39.                     } else if (command.equals("w")) {
  40. //                      x = x - 1;
  41.                         System.out.println("Unavailable at this time.");
  42.                         command = "";
  43.                     } else if (command.equals("e")) {
  44. //                      x = x + 1;
  45.                         System.out.println("Unavailable at this time.");
  46.                         command = "";
  47.                     } else if ((command.equals("quit")) || (command.equals("q"))) {
  48.                         command = "quit";
  49.                     } else {
  50.                         System.out.println("Unrecognised command. Try again.");
  51.                         command = input.nextLine();
  52.                     }
  53.                 }
  54.             } if (x == 10 && y == 11) {
  55.                 System.out.println(x + ", " + y + "\nYou are on Main Street, north of the town centre.\nYou may go north or south.\nThere is a General Store to your west.");
  56.                 System.out.println("Command?");
  57.                 command = input.nextLine();
  58.                 while (!command.equals("")) {
  59.                     if (command.equals("n")) {
  60. //                      y = y + 1;
  61.                         System.out.println("Unavailable at this time.");
  62.                         command = "";
  63.                     } else if (command.equals("s")) {
  64.                         y = y - 1;
  65.                         command = "";
  66.                     } else if (command.equals("w")) {
  67.                         x = x - 1;
  68. //                      System.out.println("Unavailable at this time.");
  69.                         command = "";
  70.                     } else if (command.equals("e")) {
  71. //                      x = x + 1;
  72.                         System.out.println("You cannot go that way.");
  73.                         command = "";
  74.                     } else {
  75.                         System.out.println("Unrecognised command. Try again.");
  76.                         command = input.nextLine();
  77.                     }
  78.                 }
  79.             } if (x == 9 && y == 11) {
  80.                 command = "";
  81.                 System.out.println("Welcome to the General Store!");
  82.                 System.out.println("Would you like to buy or sell?");
  83.                 System.out.println("--Buy");
  84.                 System.out.println("--Sell");
  85.                 System.out.println("--Quit");
  86.                 command = input.nextLine();
  87.                 while (!command.equals("")) {
  88.                     if ((command.equals("buy")) || (command.equals("b"))) {
  89. //                      Store genStore = new Store;
  90.                     } else if ((command.equals("sell")) || (command.equals("s"))) {
  91. //                      Store genStore = new Store;
  92.                     } else if ((command.equals("quit")) || (command.equals("q"))) {
  93.                         command = "";
  94.                     } else {
  95.                         System.out.println("Unrecognised command. Try again.");
  96.                         command = input.nextLine();
  97.                     }
  98.                 }
  99.                 x = x + 1;
  100.             }
  101.         }
  102.         while (area == 2) {
  103.             ////STATEMENT RESERVED FOR AREA 2
  104.         }
  105.         while ((area != 1) || (area != 2)) {
  106.             ////TEMPORARY STATEMENT CONCERNING INVALID AREAS
  107.             System.out.println("Area does not exist");
  108.         }
  109.         System.out.println("TERMINATING");
  110.     }
  111. }
  112.  
  113. //              //CHARACTER VARIABLE DECLARATION
  114. //                int health = 100;
  115. //                int mana = 100;
  116. //                int stamina = 100;
  117. //                int STR = 10;
  118. //                int CON = 10;
  119. //                int INT = 10;
  120. //                int WIS = 10;
  121. //                int DEX = 10;
  122. //                int CHA = 10;
  123.  
  124.  
  125. //while (!command.equals("")) {
  126. //  if (command.equals("n")) {
  127. ////        y = y + 1;
  128. //      System.out.println("Unavailable at this time.");
  129. //      command = "";
  130. //  } else if (command.equals("s")) {
  131. ////        y = y - 1;
  132. //      System.out.println("Unavailable at this time.");
  133. //      command = "";
  134. //  } else if (command.equals("w")) {
  135. ////        x = x - 1;
  136. //      System.out.println("Unavailable at this time.");
  137. //      command = "";
  138. //  } else if (command.equals("e")) {
  139. ////        x = x + 1;
  140. //      System.out.println("Unavailable at this time.");
  141. //      command = "";
  142. //  } else {
  143. //      System.out.println("Unrecognised command. Try again.");
  144. //      command = input.nextLine();
  145. //  }
  146. //}
Add Comment
Please, Sign In to add comment