Wednesday, August 10, 2005

Tafe : Geoff : week 4 : (Whack A Mole)-->"Catch a Smurf" Game Flowchart....


Introduction
This exercise is to demonstrate how pseudocode and a flowchart can be used to write a computer program. On completion of this exercise you will have a version of the Whack A Mole game for use on a web site.

The Game
Whack a Mole is based on an old carnival game and has been around on computers as a kids game for a long time.

Game Play
A number of things (moles) are hiding in holes / containers.
Each mole pops its head up at a random time.
The player has to hit as many visible moles as possible in the time allowed.
When time is up, the player's score is displayed and if they are lucky they win a prize.
The player is prompted to play again.

Program development life cycle
Analyse
First analyse the game rules and determine the computer logic required to play the game.

Design
Program design can be developed by writing pseudocode and drawing a flow chart to describe the logic and identify objects and variables required.

Test
Test the design by following the logic in the flow chart and pseudocode.
Watch out for dead ends, infinite loop conditions and logic errors.

Develop proto-type
Develop a rough proto-type to test the operation and functionality of the program

Review
Test the proto-type identify bugs, logic errors and other problems.

Repeat the process again and again and again
Analyse the problems, re-design, re-test, modify proto-type, review.

Develop final product
Once the proto-type meets all user requirements and performs as expected, finish developing the program.
Make it look and sound good.
Add some bells and whistles.
Pseudocode

BEGIN – PROMPT TO PLAY
Prompt the user to play
Accept user input play game
IF play game = true THEN
Start the game
END IF
END

BEGIN - START THE GAME
Hide user prompt
Set time to play
Set score to zero
WHILE game is not over
FOR each target object
Set random time to move
IF time to move THEN
Show the target object
Set random time to hide
END IF
IF target is hit THEN
Add one to score
Display hit message
Hide the target object
END IF
IF time to hide THEN
Hide the target object
END IF
END FOR
Check remaining time to play
IF time to play < = zero THEN
Game over = true
END IF
END WHILE
Stop game
Display Game Over
Prompt to play
END



Flow Chart.










ActionScript:
// hide introduction screen and start the game
// when the player clicks on the head in the Intro screen
intro.head.onRelease = function(){
fin._visible = false;
intro._visible = false;
startgame();
};
//
// initialise whack counter and ouch words
wcnt = 0;
words = new Array("WHACK", "WHAM", "POW", "ZOK", "THWAP","ZAM", "OUCH", "ZAP","BOP", "CLUNK", "SMASH", "OOPS", "ARGH!", "EEP!");
nwds = words.length;
//
// count whacks and display clip when a biffle is whacked
doWhackAt = function (x, y) {
// remove comment lines below to add a sound
// with a linkage name of ouch from the library
// var ouch = new Sound();
// ouch.attachSound("ouch");
// ouch.start();
var nm = "wc"+wcnt;
_root.attachMovie("whack", nm, wcnt+99);
_root[nm].word = words[Math.floor(Math.random()*nwds)];
_root[nm]._x = x;
_root[nm]._y = y;
_root[nm]._xscale = _root[nm]._yscale=70;
_root[nm].onEnterFrame = function() {
this._alpha -= 10;
if (this._alpha<=10) {
delete this.onEnterFrame;
this.removeMovieClip();
}
};
wcnt++;
wcnt %= 5;
};
//

// start and play the game
startgame = function () {
for (var i = 0; i<9; i++) {
var nm = "m"+i;
_root[nm].onPress = function() {
if (this._currentframe == 10) {
this.play();
whacks++;
scoreDisplay = whacks;
doWhackAt(_xmouse, _ymouse);
}
};
_root[nm].onEnterFrame = function() {
if (this._currentframe == 1 || this._currentframe == 10) {
if ((Math.random()*50)<1) {
this.play();
}
}
};
}
whacks = 0;
scoreDisplay = whacks;
endTime = getTimer()+30000;
_root.onEnterFrame = function() {
var eTime = endTime-getTimer();
if (eTime<=0) {
showTime = "Expired";
for (var i = 0; i<9; i++) {
var nm = "m"+i;
delete _root[nm].onPress;
delete _root[nm].onEnterFrame;
_root[nm].gotoAndStop(1);
delete _root.onEnterFrame;
}
gameover();
} else {
showTime = Math.ceil(eTime/1000)+" sec";
}
};
};
//
// show the game over screen and offer play again
gameover = function () {
fin._visible = true;
fin.head.onRelease = function() {
fin._visible = false;
delete fin.head.onRelease;
startgame();
};
};
Game Assets

Dynamic Text variables:
scoreDisplay
showTime


Movie Clips:
cylinder (object to hide in or behind – could be a rock)
head (mole head)
mole (moving head with a mask applied)
whack (clip to display when mole has been whacked)
intro (clip to display instructions and start game)
gameOver (clip to display Game Over and prompt to play again)



Student Task
Use the information provided above to create a prototype of the whack-a-mole game.
You may work with others to plan, design, develop and test the game.

Submit your prototype to your teacher for checking (finished or not) by end of class in week 5.

Have fun

...Catch A Smurf....

0 Comments:

Post a Comment

<< Home