Question

I'm creating a Flash (as3) quiz that utilizes PHP data and am currently in the midst of creating a score system. The idea is the faster you get a question correct, the higher your score. There is a countdown timer running down from 5 seconds for each question. So for example, if you answer the question in 5 seconds and it is correct you will get 500 points, 4 seconds = 400 points and so on. It's a multiple choice quiz and answers appear in a dynamic text field in buttons.

At the moment I have an embedded quiz with questions and answers stored in an array so I can test everything out before fully integrating my PHP.

Does anyone have any ideas where to start? Any feedback or nudge in the right direction would be greatly appreciated! If you need any more info (or script) please let me know.

Thanks

Was it helpful?

Solution

Sound like a Timer would do exactly what you're looking for.

Setup a global timer var with an interval that depends on how precise you want your scoring system to be, and fire it up with every new question. When the user answers, check the repeatCount of that timer to see how long it took them to answer properly.

public class Quiz{
    private var mTimer:Timer;

    ...

    public function Quiz():void{
         // This creates a timer that will fire every 100 ms for 50 times.
         // If you want a more precise scoring system, reduce the delay, and increase the count
         mTimer = new Timer(100, 50);
    }

    private function newQuestion():void{
         // Don't forget to reset the timer for every new question
         mTimer.reset();
         mTimer.start();
    }

    private function onRightAnswer():void{
         // Check how many times the timer fired already
         var count:int = mTimer.currentCount;

         // Deduce points for every count
         var score:int = 500 - (count * 10);
    }

    ...

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top