Question
Please help me fix my JAVA code, do not alter FunkyGameDemo: package Funky_Game; public class FunkyGameDemo { public static void main(String[] args) { // TODO
Please help me fix my JAVA code, do not alter FunkyGameDemo:
package Funky_Game;
public class FunkyGameDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
FunkyToken winner = null;
FunkyBoard board = new FunkyBoard(7);
FunkyToken[] tokens = new FunkyToken[3];
tokens[0] = new RandomToken('@');
tokens[1] = new MoveOneToken('$');
tokens[2] = new RandomToken('&');
board.placeToken(tokens[0], 3, 1);
board.placeToken(tokens[1], 4, 4);
board.placeToken(tokens[2], 0, 0);
board.displayBoard();
do {
for (int i = 0; i
if (tokens[i].active) {
tokens[i].move(board);
System.out.println(tokens[i].token + "move");
board.displayBoard();
winner = board.getWinner();
if (winner != null)
break;
}
}
} while (winner == null);
System.out.println(winner.token + " won!");
}
}
package Funky_Game;
public abstract class FunkyToken {
public char token;
public boolean active;
private int currentRow;
private int currentColumn;
// public boolean active = true;
public FunkyToken(char token) {
this.token = token;
this.active = true;
}
public char getToken() {
return token;
}
public boolean isActive() {
return active;
}
public int getCurrentRow() {
return currentRow;
}
public void setCurrentRow(int currentRow) {
this.currentRow = currentRow;
}
public int getCurrentColumn() {
return currentColumn;
}
public void setCurrentColumn(int currentColumn) {
this.currentColumn = currentColumn;
}
public abstract void move(FunkyBoard board);
// public void move(FunkyToken[][] board, int row, int column) {
//
// }
}
package Funky_Game;
import java.util.Random;
public class MoveOneToken extends FunkyToken {
public MoveOneToken(char token) {
super(token);
}
public void move(FunkyBoard board) {
Random random = new Random();
int[] directions = { -1, 0, 1 };
while (true) {
int newRow = directions[random.nextInt(3)];
int newCol = directions[random.nextInt(3)];
if (isValidMove(board, newRow, newCol)) {
if (board.getBoard()[newRow][newCol] != null) {
System.out.println("Token at (" + newRow + "," + newCol + ") removed.");
}
board.placeToken(this, newRow, newCol);
board.placeToken(null, getCurrentRow(), getCurrentColumn()); // Remove the token from the current position
break;
}
}
}
private boolean isValidMove(FunkyBoard board, int row, int column) {
return row >= 0 && row = 0 && column
}
}
package Funky_Game;
import java.util.Random;
public class RandomToken extends FunkyToken {
public RandomToken(char token) {
super(token);
}
@Override
// public void move(FunkyToken[][] board, int row, int column) {
public void move(FunkyBoard board) {
Random random = new Random();
while (true) {
int newRow = random.nextInt(board.getCurrentrow());
int newCol = random.nextInt(board.getColumns());
if (board.getBoard()[newRow][newCol] != null) {
System.out.println("Token at (" + newRow + "," + newCol + ") removed.");
}
board.placeToken(this, newRow, newCol);
board.placeToken(null, getCurrentRow(), getCurrentColumn());
setCurrentRow(newRow);
setCurrentColumn(newCol);
break;
}
}
// int newRow = random.nextInt(board.length);
// int newCol = random.nextInt(board[0].length);
//
// if(board[newRow][newCol] != null) {
// System.out.println("Token at (" + newRow + "," + newCol + ") removed.");
// }
//
// board[newRow][newCol] = this;
// board[row][column] = null;
//
// }
}
package Funky_Game;
public class FunkyBoard {
private FunkyToken[][] board;
public FunkyBoard(int rows, int columns) {
board = new FunkyToken[rows][columns];
initializeBoard();
}
public FunkyToken[][] getBoard() {
return board;
}
public void setBoard(FunkyToken[][] board) {
this.board = board;
}
public void initializeBoard() {
char token = '-';
for (int i = 0; i
for (int j = 0; j
board[i][j] = new MoveOneToken(token);
token++;
}
}
}
public void placeToken(FunkyToken token, int row, int column) {
board[row][column] = token;
}
public void displayBoard() {
for (FunkyToken[] row : board) {
for (FunkyToken token : row) {
if (token != null) {
System.out.print(token.getToken() + " ");
} else {
System.out.print("- ");
}
}
System.out.println();
}
System.out.println();
}
public FunkyToken getWinner() {
return null;
}
// public void placeToken() {
// while (activeTokens() > 1) {
// for (int i = 0; i
// for (int j = 0; j
// if (board[i][j] != null) {
// board[i][j].move(board, i, j);
// displayBoard();
// }
// }
//
// }
// }
// System.out.println("Wins!");
//}
//private int activeTokens() {
// int active = 0;
// for (FunkyToken[][] row : board) {
// for(FunkyToken[][] token : row) {
// if(token != null) {
// active++;
// }
// }
// }
// return active;
//}
//
}
Funky Board Game Design and implement a funky board game. (Please see the intro video.) Tokens will take turns to move on the board. (logic provided in the demo code) When there is only one token left on the board it wins the game. Create a game board. The size of the board can be passed in as a parameter. (Similar to TicTacToe Board in MP6) Create a FunkyToken class: - Users can pass in the token symbol they want to use. - All token pieces should be able to move. Create 2 sub classes: MoveOneToken and RandomToken. - MoveOneToken will move at a random direction, but will only move one space at a time. If the token is going to move out of the board, it will try a different direction and move again. If the spot already has a token, it will be replaced and removed from the board. - RandomToken will move to any random spot on the board. If the spot already has a token, it will be replaced and removed from the board. Use the provided FunkyGameDemo code to test run your program. Copy and paste the output of your program to a txt file and submit it with your source code just like the machine problems
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started