Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.Scanner;
  3.  
  4. public class Main1 {
  5.  
  6. static int[][] player = new int[4][3];
  7. static String[][] houseRooms;
  8.  
  9. public static void main(String[] args) {
  10. //String array of all the rooms in the house
  11. houseRooms = new String[3][3];
  12. houseRooms[0][0] = "Computer Room";
  13. houseRooms[0][1] = "Living Room";
  14. houseRooms[0][2] = "Deck";
  15. houseRooms[1][0] = "Hallway";
  16. houseRooms[1][1] = "Bathroom";
  17. houseRooms[1][2] = "Living Room 2";
  18. houseRooms[2][0] = "Dining Room";
  19. houseRooms[2][1] = "Kitchen";
  20. houseRooms[2][2] = "Laundary Room";
  21.  
  22. room();
  23.  
  24. }
  25.  
  26. public static void room() {
  27. // Randomizer to where the player and the dog will apear
  28. Random room = new Random();
  29. int startingLocationX = room.nextInt(3);
  30. int startingLocationY = room.nextInt(3);
  31. int finishLocationX = room.nextInt(3);
  32. int finishLocationY = room.nextInt(3);
  33. player[startingLocationX][startingLocationY] = 2;
  34. player[finishLocationX][finishLocationY] = 3;
  35. // Tells player where they are as well as where the dog is.
  36. System.out.println("You have started in: " + houseRooms[startingLocationX][startingLocationY]);
  37. System.out.println("The Dog has appeared in: " + houseRooms[finishLocationX][finishLocationY]);
  38.  
  39. if (startingLocationX == finishLocationX && startingLocationY == finishLocationY) {
  40. System.out.println("You have started in the same position as the Dog!");
  41. System.exit(0);
  42. }
  43. movement(startingLocationX, startingLocationY, finishLocationX, finishLocationY);
  44. }
  45.  
  46. // Gives the winning and losing conditions
  47. public static void movement(int startingLocationX, int startingLocationY, int finishLocationX, int finishLocationY) {
  48. //tells what directions the player can move as well as the starting location
  49. //of the player and the dog
  50. int directionNum[] = {0, 1, 2, 3};
  51. String directionCump[] = {"North", "South", "East", "West"};
  52. int inv = 0;
  53. int x = 0;
  54.  
  55. do {
  56. if ((startingLocationX != finishLocationX) && startingLocationY != finishLocationY) {
  57. move(startingLocationX, startingLocationY, finishLocationX, finishLocationY, directionCump, directionNum);
  58. inv = 0;
  59. x++;
  60. } else {
  61. inv = 1;
  62. }
  63. } while (inv == 0 || x == 10);
  64.  
  65.  
  66. if (inv == 1 && x != 10) {
  67. System.out.println("You found the dog now take him outside");
  68. } else if (inv == 1 && x == 10) {
  69. System.out.println("You found the dog now take him outside");
  70. } else {
  71. System.out.println("You didn't find the dog in time but you can smell what is waiting for you.");
  72.  
  73. }
  74. }
  75.  
  76. // Where the player will chose their movement as well as telling the player where they are in the room.
  77.  
  78. public static int move(int positionX, int positionY, int dogLocationX, int dogLocationY, String[] directionCump, int[] directionNum) {
  79. // Declare Scanner.
  80. Scanner num1;
  81. num1 = new Scanner(System.in);
  82. String movementChoice;
  83. String posnum;
  84. String positions;
  85.  
  86. // Print out options.
  87. System.out.println("You are in the " + houseRooms[positionX][positionY] + ", where would you like to go?");
  88. System.out.println();
  89. System.out.print("Enter 1, 2, 3 or 4 to move: ");
  90. Scanner userInput = new Scanner(System.in);
  91. String in = userInput.nextLine();
  92. if(in.equals("0") || in.equals("1") || in.equals("2") || in.equals("3"))
  93. {
  94. if (in.equalsIgnoreCase("0"))
  95. {
  96. positionX = positionX + 1;
  97. }
  98.  
  99. if (in.equalsIgnoreCase("1"))
  100. {
  101. positionX = positionX - 1;
  102. }
  103.  
  104. if (in.equalsIgnoreCase("2"))
  105. {
  106. positionY = positionY - 1;
  107. }
  108.  
  109. if (in.equalsIgnoreCase("3"))
  110. {
  111. positionY = positionY + 1;
  112. }
  113. }
  114. else
  115. {
  116. System.out.println("Input invalid! Please enter 1,2,3 or 4.");
  117. }
  118.  
  119. // Get the movement choice.
  120. movementChoice = userInput.nextLine();
  121. // If possible choice is selected then the player will move.
  122. if (houseRooms[positions] != 0 && movementChoice < 4 && movementChoice > -1) {
  123. posnum = houseRooms[positions][movementChoice];
  124. return posnum;
  125. }
  126. // if movment is not possible says there is no room there.
  127. else
  128. System.out.println("There is no room there");
  129. posnum = positions;
  130. return posnum;
  131.  
  132.  
  133. }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement