This project was assigned to me in a codecademy course, i had to pick what game i wanted to recreate or create in a terminal. I just thought that batlleship was the perfect game, something fun and that can be made a little complex at least for a beginner like me.
The code consist of a Player Class that creates the playing board and the attacking board. 10x10 both obviously. A string method to represent the board in a cool looking way. A place ships method that make sure every player position it ships in an available and possible location without collisioning.
And lastly and attack method. You know what that does LOL!.
We have dictionaries with list or tuples, to represent the status of each part of the ship, the key being the ship and the value a list of the respective point of the chip, for example Destroyer has a length of 2 so a list of lenght two. And a tuple to represent what position the ship was hit.
The game loop basically makes sure every player position their ships, that the inputs are okay and thats it. Sounds simple saying it lol, but wasnt for me!!!
Github:
https://github.com/charlesdmg-hash/battleship-terminal-game
This was a challenge for me but im very proud of the outcome and what i learned. For sure in the future will polish this project with IA or something like that.
Top comments (0)