Here's the question explicitly: I want to get the coordinate of the mouse and put that in a variable that I can plug into the equation shown in the code below [method movePosition()]. Is this possible or do I have to figure out a different approach?
The question is won't make sense without context, so here's a description: A mouse has 8 possible moves to make in a maze, which work wherever it is. A random number is picked to represent the move the mouse has to take. In my head it looks like this, the "-" being the mouse itself:
1 2 3
4 - 5
6 7 8
If the mouse is at move #F, for example, how would I get it to move to position 8 (move #G from the example below)
A B 0 F 0 0 0 0
0 0 C E G J K L
0 0 D H I 0 M N
I was thinking to make a switch statement with each "coordinate" matching to a number from 1-8 which would look like so:
public int movePosition()
{
int moveToPosition = movePicker();
switch (moveToPosition)
{
case 1:
this.getMaze()[row - 1][column - 1] = mouse;
break;
case 2:
this.getMaze()[row - 1][column] = mouse;
break;
case 3:
this.getMaze()[row - 1][column + 1] = mouse;
break;
//and so on...
}
But I realized that wouldn't work for obvious reasons. (row and column are the user defined row and column) Is there a way I could follow this same logic wherever the mouse is? I want to get the coordinate of the mouse and put that in a variable that I can plug into the equation above. Or do I have to figure out a different approach?
This is what I found similar to what I want (click here) and other questions are sort of like that too. However they all are asking how to find the coordinates from the size of the array. I need to know how to find the coordinate from the position of the mouse which could be anywhere.
Some Background:
This is homework. I have looked at other questions and although some are related to what I'm looking for, they don't have what I need.
I have a mouse that's thrown in a user defined maze. This means that I, the programmer, don't know what the size of the maze is. After the user defines the size of the maze, it gets set up with 0's. For example's sake, let's do a 3 x 8 maze.
The maze then looks like this (but user can't see this part):
array[3][8]:
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
By the end of the program, the mouse would have crossed to the end leaving behind a number indicated to the move it made. A for the first move, B for the second, C for the third, etc. this is just an example the actual code has numbers not letters. I just need to differentiate for clarity The output would look as so (user sees this):
A B 0 F 0 0 0 0
0 0 C E G J K L
0 0 D H I 0 M N
Thanks!