title: Creating a Mine Walker
body: <p>I've built a small game in java where the objective is to move the player(X) to the ice cream cone(^).  These are the instructions to the game code
  <ul>
  Write a game where you are an X trying to get an ice cream cone in a mine field</p>
  
  
  <li>Before the game starts, a field of mines are created.</li>
  <li>The board has to be first initialized</li>
  <li>There mines occupy a tenth of the board (IE (BoardSize x BoardSize)/10 = the number of mines)</li>
  <li>The mines are randomly placed on the board.  If a space which is already occupied (either by the player, the ice cream cone, or another mine) is selected then another space must be selected until an empty space is found.</li>
  <li>The player is placed at 0,0</li>
  <li>The ice cream cone is placed at a random location on the board</li>
  <li>At each turn, the player chooses to move in the X or Y direction by entering either -1, 0, or 1, where</li>
  <li>-1 is going one space in the negative direction</li>
  <li>1 is going one space in the positive direction (remember positive for Y is down)</li>
  <li>0 is staying still</li>
  <li>9 quits the game</li>
  <li>Anything other than these values should prompt the player that they have inputted an invalid value and then not move in that direction (IE 0).</li>
  <li>Before each turn the board is displayed indicating where the player (X) and the goal (^) are located.  Unoccupied spaces and mines are denoted by and underscore (<em>).  Remember mines need to be hidden so they are also underscores (</em>).  The board is maximum 10 spaces long and wide.</li>
  <li>Once the player reaches the ice cream cone the player wins</li>
  <li>If the player lands on a space with a mine they are killed and the game is over</li>
  <li>After the game is over, the player should be prompted whether or not they  want to play again.
  This is the code:</li>
  </ul>
  
  <p>import java.util.Random;
  import java.util.Scanner;</p>
  
  <pre><code>public class MineWalker {
  enum Spaces {Mine,Empty,Player,IceCream};
  public static final int BOARD_SIZE = 10;
  public final static double MINE_PERCENT = 0.1;
  
  public static void main(String[] args) {
      // TODO Auto-generated method stub
      //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&lt;board.length;y++)
      {
          for(int x=0;x&lt;board[y].length;x++)
          {
              board[x][y] = Spaces.Empty;
          }
      }
      board[pX][pY] = Spaces.Player;
      //Puts the goal on the board
      board[tX][tY] = Spaces.IceCream;
      int mines = (int)(BOARD_SIZE * BOARD_SIZE * MINE_PERCENT);
      System.out.println("Welcome to Mine Walker.  Get the ice cream cone and avoid the mines");
      do
      {
         int x = r.nextInt(BOARD_SIZE - 1) + 1; 
         int y = r.nextInt(BOARD_SIZE - 1) + 1;
         if(board[x][y] == Spaces.Empty)
          { 
              board[x][y] = Spaces.Mine;
              mines--;
          }
      }while(mines &gt; 0); // set mines
      boolean gameOver = false;
  
      while(gameOver == false)
      {
          //Draw the board
          for (int y = 0; y &lt; board.length ; y++ ) 
          {
              for (int x = 0; x &lt; board[y].length ; x++ ) {
                  switch(board[x][y])
                  {
                  case Empty:
                      System.out.print("_");
                      break;
                  case Player:
                      System.out.print("X");
                      break;
                  case Mine:
                      System.out.print("!");
                      break;
                  case IceCream:
                      System.out.print("^");
                      break;
                  default:
                      System.out.print("?");
                  break;
                  }
              }
              System.out.println(" ");
          }
          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");
              System.exit(0);
          }
  
          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 &lt;-1 || dX&gt;1)
          {
              System.out.println("Invalid input X");
              dX = 0;
          }
          if(dY &lt;-1 || dY&gt;1)
          {
              System.out.println("Invalid input Y");
              dY = 0;
          }
  
          board[pX][pY] = Spaces.Empty;
          //Moves the player
          pX+=dX;
          pY+=dY;
  
          //Makes sure everything is still in bounds
          if(pX &lt; 0)
          {
              pX = 0;
          }
          else if(pX&gt;BOARD_SIZE-1)
          {
              pX = BOARD_SIZE-1;
          }
          if(pY &lt; 0)
          {
              pY = 0;
          }
          else if(pY&gt; BOARD_SIZE-1)
          {
              pY = BOARD_SIZE-1;
          }
          String again;
          if(board[pX][pY]==Spaces.Mine)
          {           
              System.out.println("Boom! Dead!");
              System.out.println("Would you like to play again? \"Yes\" or \"No\"");  
              again = keyboard.nextLine();
              if (again.equalsIgnoreCase("Yes"))
              {
                      gameOver = false;   
              }
              else if (again.equalsIgnoreCase("No"))
              {
                  System.out.println("Goodbye!");
                  System.exit(0); 
              }
          }
          if(board[pX][pY]==Spaces.IceCream)
          {
              System.out.println("You win!");
              System.out.println("Would you like to play again? \"Yes\" or \"No\"");
          }
          board[pX][pY] = Spaces.Player;  
      }   
  }}
  </code></pre>
  
  <p>Now what I need help on is the very bottom of the code where it says if player lands on mine and if player lands on ice cream.  I need it to loop once when the player lands on either of them and I need to ask the user to play again if they want to.  I'm not entirely sure which loop to do and am stuck on the part for replaying the game.  This is what it should read in the console if I landed on a mine</p>
  
  <blockquote>
    <p>Boom! Dead!
    Would you like to play again?</p>
  </blockquote>