Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.util.Scanner;
- public class Main1 {
- static int[][] player = new int[4][3];
- static String[][] houseRooms;
- public static void main(String[] args) {
- //String array of all the rooms in the house
- houseRooms = new String[3][3];
- houseRooms[0][0] = "Computer Room";
- houseRooms[0][1] = "Living Room";
- houseRooms[0][2] = "Deck";
- houseRooms[1][0] = "Hallway";
- houseRooms[1][1] = "Bathroom";
- houseRooms[1][2] = "Living Room 2";
- houseRooms[2][0] = "Dining Room";
- houseRooms[2][1] = "Kitchen";
- houseRooms[2][2] = "Laundary Room";
- room();
- }
- public static void room() {
- // Randomizer to where the player and the dog will apear
- Random room = new Random();
- int startingLocationX = room.nextInt(3);
- int startingLocationY = room.nextInt(3);
- int finishLocationX = room.nextInt(3);
- int finishLocationY = room.nextInt(3);
- player[startingLocationX][startingLocationY] = 2;
- player[finishLocationX][finishLocationY] = 3;
- // Tells player where they are as well as where the dog is.
- System.out.println("You have started in: " + houseRooms[startingLocationX][startingLocationY]);
- System.out.println("The Dog has appeared in: " + houseRooms[finishLocationX][finishLocationY]);
- if (startingLocationX == finishLocationX && startingLocationY == finishLocationY) {
- System.out.println("You have started in the same position as the Dog!");
- System.exit(0);
- }
- movement(startingLocationX, startingLocationY, finishLocationX, finishLocationY);
- }
- // Gives the winning and losing conditions
- public static void movement(int startingLocationX, int startingLocationY, int finishLocationX, int finishLocationY) {
- //tells what directions the player can move as well as the starting location
- //of the player and the dog
- int directionNum[] = {0, 1, 2, 3};
- String directionCump[] = {"North", "South", "East", "West"};
- int inv = 0;
- int x = 0;
- do {
- if ((startingLocationX != finishLocationX) && startingLocationY != finishLocationY) {
- move(startingLocationX, startingLocationY, finishLocationX, finishLocationY, directionCump, directionNum);
- inv = 0;
- x++;
- } else {
- inv = 1;
- }
- } while (inv == 0 || x == 10);
- if (inv == 1 && x != 10) {
- System.out.println("You found the dog now take him outside");
- } else if (inv == 1 && x == 10) {
- System.out.println("You found the dog now take him outside");
- } else {
- System.out.println("You didn't find the dog in time but you can smell what is waiting for you.");
- }
- }
- // Where the player will chose their movement as well as telling the player where they are in the room.
- public static int move(int positionX, int positionY, int dogLocationX, int dogLocationY, String[] directionCump, int[] directionNum) {
- // Declare Scanner.
- Scanner num1;
- num1 = new Scanner(System.in);
- String movementChoice;
- String posnum;
- String positions;
- // Print out options.
- System.out.println("You are in the " + houseRooms[positionX][positionY] + ", where would you like to go?");
- System.out.println();
- System.out.print("Enter 1, 2, 3 or 4 to move: ");
- Scanner userInput = new Scanner(System.in);
- String in = userInput.nextLine();
- if(in.equals("0") || in.equals("1") || in.equals("2") || in.equals("3"))
- {
- if (in.equalsIgnoreCase("0"))
- {
- positionX = positionX + 1;
- }
- if (in.equalsIgnoreCase("1"))
- {
- positionX = positionX - 1;
- }
- if (in.equalsIgnoreCase("2"))
- {
- positionY = positionY - 1;
- }
- if (in.equalsIgnoreCase("3"))
- {
- positionY = positionY + 1;
- }
- }
- else
- {
- System.out.println("Input invalid! Please enter 1,2,3 or 4.");
- }
- // Get the movement choice.
- movementChoice = userInput.nextLine();
- // If possible choice is selected then the player will move.
- if (houseRooms[positions] != 0 && movementChoice < 4 && movementChoice > -1) {
- posnum = houseRooms[positions][movementChoice];
- return posnum;
- }
- // if movment is not possible says there is no room there.
- else
- System.out.println("There is no room there");
- posnum = positions;
- return posnum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement