Welcome Guest, Not a member yet? Register   Sign In
What to use? Controller, Model or Library?
#1

[eluser]Peter Dräxler[/eluser]
Hello!

I'm programming browser game. When user click on quest I set timer for 5 minutes. When timer expires, I need to execute quest code (which will e.g. add user 10 of gold).

So the question is:
Where should be this code?

In my opinion, quest code should meet these:
- accessible from anywhere
- unaccessible for user
- method

Now, why not controller?
IMHO controller should handle user input and doesn't have to be accessible from anywhere.

Why not library?
IMHO library should be independent on project.

Why not model?
IMHO model should only mediate communication with source of data.

----------------

What's your opinion guys? How would you handle this?
#2

[eluser]TWP Marketing[/eluser]
Do a forum search on "base controller', and read Phil Sturgeons Base classes:
http://philsturgeon.co.uk/blog/2010/02/C...ing-it-DRY
#3

[eluser]pickupman[/eluser]
You will likely need to javascript as a timer to ping the server to let you know I am still active. Otherwise a user could click on the quest button and leave your site, but you have no way of knowing that. You would be adding gold to someone not even there.

And should likely call the model from your controller to update the user activity. Don't over think it when you are starting out.
#4

[eluser]Peter Dräxler[/eluser]
TWP Marketing: thank you for tip on great article, but this wasn't what I was looking for
pickupman: I'm sorry - I forgot to explain how quests will work. I want to user click on "do quest" and than leave page. When he open page again in 30 minutes, quest will be done. Bur your idea about quests is not bad. I will use it somewhere else, thanks.

Finally, after research I found that my logic about controllers was wrong. Model should handle all logic and controller should handle just user input and send data to view.




Theme © iAndrew 2016 - Forum software by © MyBB