6.2 KiB
Battleship game
- This is a game suite. It includes a server and a CLI client. Both are built in C++.
- One server instance can serve multiple games at the same time.
- The goal of the game is to destroy all of your opponent(s) ships, while still keeping at least one of your own ship alive
- The start doesn't have to be balanced - ships might differ between players from the start.
- At the start of each game, one must define the size of the map and the ships available to the players.
- The game will be developed in phases.
- One player sets the game up. Other players can join
- Turn-based game
Phase 1 - Proof of Concept (POC)
- server + client cli
- simplified version, with exactly 2 players, and static ships. All ships have a width of 1. 1 < length < 7
Gameplay
- setting up the game: one player creates a new game. Sets up the size of the map, and which ships are available to each player
- once the map is set up, the first player can join the game.
- other players can also join.
- when joining for the first time, each player must set up their ships - place them on the map, and rotate them per wish
- ships always rotate on their middle point.
- Rotation: If their length is even, rotate on length/2. if it's odd, rotate on length/2+1.
- each turn, the player can only specify the coordinates. Like (x=12, y=64).
- the player will learn if they hit or miss.
- once the player has no more
Server
- new game instances are created through the client CLI
- when game is created, return a game id for the first player, and the cli sends the join command
- when a new cli is started, for a new player to join, they get to choose between existing games, or create a new one
- spawn a thread for each game instance
- when a new client joins, they join that specific thread. A thread ID must be shared with all the customer CLIs.
- keep the map and ships in memory
- the main process handles all connections. Each message it receives contains the thread ID, so that it knows which game it is for
- receiving a bombing location, the server must communicate this with the correct thread. The thread returns hit or miss.
- the main process uses some form of efficient interprocess communication to communicate with the child thread
The Game thread
- each game is handled by its own thread.
- each thread keeps the game's map in memory, each game owning a different map
- when the bombing command is received, the thread will mark the bombing, and will return whether it's a hit or a miss
- the main server must ensure sending this information back to the customer
Serialization
- all commands must be binary serialized. This is a very efficient game, and communication with the server must be minimal
- sample bombing object: game id, player id, coordinates (x, y)
- sample return object: game id, player id, coordinates (x, y), hit/miss
CLI
- the cli constantly shows the map of the game
- asks the user for coordinates
- if they get hit on the other player's turn, the CLI must show this visually
- initially the map only shows own units, and empty water all around
- Characters for drawing: use '~' for empty waters. '||','=', '^', '>', '<' and 'v' for ship drawing. Example: <====> ^
v
- use 'x' for hit regions. example <==x> for a hit on the second position in a 5-length ship
Phase 2
Movement
Each ship can move. Each ship has a speed. Smaller ships are faster. Larger ships are slower. Speed is measured in squares per turn. Highest speed is 1. Movement happens at the end of the turn. On their turn, each player decides if they keep their ships' current movement trajectory, or change it. Example: if a ship is moving towards the west, and the user likes it that way, the user doesn't have to do anything. If they want to stop the ship, or change course, they need to mention it in the movement instructions. These are all passed to the server.
Example movement object game id, player id, ship id, type: set course (w/e/n/s,stop) return - confirmation
Ammunition
Each ship has infinite ammo of one single type on deck. each ammo type has various damage when a ship sinks, all its ammo is no longer usable. On a turn, each user can use only 1 ship to fire at the opponent.
Phase 3
New unit types
- air
- submarine
- radar
Bases
- a ship must return to base for various needs like refueling, resupplying or ammo
- Bases also fix ships
- the fix of a ship is to 100% and just takes one turn
- the base must be visible on the map
Multi-ammo ships
- each ship can carry various types of ammo. There are constraints, certain ammo can only be carried by certain ships
- ammo is limited
- once the ammo is out, the ship must return to its base to get more ammo.
Resources
- special ships can be set up to mine for resources like oil
Research
- research can be performed to invent new ammo types
- radars can also be researched
Radars
- each time a new radar is used, it shows a new portion of the map
- the radar has a physical location, so must be placed on the map. It will always display the area around it, 5 squares in each direction
- once a radar is placed, it will keep showing that area until it is destroyed, or the game ends
- a radar can be destroyed if a ship hits it, just like a regular ship
- cannot see submarines
- can see air ships
Submarines
- require air surveillance to be discovered
- special ammo can take them down - torpedoes
- can hit any ship or submarine
- can see any ship or submarine
- can't hit or see air ships
New ammo
- anti-air - can take down any air ship (plane / helicopter) in one single hit
- torpedo - can take down any submarine in one single hit
Phase 4
Time to build other clients
- web
- local/native
Carrier
- new type of unit
- can carry drones, planes, helicopters
- is large
- has own radar
Air unit - reconnaissance plane
- used just for discovery
- can find ships or submarines
- move very fast
- can only see 4 squares around them
- once they pass, they can no longer see the ships in the places it left
- large range
Air unit - reconnaissance helicopter
- similar to radar, but has smaller radius
- can see any ship or submarine
- does not make damage
- small range
Air unit - attack plane
- very fast
- can attack any kind of ship - air, water, underwater
- short range