Battleship


#1

hi :slight_smile: I want to code a battleship game with user graphical interface, iam new to coding and it not clear for me if I have to use tkinter or pygame, any tips ll be appreciated and thanks a lot in advance :slight_smile:
best regards


#2

Go with pygame, a reasonable approach would be to have a grid where you draw sprites on each square to match the state, for example you might have a sprite for water, one for water that has been shot at but is empty, one for water that has been hit (but the ship is still unknown), a couple sprites for parts of ships in their intact/hit states

Oh and keep the gui stuff separate from the game logic. The gui should be calling functions/methods when input happens, and request game state which it then uses to figure out what to draw.


#3

This is going to end up being more work than you think.
It’s important to draw out the logic of the game.
As @ionatan said forget the gui for now and build the logic . Do it in small modular bits. Do something small like a display_board() function then test it extensively.
The game of battleship itself can be broken down into a few short loops. The logic behind those methods can get tricky.
Things you really need to test a lot, ship placement, cpu torpedo logic.

This isn’t to discourage you, battleship is an excellent project.
Just remember
1.) Have a plan (written/drawn)
2.) outline your code
3.) code small bits
4.)evaluate and test that small bit extensively
5.) Combine your small bits


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.