1

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.

  1. Steal a bike
  2. Repair the bike
  3. 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.

  1. Bike has been stolen or not. If yes, Mark action to DONE
  2. Bike has been repaired or still damaged. If repaired, Mark Action DONE
  3. 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.

gung - Reinstate Monica
  • 11,583
  • 7
  • 60
  • 79
Asad kamran
  • 440
  • 10
  • 21
  • 1
    *On the ground is a pile of leaves. **>count leaves** There are 69,105 leaves here.* – rlemon Oct 19 '11 at 11:33
  • You might want to clarify what you have tried and where exactly your problems are in achieving your goal. – Gordon Oct 19 '11 at 11:42
  • 2
    Its a php mafia game, Here crimes, bike theft, car theft, Robbery, etc are possible (Note They all has corresponding tables that store users infor). I want to generate 5 task for users, Each task have a detailed description (in textual form) for users, what to achieve, but as a developer i have to store it all of 5 tasks in DB, as mension in question, each task consisted of 1 or more actions to do. I stored the tasks and Actions in table. But face difficulty in how to STORE ACTION(in which form to store actions, and how to validate. Thanks – Asad kamran Oct 19 '11 at 11:54

1 Answers1

1

A cheap way to do this would look like this:

tasks
{
    user_id
    has_theft_bike
    has_repaired_bike
    ... 
}

However, this is not easy to expand. A more correct way would be to define all actions in an actions table

 actions // defines all possible actions (also actions not part of a task)
 {
      action_id
      description
 }

 user_actions // has one record for every action a user commits
 {
      user_id
      action_id
      date // possible extra
 }

 tasks // all possible tasks
 {
     task_id
     name
 }

 task_actions // all actions linked to a task
 {
     task_id
     action_id
 }

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.

TFennis
  • 1,393
  • 1
  • 14
  • 23
  • Thanks for your help. I did not back to this as initial users comments break my hope for help. although i try to explain the full scenario. your distribution is correct and now i feel this was a better way. Any how, as the number of tasks are fixed (10 for this game) i implement whole logic in single page. Just storing tasks title , description etc. in TASK table. – Asad kamran Nov 17 '11 at 07:14
  • i store current_task in USERS table (default to ZERO as No task completed) and Set Task to 1 When he willing to perform and CHECK each task actions in a DECISION for current Task e.g If(users_task==1) { Logic for Checking all actions related to TASK 1}else if(users_task==2){ //TASK 2 Logic} and so on.... Thank you for you help. – Asad kamran Nov 17 '11 at 07:15
  • Is this maintainable in the long run? Let's say , 400 000 users – John Mar 03 '13 at 19:00