If statements with timers
i creating trivia game if answer question in x seconds give more points. struggling part.. @ moment code basic , not game test run.
package {
import flash.display.movieclip;
import flash.utils.timer;
import flash.events.timerevent;
import flash.events.mouseevent;
public class timers extends movieclip {
public var time:timer = new timer(4000);
public var timer:timer = new timer(16500);
public function timers() {
// constructor code
timer.addeventlistener(timerevent.timer, completed);
timer.start();
wrong.addeventlistener(mouseevent.click, wronganswer);
right.addeventlistener(mouseevent.click, rightanswer);
}
public function wronganswer(e:mouseevent):void{
trace(-50);
timer.stop();
}
public function completed(t:timerevent):void{
timer.stop();
trace(-100)
}
}
public function rightanswer(e:mouseevent):void{
if (right answer selected within 8 seconds)//this trying for
{
trace("100");
//timer.stop();
}
else {
trace("-50");
//timer.stop();
}
}
}
anyone have suggestions if/else statements.
// points if answered before timeformaxpoints
var maxpoints:int = 10;
// points if answered before timeforminpoints. after timeforminpoints, no points.
var minpoints:int = 5;
// both times in seconds
var timeformaxpoints:int = 3;
var timeforminpoints:int = 10;
var t:timer=new timer(1000,timeforminpoints+1);
t.addeventlistener(timerevent.timer,timerf);
var points:number;
var totalpoints:int;
function nextquestionf():void{
// present question
points=maxpoints;
t.reset();
t.start();
}
function timerf(e:timerevent):void{
if(t.currentcount>timeformaxpoints){
points-=(maxpoints-minpoints)/(timeformaxpoints-timeforminpoints);
}
if(t.currentcount==repeatcount){
points=0;
}
}
function answerf():void{
t.stop();
// if correct,
totalpoints+=math.floor(points);
// if incorrect, i'm not sure want totalpoints, if anything.
}
More discussions in ActionScript 3
adobe
Comments
Post a Comment