For the past couple of months, I’ve been learning how to code through Codecademy’s Computer Science 101 course path. For my final project in the “Intro to Programming” section, I was instructed to research, plan, build, use a git repository, commit changes, and write a blog about a fully functional python terminal game. For the first program in my coding career, I chose to make a game of battleship.
_
This game takes in the names of two players and decides who goes first through a game of heads or tails. The winner selects from a list of their available ships and places each one using the front and back coordinates. The program loops until the coordinates are given in the correct format, have a distance equal to the length of the selected ship, and are not already occupied by another. The player’s grid is updated and printed with the newly placed ship, prompts another selection, and repeats. After, the player is asked to confirm or relocate the original placements. If the player chooses to relocate a ship, the grid is updated accordingly, and the confirmation process repeats until all ships have been confirmed. The opposing player then follows the same procedures for setting up their fleet.
On each turn, a player is asked to select an enemy coordinate to fire upon, confirm that coordinate, and fire on command. A new grid is printed for the player with no ships displayed but informs the player of the results, marking an “X” for a hit or an “O” for a miss, along with a description of the move. Once all a player’s ships have been destroyed, the game is over, and the survivor is crowned the winner.
This project challenged me to deep dive into ‘while’ loops and eventually led me to place print statements after every function so I could understand what was happening and debug at one point. I also learned the use of input functions and cleaned up print statements by using f-strings.
I plan to continue with the CS 101 path, which includes data structures and algorithms next, and after, move to C++ and game dev. If you have the time, please feel free to review the game and provide any feedback or advice on improving the program, cleaning up the code, or anything else related. Thank you.
Top comments (0)