i need to fill up 1/10th of the board with mines but i am only able to successfully put 1! also my goal is not showing up on the game even though i put it as an up arrow.
package Homework4; import java.util.Random; import java.util.Scanner; public class HW4 { //Creates a new type to be used to create the board //We know that the board can only take on the value of Empty, Player, Walked_Path, and Goal //Thus it is better to use an enum and define these types instead of using an integer or a string //which would take up a lot of space in memory enum Spaces {Empty, Player, Walked_Path, Goal, mine}; public static final int BOARD_SIZE = 10; // public static final double mine = (BOARD_SIZE*BOARD_SIZE)/10; public static void main(String[] args) { // TODO Auto-generated method stub //Keep track of the number of moves made by the player int numberOfMoves = 0; //The player's location int pX = 0; int pY = 0; //The target location Random r = new Random(); int tX = r.nextInt(BOARD_SIZE); int tY = r.nextInt(BOARD_SIZE); //User input Scanner keyboard = new Scanner(System.in); //Set up the board Spaces[][] board = new Spaces[BOARD_SIZE][BOARD_SIZE]; //Initialize the board for(int y=0;y<board.length;y++) { for(int x=0;x<board[y].length;x++) { board[x][y] = Spaces.Empty; } } //Put the user on the board board[pX][pY] = Spaces.Player; //Puts the goal on the board board[tX][tY] = Spaces.Goal; //puts the mines on the board board[tX][tY] = Spaces.mine; //Prompt the user System.out.println("Welcome to catch me where you have to catch the enemy"); //Game over condition boolean gameOver = false; while(gameOver == false) { //Draw the board for(int y=0;y<board.length;y++) { for(int x=0;x<board[y].length;x++) { switch(board[x][y]) { case Empty: System.out.print("_"); break; case Player: System.out.print("X"); break; case Walked_Path: System.out.print("#"); break; case Goal: System.out.print("^"); break; case mine: System.out.print("M"); break; } } System.out.println(" "); } //Calculates the distance. This doesn't use square root in order to save processing cycles //The player moves System.out.println("Enter either -1,0,1 to move in the x or 9 to quit"); //Movement in the X direction int dX = keyboard.nextInt(); //Or quit if(dX == 9) { System.out.println("Game over"); break; } System.out.println("Enter either -1,0,1 to move in the y"); //Movement in the y direction int dY = keyboard.nextInt(); //Checks to see if the movement is valid if(dX <-1 || dX>1) { System.out.println("Invalid input X"); dX = 0; } if(dY <-1 || dY>1) { System.out.println("Invalid input Y"); dY = 0; } //Sets the player position to a walked path board[pX][pY] = Spaces.Walked_Path; //Moves the player pX+=dX; pY+=dY; //Makes sure everything is still in bounds if(pX < 0) { pX = 0; } else if(pX>BOARD_SIZE-1) { pX = BOARD_SIZE-1; } if(pY < 0) { pY = 0; } else if(pY> BOARD_SIZE-1) { pY = BOARD_SIZE-1; } //Winning condition if(board[pX][pY]==Spaces.mine) { System.out.println("You are dead!"); break; } if(board[pX][pY]==Spaces.Goal) { System.out.println("You win! The secret location was at "+tX+" "+tY); System.out.println("It took "+numberOfMoves+" moves"); gameOver = true; } //Sets the player in the new position board[pX][pY] = Spaces.Player; numberOfMoves++; } } }