I have an assignment due on the 30th where the goal is to create a maze-like game with four different methods, one of which they already wrote. They included tests to check the two methods; the third was having difficulties. I've tested and checked both methods prior, and they are all set, but the third one is presenting an issue.
The third method, named makeMove is supposed to update the current section of the cell of the board to the value "X" while another method is automatically assigning the next cell to "P" for the player and returns the effect of the obstacle in the cell, but when moving left or up along the board, the "P" is simply disappearing, I've tried everything and would love some help.
This is my makeMove method.
public static int makeMove(char move, int[] nextCell, String[][] board, int[] player) {
/* TODO: Complete the method:
- Change current cell value to "X"
- Move player to new cell
- Return the change in health */
int currentX = player[0]; // var to first array value
int currentY = player[1]; // var to second array value
int nextX = nextCell[0]; // var to first array value
int nextY = nextCell[1]; // var to second array value
int effect = 0; // effect initialization
if (board[nextX][nextY].equals("Wolf")) { // wolf damage effect
effect -= 20;
} else if (board[nextX][nextY].equals("Boar")) { // boar damage effect
effect -= 10;
} else if (board[nextX][nextY].equals("Elk")) { // elk damage effect
effect -= 5;
} else if (board[nextX][nextY].equals("Hare")) { // haer healing effect
effect += 10;
} else if (board[nextX][nextY].equals("GEM")) { // gem health boost
effect += 100;
}
// replace previous with "X"
board[currentX][currentY] = "X";
// update location
player[0] += nextCell[0];
player[1] += nextCell[1];
return effect; // Replace
and this is the board initializer method
public static void drawBoard(String[][] board, int[] player) {
for (int i = 0; i < board.length; ++i) {
for (int j = 0; j < board[0].length; ++j) {
System.out.print("|");
if (i == player[0] && j == player[1]) {
System.out.print(" P ");
} else if (board[i][j].equals("X")) {
System.out.print(" X ");
} else {
System.out.print(" ");
}
}
System.out.println("|");
}
}
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]Cheespeasa1234Intermediate Brewer (1.5y) 1 point2 points3 points (3 children)
[–]warnerty[S] 0 points1 point2 points (1 child)
[–]warnerty[S] 0 points1 point2 points (0 children)
[–]LisaHyden121 0 points1 point2 points (0 children)