The main screen controlled the whole game’s main functionality.  One of the most important factors of my game was to make sure the games randomly loaded. It was easy to load individual games, I would only need to create a variable for the class, and then import the class with its objects on top of the main screen. But this wouldn’t work for creating random games.

It took me a while to work out how to randomise the games. I didn’t have previous knowledge of arrays, but after doing research I found out that this was what I needed to make this work. I could create a variable for the array, which would hold all of the game levels, and then use the array as this item to call. Here is the randomising game function:


//return a random number between 2 others

private function startGame(event:Event):void{
if( != controls_mc)
stage.removeEventListener(MouseEvent.CLICK, startGame);

//Create an array for the different possible games
var gameArray = new Array;

var test = new Main1();
var test1 = new Main1();
var test2 = new breath();
var test3 = new Falling();
var test4 = new Stop();
var test5 = new Tapping();

//add classes to the array – this will make it easier to add more games in the future.
gameArray.push(test, test1, test2, test3, test4, test5);

//start multiple games after each other (without looping).
//choose a random number between 0 and the length of the gameArray -1.
var gameIndex = randomMinMax(0, (gameArray.length – 1));


//assign a variable to the object of the randomly assigned game.
var gameObject = gameArray[gameIndex];

//create a new instance of the game object and play it!
//game = new gameObject();

This method worked brilliantly, and didn’t end up causing any other issues with the rest of my code.

coding the endgame function

I really struggled to work out a way to end the game, I attempted using many different methods but none of these would work. I  got to the point where if there was no end point to the game there was no point of the game, so I tried to find any alternative that could work to give an impression the game had ended. I found the code where by I would completely remove the array that creates the game when the player dies.

public function gameOver():void
gameArray = null;

This code completely removed the array, and left the screen white. As it was so close to the end of the project I had to just accept this and continue with the other issues I still had to face. While working on other issues I came across some code that ended up working perfectly, this code made me create a new class which is a screen that has game over written on it, when the user dies the game over screen would appear.

public function gameOver():void
gameArray = null;

stage.removeEventListener(MouseEvent.CLICK, startGame);
var endGame:gameEnd = new gameEnd();

This was a much better solution for my issue. This method although better than the last still didn’t allow the game to work properly. I could not restart the game from this point, the game would have to be closed and re opened to start again.