So I just wanted to get some opinions on the overall structure of a game I have to build for a programming class.
Essentially - I'm building two programs - a client and a server for a battleships game. I've already written the actual program which plays the battleships game. The program I've written is where a map and rules file is read in and the user tries to guess the location of the ships until they sink all of the ships.
For this new program - the server has to allow groups of two people to vs each other using the battleships game. Clients connect to the game using a game name, and once the game receives two clients, it can begin. We're required to use TCP on the local machine to communicate between server and clients, as well as threads in at least the server.
Here's what I was thinking..
Once a client joins - check which game they want to connect to. If it is a new game - create a new thread for that game and give the socket descriptor for the first client. Otherwise, if there is already one person in the game, alert the game thread of the new participant and it can start the game.
When a game is started - the game thread would have to spawn two more threads.. one instance of the battleship game for each player. The instance for each player will be where their ships are placed. The thread will then listen for input from each client in turn and pass that information onto the respective game.
Is this interpretation correct? That I'll need 3 threads per running game? And also, is it possible to use exec() in a thread to run a new battleships instance and then pass information to the stdin of that instance using threads (and get the stdout)?
Please let me know if I've been hazy on anything and I'll clarify. Thanks a lot in advance for any help!