简体   繁体   中英

How to check whether the user completed their missions?

I am working on a coding/gaming application. I am currently stuck in the daily missions part.

So, the user receives some missions each day, such as solving a problem, following another user, or completing a quiz that, they have to complete.

The problem is, I didn't know how to listen for mission completion? How will I know whether the user completed their missions or not ?

Here's a solution I thought of, however, I highly doubt that it is good:

Every time the user completes a certain task, I check whether they had that task as a daily mission. If positive, I'll mark that mission as complete.

Something like:

onProblemSolve(){
   const missions = this.currentUser.getMissions();
   if(missions.contains('problemSolving')) {
       this.markMissionAsComplete();
   }
}

I asked the same question on https://gamedev.stackexchange.com/ and I received an answer that clarified things, here's the link to the question: https://gamedev.stackexchange.com/questions/194823/how-to-check-whether-the-user-completed-their-missions

here's their answer: Instead of checking if a puzzle is part of a daily quest, you could fire an event once the puzzle is done. Your daily quests can listen to this event and if there is a quest that involves solving a puzzle, you mark it done. This has a few benefits. You can have an achievement system next to your daily quests and do not need to do much more code changes. If you have the logic on the puzzles side (as your snippet), you would have the same code again to mark an achievement. But if your achievement system just listens on puzzle done, nothing needs to change on the puzzle part. Why would your puzzle even care, if it is needed for a daily quest or achievement?

As a fallback, you should not only count on the event but involve your database as well. That does not mean that every event should write itself to it. Things like puzzle done would probably not only write "Level xy done" but when exactly with some extra stats like how many tries, time, hints, points and whatever your game offers. When you start your game, you can do a query for things like "has x puzzle done today". You do not want to call your database with this the whole time for performance reasons, but once at startup could be fine (or when loading your quest menu).

the Observer Pattern is your friend. There is always more than one way how you can do something but for most things, someone did it already and there is a pattern for it.

here's an interesting article: https://www.gameprogrammingpatterns.com/observer.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM