Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ExerciseFour;
- import javax.swing.*;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.Scanner;
- public class Exercise4 extends JFrame {
- public static Boolean[][] getMaze() {
- {
- int rowCounter = 0;
- System.out.println("Please input the maze you want to play (see below for the input needed for each maze):");
- System.out.println("-> maze21.txt = 'easy'");
- System.out.println("-> maze41.txt = 'medium'");
- System.out.println("-> maze61.txt = 'hard'");
- Scanner input = new Scanner(System.in);
- String mazeType = input.next().trim();
- if (mazeType.equals("easy")) {
- try {
- File file = new File("C:\\Users\\Wiktoria\\Desktop\\src\\maze21.txt");
- input = new Scanner(file);
- boolean[][] booleanArray = new boolean[21][21];
- while (input.hasNextLine()) {
- String line = input.nextLine();
- for (int i = 0; i < line.length(); i++) {
- char lineChar = line.charAt(i);
- if ('#' == (lineChar)) {
- booleanArray[rowCounter][i] = true;
- } else if (' ' == (lineChar)) {
- booleanArray[rowCounter][i] = false;
- }
- }
- rowCounter++;
- }
- for (int x = 0; x < booleanArray.length; x++) {
- for (int y = 0; y < booleanArray[x].length; y++) {
- if (booleanArray[x][y] == true) {
- System.out.print("#");
- } else if (booleanArray[x][y] == false) {
- System.out.print(" ");
- }
- }
- System.out.println();
- }
- } catch (Exception e) {
- }
- }
- if (mazeType.equals("medium")) {
- try {
- File file = new File("C:\\Users\\Wiktoria\\Desktop\\src\\maze41.txt");
- input = new Scanner(file);
- boolean[][] booleanArray = new boolean[41][41];
- while (input.hasNextLine()) {
- String line = input.nextLine();
- for (int i = 0; i < line.length(); i++) {
- char lineChar = line.charAt(i);
- if ('#' == (lineChar)) {
- booleanArray[rowCounter][i] = true;
- } else if (' ' == (lineChar)) {
- booleanArray[rowCounter][i] = false;
- }
- }
- rowCounter++;
- }
- for (int x = 0; x < booleanArray.length; x++) {
- for (int y = 0; y < booleanArray[x].length; y++) {
- if (booleanArray[x][y] == true) {
- System.out.print("#");
- } else if (booleanArray[x][y] == false) {
- System.out.print(" ");
- }
- }
- System.out.println();
- }
- } catch (Exception e) {
- }
- }
- if (mazeType.equals("hard")) {
- try {
- File file = new File("C:\\Users\\Wiktoria\\Desktop\\src\\maze61.txt");
- input = new Scanner(file);
- boolean[][] booleanArray = new boolean[61][61];
- while (input.hasNextLine()) {
- String line = input.nextLine();
- for (int i = 0; i < line.length(); i++) {
- char lineChar = line.charAt(i);
- if ('#' == (lineChar)) {
- booleanArray[rowCounter][i] = true;
- } else if (' ' == (lineChar)) {
- booleanArray[rowCounter][i] = false;
- }
- }
- rowCounter++;
- }
- for (int x = 0; x < booleanArray.length; x++) {
- for (int y = 0; y < booleanArray[x].length; y++) {
- if (booleanArray[x][y] == true) {
- System.out.print("#");
- } else if (booleanArray[x][y] == false) {
- System.out.print(" ");
- }
- }
- System.out.println();
- }
- } catch (Exception e) {
- }
- }
- }
- return getMaze();
- }
- public static void main(String args[]) throws FileNotFoundException {
- getMaze();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement