DEV Community

Cover image for Battleship!
Nathan Cook
Nathan Cook

Posted on

Battleship!

Hello everyone! This is my first venture into making a terminal game. It's a simple battleship game. While there is still room to add more functionality and make it more aesthetically pleasing, I am happy with how it turned out.
Each player is a class. Using the input function, each player is prompted to pick a size, latitude, and longitudinal starting point for their battleship. After each player inputs their numbers, a function is called which creates a list of tuples, which act as coordinates, for each players' ship.
Next the players are prompted to enter a latitude and longitude to guess their opponent's coordinates. If the latitude and longitude is a tuple in their opponent's coordinate list, then that tuple is popped out of the list, and the text, "You hit my battleship!" is displayed. If it is not a tuple in the list, "miss" is passed to the terminal screen. And, if the length of the list is 0 after "hitting" a coordinate, "You sunk my battleship!" is printed, and the game is over. Here is a link to the code on github:
https://github.com/724nathanco/Battleship/blob/main/Fuckyou.py
Check it out, and give it a try! In the future, I may try to add the option to add more ships.

P.S. Sorry for the vulgar file name. I had created the file as battleship.py, but somehow all the contents were erased after I had finished it. So, I had to do it all over again, and I was pretty upset.

Top comments (1)

Collapse
 
724nathanco profile image
Nathan Cook

github.com/724nathanco/Battleship.git

Hmm, looks like that link isn't working. Try this one.