[web] Quiz game

Started by
-1 comments, last by newBe 12 years, 5 months ago
Hello

I am working on a game for my classess so i decided to create a quiz game first i created a quiz game with only text and random answers, and chooseing the correct answer with mouse, to this point it was working,
after that i created some sounds with body of question and answers in mp3. After adding it to the game code, and changing the stering from mouse to keyboard the problem started, the answer i choose and is correct is not, also at this point i added option that after selecting the answer, the game is automaticaly reading the correct answer and is marking it. After all that the game is showing the next question and so on. i will paste the part of code that is responsible for showing and choseing the correct answer:

the one ,two, three are variables for presed buttons


function showQuestion():void
{
if(Index==quest.length)
{
gotoAndPlay(3)
}
rand = Math.ceil(Math.random()*3);
Que.text = quest[Index];
var mySoundQuestion = sndq[Index];
mySoundQ.load(new URLRequest(mySoundQuestion));
mySCQ = mySoundQ.play();
mySCQ.addEventListener(Event.SOUND_COMPLETE, showAnswer1);
}
//showQuestion();

function showAnswer1(event:Event):void
{
if(rand == 1)
{
O1_txt.text = answ[Index][0];
var mySoundAns1 = snd[Index][0];
mySoundA1.load(new URLRequest(mySoundAns1));
mySCA1 = mySoundA1.play();
mySCA1.addEventListener(Event.SOUND_COMPLETE, showAnswer2);
}
if(rand ==2)
{
O1_txt.text = answ[Index][1];
mySoundAns1 = snd[Index][1];
mySoundA1.load(new URLRequest(mySoundAns1));
mySCA1 = mySoundA1.play();
mySCA1.addEventListener(Event.SOUND_COMPLETE, showAnswer2);
}
if(rand == 3)
{
O1_txt.text = answ[Index][2];
mySoundAns1 = snd[Index][2];
mySoundA1.load(new URLRequest(mySoundAns1));
mySCA1 = mySoundA1.play();
mySCA1.addEventListener(Event.SOUND_COMPLETE, showAnswer2);
}
}

function showAnswer2(event:Event):void
{
if(rand == 1)
{
O2_txt.text = answ[Index][1];
var mySoundAns2 = snd[Index][1];
mySoundA2.load(new URLRequest(mySoundAns2));
mySCA2 = mySoundA2.play();
mySCA2.addEventListener(Event.SOUND_COMPLETE, showAnswer3);
}
if(rand == 2)
{
O2_txt.text = answ[Index][2];
mySoundAns2 = snd[Index][2];
mySoundA2.load(new URLRequest(mySoundAns2));
mySCA2 = mySoundA2.play();
mySCA2.addEventListener(Event.SOUND_COMPLETE, showAnswer3);
}
if(rand == 3)
{
O2_txt.text = answ[Index][0];
mySoundAns2 = snd[Index][0];
mySoundA2.load(new URLRequest(mySoundAns2));
mySCA2 = mySoundA2.play();
mySCA2.addEventListener(Event.SOUND_COMPLETE, showAnswer3);
}
}

function showAnswer3(event:Event):void
{
if(rand == 1)
{
O3_txt.text = answ[Index][2];
var mySoundAns3 = snd[Index][2];
mySoundA3.load(new URLRequest(mySoundAns3));
mySCA3 = mySoundA3.play();
mySCA3.addEventListener(Event.SOUND_COMPLETE, nextAction);
}
if(rand == 2)
{
O3_txt.text = answ[Index][0];
mySoundAns3 = snd[Index][0];
mySoundA3.load(new URLRequest(mySoundAns3));
mySCA3 = mySoundA3.play();
mySCA3.addEventListener(Event.SOUND_COMPLETE, nextAction);
}
if(rand == 3)
{
O3_txt.text = answ[Index][1];
mySoundAns3 = snd[Index][1];
mySoundA3.load(new URLRequest(mySoundAns3));
mySCA3 = mySoundA3.play();
mySCA3.addEventListener(Event.SOUND_COMPLETE, nextAction);
}
}


function nextAction(event:Event)
{
clock.start();
chanREQ1 = clockSound.play();
field1.buttonMode = true;
field2.buttonMode = true;
field3.buttonMode = true;
//stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
stage.focus = field1;
stage.focus = field2;
stage.focus = field3;
field1.addEventListener(Event.ENTER_FRAME, action1);
field2.addEventListener(Event.ENTER_FRAME, action2);
field3.addEventListener(Event.ENTER_FRAME, action3);
}


function action1(event:Event)
{
if((one) && (rand==1))
{
one = false;
scoreInc()
stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
chanAns = corAns.play();
chanAns.addEventListener(Event.SOUND_COMPLETE, onShowPlayCorrAns);
}
else if((two)&& (rand==1))
{
two = false;
decreaseEnergy()
stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
chanAns = corAns.play();
chanAns.addEventListener(Event.SOUND_COMPLETE, onShowPlayCorrAns);
}
else if((three) && (rand==1))
{
three = false;
stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
decreaseEnergy()
chanAns = corAns.play();
chanAns.addEventListener(Event.SOUND_COMPLETE, onShowPlayCorrAns);
}
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
}

function action2(event:Event)
{
if((two) && (rand==2))
{
scoreInc()
two = false;
stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
chanAns = corAns.play();
chanAns.addEventListener(Event.SOUND_COMPLETE, onShowPlayCorrAns);
}
else if((one)&& (rand ==2))
{
one = false;
decreaseEnergy()
stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
chanAns = corAns.play();
chanAns.addEventListener(Event.SOUND_COMPLETE, onShowPlayCorrAns);
}
else if((three) && (rand ==2))
{
three = false;
stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
decreaseEnergy()
chanAns = corAns.play();
chanAns.addEventListener(Event.SOUND_COMPLETE, onShowPlayCorrAns);
}
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
}

function action3(event:Event)
{
if((three) && (rand==3))
{
scoreInc()
three = false;
stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
chanAns = corAns.play();
chanAns.addEventListener(Event.SOUND_COMPLETE, onShowPlayCorrAns);
}
else if((two)&& (rand ==3))
{
decreaseEnergy()
two = false;
stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
chanAns = corAns.play();
chanAns.addEventListener(Event.SOUND_COMPLETE, onShowPlayCorrAns);
}
else if((one) && (rand ==3))
{
decreaseEnergy()
one = false;
stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
chanAns = corAns.play();
chanAns.addEventListener(Event.SOUND_COMPLETE, onShowPlayCorrAns);
}
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
}

function onShowPlayCorrAns(event:Event):void
{
if(rand==1)
{
markCorectAnswer1()
}
if(rand==2){
markCorectAnswer2()
}
if(rand==3)
{
markCorectAnswer3()
}
clock.addEventListener(TimerEvent.TIMER_COMPLETE, endQ);
}

function markCorectAnswer1():void
{
mySCA1 = mySoundA1.play();
tick.visible=true;
tick.y=field1.y
}
function markCorectAnswer2():void
{
mySCA2 = mySoundA2.play();
tick.visible=true;
tick.y=field2.y
}
function markCorectAnswer3():void
{
if((three) && (rand==3))
mySCA3 = mySoundA3.play();
tick.visible=true;
tick.y=field3.y
}

This topic is closed to new replies.

Advertisement