This example can be as simple or as complicated as you like. Simple first is better because then someone else can build on your example and add more features.
More implementation instructions will be added on request!
The Game
Battleship is a two player game played on a 10x10 grid. There are 5 ships with lengths: 2, 3, 4, 5, 5
Each of these steps would be an excellent PR on its own but you can combine multiple steps if you want to.
1. Rendering the battleship grid
This may be blocked on rendering text but can be done without it since text can be added later too.
In this step, just draw the basic battleship grid for one player. (picture is above.) The drawing can be just a simple 10x10 grid with some different fill colors for things like the grid tiles, ship tiles, etc. An appropriate struct for the battleship board and ships will need to be created.
Only draw one player's board since showing both player's ships would defeat the purpose of the game. You will need a lower board for the player's ships and an upper board to keep track of where that player has guessed. We want to replicate the game as closely as possible.
Structure the board drawing so we don't need to redraw it every time something happens. We want to be able to "add" more to the drawing as the game progresses, not reset and redraw every time.
2. Commands for Attack + Turns
Create a loop where we will continuously collect input and then update the board shown on the screen. This is where the rules of the game will start to be implemented.
Before the loop, draw the board using the function implemented in part 1. Then, using the terminal as your way of collecting input, have the player enter a tile they would like to try and bomb. Make sure this tile is not a tile that the player has picked before. Draw something different depending on whether the bomb hit an opponent's ship or not.
For the opponent's moves, generate a random move using the random utilities provided in the turtle crate.
More implementation instructions will be added on request!
3. Single Player Mode (optional)
The game should now be playable by a single person on one computer. The opponent currently plays randomly. Try to make the opponent make better, more systematic guesses.
More implementation instructions will be added on request!
4. Multiplayer Mode P2P
This step can be as simple or as complicated as you want. It's an excellent way to learn about sockets, basic networking, servers and clients. The basic idea is that you want to enable people to play the game with each other. You could have them provide their IP addresses to each other so they can connect directly or you could figure out how to host and provide a server for them to connect to in order to find each other.
More implementation instructions will be added on request!
5. Advanced Controls
Using the poll_event() method on turtle, implement arrow keys and enter based controls. You could move the turtle with the pen up as an indicator of what is being selected. This would be really interesting to implement!
This example can be as simple or as complicated as you like. Simple first is better because then someone else can build on your example and add more features.
More implementation instructions will be added on request!
The Game
Battleship is a two player game played on a 10x10 grid. There are 5 ships with lengths: 2, 3, 4, 5, 5
Rules: https://www.thespruce.com/the-basic-rules-of-battleship-411069
Suggested Implementation Steps
Each of these steps would be an excellent PR on its own but you can combine multiple steps if you want to.
1. Rendering the battleship grid
This may be blocked on rendering text but can be done without it since text can be added later too.
In this step, just draw the basic battleship grid for one player. (picture is above.) The drawing can be just a simple 10x10 grid with some different fill colors for things like the grid tiles, ship tiles, etc. An appropriate struct for the battleship board and ships will need to be created.
Only draw one player's board since showing both player's ships would defeat the purpose of the game. You will need a lower board for the player's ships and an upper board to keep track of where that player has guessed. We want to replicate the game as closely as possible.
Structure the board drawing so we don't need to redraw it every time something happens. We want to be able to "add" more to the drawing as the game progresses, not reset and redraw every time.
2. Commands for Attack + Turns
Create a loop where we will continuously collect input and then update the board shown on the screen. This is where the rules of the game will start to be implemented.
Before the loop, draw the board using the function implemented in part 1. Then, using the terminal as your way of collecting input, have the player enter a tile they would like to try and bomb. Make sure this tile is not a tile that the player has picked before. Draw something different depending on whether the bomb hit an opponent's ship or not.
For the opponent's moves, generate a random move using the random utilities provided in the turtle crate.
More implementation instructions will be added on request!
3. Single Player Mode (optional)
The game should now be playable by a single person on one computer. The opponent currently plays randomly. Try to make the opponent make better, more systematic guesses.
More implementation instructions will be added on request!
4. Multiplayer Mode P2P
This step can be as simple or as complicated as you want. It's an excellent way to learn about sockets, basic networking, servers and clients. The basic idea is that you want to enable people to play the game with each other. You could have them provide their IP addresses to each other so they can connect directly or you could figure out how to host and provide a server for them to connect to in order to find each other.
More implementation instructions will be added on request!
5. Advanced Controls
Using the
poll_event()
method on turtle, implement arrow keys and enter based controls. You could move the turtle with the pen up as an indicator of what is being selected. This would be really interesting to implement!