I'm just getting started, but here's how I'd do it.
The general flow would be like this.
At the beginning of the state, on the server side, you will need to figure out what actions are possible for the player.
In the server side arguments function for the state, send the list of what is possible now in args.
In onUpdateActionButtons on the client, you can use args values to set the action buttons correctly.
When the player clicks on an action button, your onAction event function can send an ajax call for that action.
In the server side action php, you map the onAction ajax call to an action function onAction in game.php.
In the server side game action function you take the action, then adjust the database to show the action is already taken, then restart the action state.
I'd start with the state table.
(game) state 20 start player turn, reset all actions to "not taken", enter state 21
(activeplayer) state 21 player turn, check what actions are not taken
if all actions are taken, you can end turn by going to state 22
otherwise send actions list to client, show the right buttons
As player takes each action, set the action as "taken", then enter state 21 again
state 22 end player turn
I'd define some utility functions:
Code: Select all
setAllActionsAvailable() {...}
setActionTaken( action ) {...}
anyActionsAvailable() {...}
getActionsAvailable() {...}
There are lots of database table designs that could handle this. Here's one idea. You could have a table like this:
Code: Select all
...
player_id int(10)
name varchar(20)
taken tinyint(1)
...
When you set up the game, you'd create the table with all the possible actions for each player.
Once you have the table layout, writing the above functions would not be difficult, and using them makes your code readable. For example:
Code: Select all
function setActionTaken( $action ) {
$active_player_id = self::getActivePlayerId();
$sql = "update actions_table set taken = 1 where player_id = '$active_player_id' and name = '$action'";
self::DbQuery($sql);
}
Best wishes, Brian