Sunday, 7 November 2010

Paper, Scissors and rocks in Actionscript 3 part 2

You should now have the basic structure of the Paper, Scissors and Rocks game from part 1. I will be adding three counters to the game in part 2. These will count the number of wins, draws and losses.

Paper, Scissors and rocks in Actionscript 3 part 2

Step 1

Open up part 1 of the tutorial. Then select the text tool and with dynamic text and drag three text fields on the stage.  Beside the text fields add the following text: Wins, draws and losses. Give your dynamic text the instance names: wins_txt, draws_txt and losses_txt.

Step 2 

Update the following code in the Actions panel.I have not included all the code from the previous tutorial.

var winCount:uint = 0;
var loseCount:uint = 0;
var drawCount:uint = 0;

//player Wins
if((playersChoice == "paper" && computer == "rock") || 
    (playersChoice == "scissors" && computer == "paper") ||            
    (playersChoice == "rock" && computer == "scissors")){
    output_txt.text = "You win! \n The computer chose " + computer;
    win_txt.text = String(winCount);

//player draw
else if(playersChoice == computer){
    output_txt.text = "Its a draw \n The computer chose " + computer;
    draw_txt.text = String(drawCount);
//player lose
    output_txt.text = "You lose! \n The computer chose " + computer;
    lose_txt.text = String(loseCount);

Step 3

Test your movie Ctrl + Enter.

You can download the source files here.


annick 18 February 2011 at 09:19  

Thank you so much for this tutorial!!
I just have one little problem: My counter doesnt work. It counts till 1. But when I win/lose/draw again it doesnt count anymore. Do you know where this comes from?

iliketo 5 March 2011 at 04:14  


It looks like your counter variables are inside the chosen function. Every time you call this function it will reset the counters back to zero. Try putting the variables outside the function.

  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP