Jump to content
  • Advertisement
Sign in to follow this  
newBe

[web] Quiz game

This topic is 2484 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!