I am developing a php text based game. I am organizing tasks in games. Basically tasks increase the understanding of the game.
A task is a group of small actions in the game.
For example:
TASK Description: You are required to steal a bike, repair it and ship to another city.
It includes 3 actions.
- Steal a bike
- Repair the bike
- Ship it to another city (let say London)
These 3 actions are possible at single of different pages.
I created a table for TASK(task_id, title, description (TASK Description Above),STATUS), but I'm not sure how to store and execute actions of task.
I have one idea, to use a related table TASK_ACTIONS (task_id, action_id,action(?),done)
But I'm not sure in which form to store actions action(?):
An sql statement to check for actions Like following three points.
- Bike has been stolen or not. If yes, Mark action to DONE
- Bike has been repaired or still damaged. If repaired, Mark Action DONE
- Bike has been shipped to London or not. If shipped, Mark Action DONE
If all above marked DONE then mark TASK STATUS as COMPLETED, show next task.
A cheap way to do this would look like this:
However, this is not easy to expand. A more correct way would be to define all actions in an actions table
This way you log every action a user does. You could make a steal bike action and a repair bike action.
Now you can for instance retrieve all actions you need to complete task 5 (steal a bike and repair it). Then if all those action id's are in the user_actions table for your current user. it means the user has completed the task.
Just not that your user_actions table will grow really really really fast if you have a couple of users.