HTML and CSS Reference
In-Depth Information
Next, the logic finds a number between 0 and 99 , and checks to see whether it is less
than the chanceRandomEnemyMovement value. If it is, it will ignore the directionsToTest
array and simply try to find a random direction to move in. In either case, all the di-
rections (either in the directionsToTest array or in order up, down, left, and right) are
tested until the testBounds() function returns true .
That's all there is to this code. In Example 9-3 , you will find the entire set of code for
this game.
Micro Tank Maze Complete Game Code
Example 9-3. Micro Tank Maze full source code listing
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CH(EX3: Micro Tank Maze Game</title>
<script src="modernizr-1.6.min.js"></script>
<script type="text/javascript">
window.addEventListener('load', eventWindowLoaded, false);
function eventWindowLoaded() {
canvasApp();
}
function canvasSupport () {
return Modernizr.canvas;
}
function canvasApp(){
if (!canvasSupport()) {
return;
}else{
theCanvas = document.getElementById("canvas");
context = theCanvas.getContext("2d");
}
//application states
const GAME_STATE_INIT = 0;
const GAME_STATE_WAIT_FOR_LOAD = 10;
const GAME_STATE_TITLE = 20;
const GAME_STATE_NEW_GAME = 30;
const GAME_STATE_WAIT_FOR_PLAYER_MOVE = 40;
const GAME_STATE_ANIMATE_PLAYER = 50;
const GAME_STATE_EVALUATE_PLAYER_MOVE = 60;
const GAME_STATE_ENEMY_MOVE = 70;
const GAME_STATE_ANIMATE_ENEMY = 80;
const GAME_STATE_EVALUATE_ENEMY_MOVE = 90;
const GAME_STATE_EVALUATE_OUTCOME = 100;
const GAME_STATE_ANIMATE_EXPLODE = 110;
const GAME_STATE_CHECK_FOR_GAME_OVER = 120;
Search WWH ::




Custom Search