Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.19 KB | None | 0 0
  1. package ExerciseFour;
  2.  
  3. import javax.swing.*;
  4. import java.io.File;
  5. import java.io.FileNotFoundException;
  6. import java.util.Scanner;
  7.  
  8. public class Exercise4 extends JFrame {
  9.  
  10.  
  11. public static Boolean[][] getMaze() {
  12. {
  13.  
  14. int rowCounter = 0;
  15.  
  16. System.out.println("Please input the maze you want to play (see below for the input needed for each maze):");
  17. System.out.println("-> maze21.txt = 'easy'");
  18. System.out.println("-> maze41.txt = 'medium'");
  19. System.out.println("-> maze61.txt = 'hard'");
  20. Scanner input = new Scanner(System.in);
  21. String mazeType = input.next().trim();
  22.  
  23. if (mazeType.equals("easy")) {
  24. try {
  25. File file = new File("C:\\Users\\Wiktoria\\Desktop\\src\\maze21.txt");
  26. input = new Scanner(file);
  27. boolean[][] booleanArray = new boolean[21][21];
  28.  
  29. while (input.hasNextLine()) {
  30. String line = input.nextLine();
  31. for (int i = 0; i < line.length(); i++) {
  32. char lineChar = line.charAt(i);
  33. if ('#' == (lineChar)) {
  34. booleanArray[rowCounter][i] = true;
  35. } else if (' ' == (lineChar)) {
  36. booleanArray[rowCounter][i] = false;
  37. }
  38. }
  39. rowCounter++;
  40. }
  41. for (int x = 0; x < booleanArray.length; x++) {
  42. for (int y = 0; y < booleanArray[x].length; y++) {
  43. if (booleanArray[x][y] == true) {
  44. System.out.print("#");
  45. } else if (booleanArray[x][y] == false) {
  46. System.out.print(" ");
  47. }
  48.  
  49. }
  50. System.out.println();
  51. }
  52. } catch (Exception e) {
  53. }
  54.  
  55.  
  56. }
  57.  
  58.  
  59. if (mazeType.equals("medium")) {
  60. try {
  61. File file = new File("C:\\Users\\Wiktoria\\Desktop\\src\\maze41.txt");
  62. input = new Scanner(file);
  63. boolean[][] booleanArray = new boolean[41][41];
  64.  
  65. while (input.hasNextLine()) {
  66. String line = input.nextLine();
  67. for (int i = 0; i < line.length(); i++) {
  68. char lineChar = line.charAt(i);
  69. if ('#' == (lineChar)) {
  70. booleanArray[rowCounter][i] = true;
  71. } else if (' ' == (lineChar)) {
  72. booleanArray[rowCounter][i] = false;
  73. }
  74. }
  75. rowCounter++;
  76. }
  77. for (int x = 0; x < booleanArray.length; x++) {
  78. for (int y = 0; y < booleanArray[x].length; y++) {
  79. if (booleanArray[x][y] == true) {
  80. System.out.print("#");
  81. } else if (booleanArray[x][y] == false) {
  82. System.out.print(" ");
  83. }
  84.  
  85. }
  86. System.out.println();
  87. }
  88. } catch (Exception e) {
  89. }
  90. }
  91.  
  92.  
  93. if (mazeType.equals("hard")) {
  94. try {
  95. File file = new File("C:\\Users\\Wiktoria\\Desktop\\src\\maze61.txt");
  96. input = new Scanner(file);
  97. boolean[][] booleanArray = new boolean[61][61];
  98.  
  99. while (input.hasNextLine()) {
  100. String line = input.nextLine();
  101. for (int i = 0; i < line.length(); i++) {
  102. char lineChar = line.charAt(i);
  103. if ('#' == (lineChar)) {
  104. booleanArray[rowCounter][i] = true;
  105. } else if (' ' == (lineChar)) {
  106. booleanArray[rowCounter][i] = false;
  107. }
  108. }
  109. rowCounter++;
  110. }
  111. for (int x = 0; x < booleanArray.length; x++) {
  112. for (int y = 0; y < booleanArray[x].length; y++) {
  113. if (booleanArray[x][y] == true) {
  114. System.out.print("#");
  115. } else if (booleanArray[x][y] == false) {
  116. System.out.print(" ");
  117. }
  118.  
  119. }
  120. System.out.println();
  121. }
  122. } catch (Exception e) {
  123. }
  124. }
  125.  
  126. }
  127. return getMaze();
  128.  
  129. }
  130.  
  131. public static void main(String args[]) throws FileNotFoundException {
  132. getMaze();
  133.  
  134.  
  135. }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement