DEV Community

sbhatia57
sbhatia57

Posted on

Battleship Terminal Game

Introduction:

For my CS101: Introduction to Programming Codecademy Computer Science Path Portfolio project I created a battleship terminal game. The game randomly generates the position of the opponent's 5 ships at the start of each game and allows the player to select a location in the 10x10 grid displayed to strike.

Image description

Program Description:

As mentioned above the program first places the opponent's five ships in random positions on the 10x10 grid.

Each ship is first randomly determined to be either vertically or horizontally placed on the grid and then the starting position (x, y) of the ship is repeatedly generated until the ship can be placed on the grid without overlapping with another ship.

Once all the opponent's ships are placed on the 10x10 grid the game loop begins. The player is shown an empty 10x10 grid displaying their hits (X) and misses (O) as well as some metrics describing the number of their hits, misses, number of missiles left, and the number of hits they need to win. The player is able to keep striking locations until they either sink all the opponent's ships (winning the game) or run out of missiles (losing the game).

Code:

https://github.com/sbhatia57/battleship.git

Conclusion:

I had a lot of fun working on this project and the resulting game is fun to play as well!

Top comments (0)