RakNet Bingo
2020
#C++ #RakNet #Networking #VisualStudio
This is a command line networked client-server Bingo game developed using C++ and RakNet in Visual Studio.
The server is responsible for generating Bingo Cards for all connected player clients, and drawing numbers until there is a winner.
Program Flow
When the game starts, the server caches all of the guids of clients currently connected, and uses them as the players. This means that a client joining in the middle of the game will have to wait until the next game to play. At this point, the server generates a unique game card with 9 numbers for each client, and sends the numbers through a custom message. Upon receiving their message, each client parses the number message and fills their bingo card with their numbers. Then the server will draw a random number between 10 and 99 every 100ms, and send that number to each client through a custom message. Upon receipt, each client will check if it's on their card and mark it with an 'O' if it is. A client will print its board whenever it is marked by a matching number. If a client's card is completely marked, it will send a custom BINGO! message to the server, at which point the server will send a custom message to all clients saying that there is a winner and that the game has ended.
Architecture
The main function creates a BingoGame instance, which creates a derived BingoPlayer that is either a BingoClient or BingoServer, depending on the command line argument. The RakNetController is also instantiated, which the BingoPlayer has a reference to. Each BingoPlayer has an update function that is called repeatedly in the BingoGame's game loop. The update function is where the client or server processes newly received messages and sends any messages it needs to send. Default messages are processed in the RakNetController, while each custom message (those specific to the Bingo Game) are processed in the player's processMessage function. The BingoClient has a bingoBoard, which can be filled, printed, and marked.