Rock, Paper, Scissors – Flash CC

After completing the lesson in which we created the flipping a coin game, we were tasked on creating a game of Rock, Paper, Scissors using Flash.

I started by creating a new document using Actionscript 3.0 and setting a black background.  I then sourced the three images of hands in the form of rock, paper and scissors ready to edit in Photoshop.  I created a silhouette of each hands and increased the saturation to create them completely white. These would be used as the games buttons corresponding to the players choice. Also, I changed the images into movie clips and changed their instance names to rock, paper and scissors respectively.

Next, I created a dynamic text box in the top left of the window. This would be used to display yours and the computers choice and whether you have won, drawn or lost. Also, I created an additional 3 dynamic text boxes in the top write to display the numbers of wins, draws and losses as you progress, allowing the player to keep track of the score.

I then moved on to the code.

FlashScreen1The above code turns the hand images into buttons which respond to the click of a mouse.

Capture2I then added a variable called “choicesArray” using an array to store the list of choices, ensuring this matches the instance names I previously selected.

Capture3Next, I started the create a function called chosen. The “(e:Event):void” section which follows essentially says to run the following code when an event happens, in this case, a mouse click.

The next variable is the players choice, which is a string which stores the instance name of the button clicked by the player. This is why it is important that the instance name matched the previous variable.

As it mentions in the code, the computer choice variable pulls a random choice from the choicesArray variable earlier created.

Lastly, to finish the function I created an If statement which holds all the possible outcomes by comparing the players choice to the computers choice and determining whether you have won, drawn or lost. Also, creating an output text which will be displayed to the player in the dynamic text box name “output.txt” which I created at the beginning.

An example of the game running is shown below, the player has chosen rock:



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s