Home > OS >  Two player check socre and show result (who won lost or tie) AS3
Two player check socre and show result (who won lost or tie) AS3

Time:09-17

please help me

I am trying to make a two-player game and facing an issue with the result page I need to show on the result page who won lost or if tie

here is my flash file https://drive.google.com/file/d/1wGQh1UXlsQXQT1ofyubljxgWQJelB7GE/view?usp=sharing

    stop();

//for tow players
var p_1_scoreCount:Number = 0;
var p_2_scoreCount:Number = 0;
stage.addEventListener(KeyboardEvent.KEY_UP, detectKey);  

function detectKey(event:KeyboardEvent):void {

// player 1 keyboard kye A
if (event.keyCode == 65){
  p_1_scoreCount  = 1;
  p_1_score.text = String(p_1_scoreCount);
}
// player 2 keyboard kye B
if (event.keyCode == 66){
p_2_scoreCount  = 1;
p_2_score.text = String(p_2_scoreCount);
}

}


///for coundown 
var nCount:Number = 10;
var myTimer:Timer = new Timer(1000, nCount);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, completeHandler);

timer_txt.text = nCount.toString();
myTimer.start();

myTimer.addEventListener(TimerEvent.TIMER, countdown);

function countdown(e:TimerEvent):void
{
 nCount--;
timer_txt.text = nCount.toString();
}

// 10 Sec finish it will go to result page
function completeHandler(event:TimerEvent):void {
 gotoAndStop("result"); //Result Page
}

CodePudding user response:

Ok, here we go.

if (p_1_scoreCount > p_2_scoreCount)
{
    // Player №1 is winner.
}
else if (p_1_scoreCount < p_2_scoreCount)
{
    // Player №2 is winner.
}
else
{
    // It's a draw.
}
  • Related