cvp
Sure, lets start with the server. All the game logic (e.g. shuffling the deck, determining who wins, adjusting scores, etc) is scripted using PHP . When a player makes a decision that changes the status of the game, such as passing his/her turn, or playing a hand, the data is sent via ajax request. The ajax identifies the table number, the seat number that made the change, the type of change, and what the actual change is. Based on that info, the PHP program updates the game info on my server. The PHP script is quite large as it covers every possible process in the game. I think it ended up being around 500 lines of code.
Now for the client. Every second, the client sends an ajax request to a php page that pulls the game's current info from the server using a SQL query. Based on the data, the client updates whose turn it is, what cards have been played, current scores, etc.
This SQL table contains ALL the important game info. The only data saved on the clients local machine is relevant to presenting data from the server.
The process of sitting at a table, and playing a round goes something like this:
- A player signs in with their name, which is temporarily saved client-side
- The player goes to the lobby, and an ajax request pulls the current players at each table.
- When the player joins an empty seat at a table, ajax sends the username to the server to update the table occupants.
- When the 3rd person joins the table, the php program runs to shuffle the deck, randomly assign deal, and other game-setup processes, and the appropriate data is saved on the server.
- The client sees that a new hand has been dealt based on changes in the gamedata pulled from the server.
- If it's your turn, you will be given options for playing a hand, passing, and other things you can to do affect the game.
- Once you've made your turn, an ajax request pushes the changes to the php program that updates the appropriate game data on the server.
- The next player plays their turn... which again updates the appropriate data using an ajax request to a php program.
- The same process of someone playing their turn, and updating the server continues until the program realizes that one player doesn't have any cards.
- The round ends, the program adjusts the scores, and then restarts the process by shuffling the deck, and assigning the first turn, etc.
This method works quite nicely since Triad is a turn based game. Ajax requests would not be suitable to active multiplayer games.
I hope this helps.