Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am trying to write a program where a mouse M moves through a maze by a random number. So either it moves up, down,

I am trying to write a program where a mouse "M" moves through a maze by a random number. So either it moves up, down, left, right or diagonal. So, a total of 4 possible. The mouse can only move forward so either diagnolly down toward the furthest bottom right corner. it can also move down or right, but never back or off the edge of the maze. Im trying to move the mouse one time with a switch statement. I have two array setup. One with what I would display as the maze, and the other where I could use the rows and columns to determine the movement of the mouse. I am stuck on how to get the mouse to move with my switch. can you help? here is my code so far... (JAVA)

import java.util.Scanner;

public class MouseMaze

{

public static void main (String[] args){

Scanner keyboard = new Scanner(System.in);

System.out.println("*** Mouse Maze ***");

int x=0,y=0;

char [][] maze = new char [10][10];

int [][] realMaze= new int [10][10];

char cat='C';

char mouse='M';

// System.out.println("Enter array dimensions (note: it will be a square so if you enter 5, the maze is 5x5)");

// int dim=keyboard.nextInt();

// System.out.println("The array will be "+dim+"x"+dim);

// char [][] maze = new char [dim][dim];

System.out.println("Array is 10x10");

// if (dim>100)

// System.out.println("You must be crazy, im not making a mouse run that far.");

int randomNumber=(int)(Math.random()*8+1);

System.out.println("Random Number is: "+randomNumber);

// initialize array

int dim=10;

for (int row=0; row

for (int column=0; column

maze[row][column]='-';

// end of initialize array

maze[0][0]=mouse;

// print out array

for (int r=0;r

{

for (int c=0; c

{

System.out.print(maze[r][c]+" ");

} //end of c loop

System.out.println();

} //end of r loop

//initilaze second array to hold real moves

for (x=0; x

for (y=0; y

realMaze[x][y]=0;

// end of second array

switch(randomNumber){

// case 1: System.out.println("Mouse moved back");

// break;

// case 2:

case 3: System.out.println("Mouse moved back");

break;

case 4:

// break;

case 5: x+=1;

case 6:

case 7:

case 8:

}

// maze[0][0]=mouse;

} // public static void main end

} // public class MouseMaze end

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago