Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- * Handles the Game loop, and Game logic along with input/ responses
- */
- public class Game {
- private boolean running = true;
- public int playX;
- public int playY;
- Entity e1;
- Item item;
- private Scanner input = new Scanner(System.in);
- /**
- * Constructor for the Game loop / logic
- *
- * @param world The world the game interacts with
- */
- public Game(World world) {
- while (running) {
- //Prompt and input
- System.out.println("\nYou are located in the " + world.world[playX][playY].name);
- System.out.print(": ");
- String command = input.next().toLowerCase();
- //Perspective/ Player movement
- switch (command) {
- case "east":
- case "e":
- if (world.world[playX + 1][playY] != null
- && playX + 1 < world.world.length) {
- playX += 1;
- } else {
- System.out.println("You cannot go that way.");
- }
- break;
- case "west":
- case "w":
- if (playX > 0) { //NOTE: Kept throwing an out of bounds for 2D array, just did plain greater than bounds check
- playX -= 1; //NOTE: Wanted to do (world.world[playX-1][playY] != null) but no go
- } else {
- System.out.println("You cannot go that way.");
- }
- break;
- case "north":
- case "n":
- if (playY > 0) { //NOTE: Kept throwing an out of bounds for 2D array, just did plain greater than bounds check
- playY -= 1; //NOTE: Wanted to do (world.world[playX][playY-1] != null) but no go
- } else {
- System.out.println("You cannot go that way.");
- }
- break;
- case "south":
- case "s":
- if (world.world[playX][playY + 1] != null
- && playY + 1 < world.world[0].length) {
- playY += 1;
- } else {
- System.out.println("You cannot go that way.");
- }
- break;
- case "l":
- case "look":
- System.out.println(world.world[playX][playY].desc);
- if (world.world[playX][playY].contents.size() > 0) {
- world.world[playX][playY].contents();
- }
- break;
- case "quit":
- case "exit":
- case "q":
- running = false;
- break;
- case "get":
- System.out.println("What would you like to get?");
- String command2 = input.next().toLowerCase();
- if(item.name.equals(command2)){
- e1.ItemGet(item);
- world.world[playX][playY].removeItem(item);
- System.out.println("You've gotten the " + item);
- }else{
- System.out.println("I do not see the " + item);
- }
- default:
- System.out.println("Your command of " + command + " was not understood.");
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement