lundi 28 septembre 2015

Scoring system not working AS3

it's me again, I've finnaly made the math generator to work and see if the answer is correct or incorrect ("horray!") but, this is programming, and another error apeared ("darnit..."). so I added a scoring system and at the first correct answer it gives me 1 point but at the second correct answer it doesn't give me another point, it stays at 1 point :(. Also, is there a way to block the "verificar" button until the "startButton" button is pressed? (so people that try my math generator don't cheat!) Thank you very much for your help!

import flash.utils.Timer;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
stop()
var reloj:Timer = new Timer(1000,60);
startButton.addEventListener(MouseEvent.CLICK, startTimer);
reloj.addEventListener(TimerEvent.TIMER, moveHand);
reloj.addEventListener(TimerEvent.TIMER_COMPLETE, endTimer);
function startTimer(e:MouseEvent):void
{
        reloj.start();
        startButton.visible = false;
}
function moveHand(e:TimerEvent):void
{
        segundero.rotation = segundero.rotation + 6
}
function endTimer(e:TimerEvent):void
{
        trace("Se agotó el tiempo");
        gotoAndPlay (1, "1");
}
nuevo.addEventListener(MouseEvent.CLICK, generarPregunta);
function generarPregunta(MouseEvent):void
{
        var random1:Number = Math.floor(Math.random()*25)
        var random2:Number = Math.floor(Math.random()*25)
        var array:Array = new Array ("+","-","*","/")
        var randomIndex:int = Math.floor (Math.random()*4)
        SimbMat.text = array [ randomIndex ]
        numI.text = random1 + ""
        numD.text = random2 + ""
}

verificar.addEventListener(MouseEvent.CLICK, verificarRespuesta);
function verificarRespuesta(MouseEvent):void
{
    var puntaje:int = 0
        if (String(SimbMat.text) == "+")
        {
                if (Number(numI.text) + Number(numD.text) == Number(imput.text))
                    {
                                trace("correcto")
                                puntaje++;
                                updateScore();
                                generarPregunta(MouseEvent);
                        }
                else
                {trace("incorrecto")}
        }
        else if (String(SimbMat.text) == "-")
        {
                if (Number(numI.text) - Number(numD.text) == Number(imput.text))
                {
                        trace("correcto")
                        puntaje++;
                        updateScore();
                        generarPregunta(MouseEvent);
                }
                else
                {trace("incorrecto")}
        }
        else if (String(SimbMat.text) == "*")
        {
                if (Number(numI.text) * Number(numD.text) == Number(imput.text))
                {
                        trace("correcto")
                        puntaje++;
                        updateScore();
                        generarPregunta(MouseEvent);
                }
                else
                {trace("incorrecto")}
        }
        else if (String(SimbMat.text) == "/")
        {
                if (Number(numI.text) / Number(numD.text) == Number(imput.text))
                {
                        trace("correcto")
                        puntaje++;
                        updateScore();
                        generarPregunta(MouseEvent);
                }
                else
                {trace("incorrecto")}
        }
                
        function updateScore() :void
{
        score.text = "Puntaje: " + puntaje;
}
}

Aucun commentaire:

Enregistrer un commentaire