The first step in my exploration was how to keep track of each player. Normally with a multiplayer game, the client is connected to the server for the duration of the game, meaning that the server can assign an identifier to that client connection. With a non-continuous connection, I needed to create a way to identify a player between sessions. I decided that creating a simple account and login system would be the best.
I won't go into the details of the login system, as that is not the focus of the project.
Once a player is logged in the client polls the REST API for the current game state with a GET, which is output in XML format.
while($row = mysqli_fetch_array($result)) { //XML format info about player echo " <playerpos> <char>".$row['name']."</char> <x>".$row['x']."</x> <y>".$row['y']."</y> <class>".$row['class']."</class> <health>".$row['health']."</health> </playerpos>"; }With the game state, the client assembles the game world and displays it to the player. Part of the game state information is also the current players turn. When the player makes their move, the client sends a POST to the server with their move, which is dealt with server side to determine the new game state.
This method doesn't rely on players being connected simultaneously and allows for larger scalability of a game session, since the server isn't managing a large number of simultaneous connections.
You can check out the simple game here.
No comments:
Post a Comment