Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //NULL: How to compact: "while ((command.equals("n")) || (command...."
- //How to consolidate the intense number of "if (x == 10 && y == 10) {" etc. groups cleanly
- import java.util.Scanner;
- public class Testing {
- public static void name( String args[]) {
- Scanner input = new Scanner(System.in);
- System.out.println("What is your name, hero?");
- String hero1Name = input.nextLine();
- System.out.println("Welcome to Castle Alpha, " + hero1Name +"!");
- System.out.println("What is the name of your companions?");
- System.out.println("What is your companion's name?");
- String hero2Name = input.nextLine ();
- System.out.println("Welcome to the party, " + hero2Name + "!");
- }
- public static void main( String args[]) {
- Scanner input = new Scanner(System.in);
- int x = 10;
- int y = 10;
- int area = 1;
- // int numCommand = 0;
- String command = "";
- while (area == 1) {
- if (command.equals("quit")) {
- break;
- }
- if (x == 10 && y == 10) {
- System.out.println(x + ", " + y + "\nYou are in the town centre.\nYou may go north, east, south, or west.");
- System.out.println("Command?");
- command = input.nextLine();
- while ((!command.equals("")) || (!command.equals("quit"))) {
- if (command.equals("n")) {
- y = y + 1;
- command = "";
- } else if (command.equals("s")) {
- // y = y - 1;
- System.out.println("Unavailable at this time.");
- command = "";
- } else if (command.equals("w")) {
- // x = x - 1;
- System.out.println("Unavailable at this time.");
- command = "";
- } else if (command.equals("e")) {
- // x = x + 1;
- System.out.println("Unavailable at this time.");
- command = "";
- } else if ((command.equals("quit")) || (command.equals("q"))) {
- command = "quit";
- } else {
- System.out.println("Unrecognised command. Try again.");
- command = input.nextLine();
- }
- }
- } if (x == 10 && y == 11) {
- 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.");
- System.out.println("Command?");
- command = input.nextLine();
- while (!command.equals("")) {
- if (command.equals("n")) {
- // y = y + 1;
- System.out.println("Unavailable at this time.");
- command = "";
- } else if (command.equals("s")) {
- y = y - 1;
- command = "";
- } else if (command.equals("w")) {
- x = x - 1;
- // System.out.println("Unavailable at this time.");
- command = "";
- } else if (command.equals("e")) {
- // x = x + 1;
- System.out.println("You cannot go that way.");
- command = "";
- } else {
- System.out.println("Unrecognised command. Try again.");
- command = input.nextLine();
- }
- }
- } if (x == 9 && y == 11) {
- command = "";
- System.out.println("Welcome to the General Store!");
- System.out.println("Would you like to buy or sell?");
- System.out.println("--Buy");
- System.out.println("--Sell");
- System.out.println("--Quit");
- command = input.nextLine();
- while (!command.equals("")) {
- if ((command.equals("buy")) || (command.equals("b"))) {
- // Store genStore = new Store;
- } else if ((command.equals("sell")) || (command.equals("s"))) {
- // Store genStore = new Store;
- } else if ((command.equals("quit")) || (command.equals("q"))) {
- command = "";
- } else {
- System.out.println("Unrecognised command. Try again.");
- command = input.nextLine();
- }
- }
- x = x + 1;
- }
- }
- while (area == 2) {
- ////STATEMENT RESERVED FOR AREA 2
- }
- while ((area != 1) || (area != 2)) {
- ////TEMPORARY STATEMENT CONCERNING INVALID AREAS
- System.out.println("Area does not exist");
- }
- System.out.println("TERMINATING");
- }
- }
- // //CHARACTER VARIABLE DECLARATION
- // int health = 100;
- // int mana = 100;
- // int stamina = 100;
- // int STR = 10;
- // int CON = 10;
- // int INT = 10;
- // int WIS = 10;
- // int DEX = 10;
- // int CHA = 10;
- //while (!command.equals("")) {
- // if (command.equals("n")) {
- //// y = y + 1;
- // System.out.println("Unavailable at this time.");
- // command = "";
- // } else if (command.equals("s")) {
- //// y = y - 1;
- // System.out.println("Unavailable at this time.");
- // command = "";
- // } else if (command.equals("w")) {
- //// x = x - 1;
- // System.out.println("Unavailable at this time.");
- // command = "";
- // } else if (command.equals("e")) {
- //// x = x + 1;
- // System.out.println("Unavailable at this time.");
- // command = "";
- // } else {
- // System.out.println("Unrecognised command. Try again.");
- // command = input.nextLine();
- // }
- //}
Add Comment
Please, Sign In to add comment