Question: Please make the code below look like more of an actual maze , and be more fun (perhaps with bombs and such) and say yay
Please make the code below look like more of an actual maze, and be more fun (perhaps with bombs and such) and say "yay" or something when user reaches the end (far right). As of now, the maze looks physically messy/confusing, and it's not even a maze... more like a free for all moving all about... Thank you!!
Here's the prompt for the Java Maze program:
Create a 2-D String array that can be moved through by a user. Establish a path that must be followed from [0][0] to the last [row][col] value in your array.
And here's my code as of now...
import java.util.*;
public class Maze { private static String maze[][];
public Maze() { maze = new String[5][5]; for(int i = 0; i < 5; i++) for(int j = 0; j < 5; j++) maze[i][j] = "-"; } public String toString() { String result = ""; result += " | | | | "; result += " " + maze[0][0] + " | " + maze[0][1] + " | " + maze[0][2] + " | " + maze[0][3] + " | " + maze[0][4] + " "; result += "_____|_____|_____|_____|_____ "; result += " | | | | "; result += " " + maze[1][0] + " | " + maze[1][1] + " | " + maze[1][2] + " | " + maze[1][3] + " | " + maze[1][4] + " "; result += "_____|_____|_____|_____|_____ "; result += " | | | | "; result += " " + maze[2][0] + " | " + maze[2][1] + " | " + maze[2][2] + " | " + maze[2][3] + " | " + maze[2][4] + " "; result += "_____|_____|_____|_____|_____ "; result += " | | | | "; result += " " + maze[3][0] + " | " + maze[3][1] + " | " + maze[3][2] + " | " + maze[3][3] + " | " + maze[3][4] + " "; result += "_____|_____|_____|_____|_____ "; result += " | | | | "; result += " " + maze[4][0] + " | " + maze[4][1] + " | " + maze[4][2] + " | " + maze[4][3] + " | " + maze[4][4] + " "; result += " | | | | "; return result; } public static void main(String args[]) { int row = 5, col = 5, choice, currentRow = 0, currentCol = 0; Scanner scan = new Scanner(System.in); Maze maize = new Maze(); maze[currentRow][currentCol] = "X"; do { System.out.println("Enter 0 to exit maze"); System.out.println("Enter 1 to go up"); System.out.println("Enter 2 to go down"); System.out.println("Enter 3 to go to the left"); System.out.println("Enter 4 to go to the right"); System.out.println("Pls pick an option(1,2,3,4 or 0)..."); choice = scan.nextInt(); if(choice == 1) { if((currentRow-1) >= 0) { maze[currentRow][currentCol] = "-"; currentRow--; maze[currentRow][currentCol] = "X"; } else System.out.println("Nope, can't move up"); } else if(choice == 2) { if((currentRow+1)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
