Book Image

Flash Game Development by Example

By : Emanuele Feronato
Book Image

Flash Game Development by Example

By: Emanuele Feronato

Overview of this book

<p>You can't call yourself a Flash game developer unless you know how to build certain essential games, and can quickly use the skills and techniques that make them up.<br /><br />Flash Game Development by Example is an ultra-fast paced game development course. Learn step-by-step how to build 10 classic games. Each game introduces new game development skills, techniques, and concepts. By the end of the book you will have built ten complete games &ndash; and have the skills you need to design and build your own game ideas.<br /><br />The book starts with simple well known puzzle games: Concentration and Minesweeper. After learning the basics of game design you&rsquo;ll introduce AI with a four-in-a-row game. Then as you build your own versions of old arcade games such as Snake, Tetris, and Astro Panic. The book ends with a collection of modern casual classics.</p>
Table of Contents (17 chapters)
Flash Game Development by Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Where to Go Now
Index

Unleashing CPU power


Finally it's time for the computer to make its move. At the moment it will be a random move, so you just need to check for legal columns to move, and randomly choose one of them.

The idea: Choose a random column among the possible ones and place the disc.

The development: This is computerMove function, to be inserted in disc_movieclip.as:

private function computerMove():void {
  var possibleMoves:Array=par.possibleColumns();
  var cpuMove:uint=Math.floor(Math.random()*possibleMoves.length)
  currentColumn=possibleMoves[cpuMove];
  x=35+60*currentColumn;
  currentRow=par.firstFreeRow(currentColumn,currentPlayer);
  fallingDestination=35+currentRow*60;
}

Apart from computer decision, it works as if the player was human.

var possibleMoves:Array=par.possibleColumns();

possibleMoves variable stores the array with all legal columns.

var cpuMove:uint=Math.floor(Math.random()*possibleMoves.length)

cpuMove is a random number between zero (included) and the number of elements in...