Allan Didier

Battleship Adjustable

Goals

Create a more advanced Battleship game.

Skills

  • 2D Arrays
  • Algorithms

Program Details

Modify your Battleship game so that the board size, ship size, and number of guesses are determined by the player.

Your game needs to be designed with the following rules.

  1. Game Board Size
    1. Ask the user for the height and width of the board.
    2. Your code should be able to handle a non-square board.
    3. Because the console is limited in size, we will only test boards up to 20×20.
  2. Ship Size
    1. Let the user choose the size of the ship.
    2. Check to make sure the user does not choose a ship that won’t fit on the board.
  3. Ship Placement
    1. Placement of the ship should still be random. 
    2. Ship must be placed fully on the board.
    3. Allow for the ship to be placed diagonally.
    4. Hint:
      1. Choose a random X and Y position for ship (or the first square of the ship).
      2. Choose another random number for the direction of the ship (N, NE, E, SE, S,…)
      3. Check to make sure the ship will fit in the (X,Y) position and direction. If it doesn’t, choose a different position and/or direction.
  4. Guesses
    1. Let the user determine the number of guesses.
    2. Don’t let the number of guesses be more than the number of spots on the board.

Resources

Edhesive Term 1

Edhesive T1 Lesson 25: Algorithms

AP College Board 6.4: Algorithms using arrays