//Game control
var Game = {
//Game time, one minute
time : 61,
//The Gopher map, there are ten in total, two of which are bad
mouseMap : {
1:'good',
2:'bad',
3:'good',
4:'good',
5:'bad',
6:'good',
7:'bad',
8:'good',
9:'good',
10:'good'
},
//All gopher dom elements
allMouse : [],
//Current score
nowScore : 0,
//What are the holes currently occupying
hasHole : {},
//What are the gophers currently active
hasMouse : {},
//The collection of holes on the page
lis : null,
//Initialize the gopher and the hole
init : function(){
//Get the page's hole collection
= ('panel').getElementsByTagName('li');
_this = this;
//Initialize 10 gophers
for(var i=1;i <=10;i++){
var mouse = new Mouse([i]);
//Extended gopher being clicked event
= function(){
//Modify the score
(100 * (=='good'?1:-1));
}
//Extended Gopher animation end event
= function(){
//Remove the gopher from the cave
var li = _this.lis[];
();
= null;
//Clear the corresponding holes and gophers
_this.hasHole[] = null;
_this.hasMouse[] = null;
}
(mouse);
}
},
//Modify the game score
changeScore : function(score){
+= score;
('score').innerHTML = ;
},
//The game begins
start : function(){
if( <= 0)return;
var _this = this;
//Random hole number
var random = parseInt(()*9,10);
while([random]){
random = parseInt(()*9,10);
}
//Random Gopher Number
var randomMouse = parseInt(()*10,10);
while([randomMouse]){
randomMouse = parseInt(()*10,10);
}
//Add gophers to the cave
[randomMouse].hole = random;
[randomMouse].num = randomMouse;
[random].appendChild([randomMouse].mouse);
[random].mouse = [randomMouse];
[random].('normal');
//Record the number of gophers and caves
[random] = 'true';
[randomMouse] = 'true';
setTimeout(function(){_this.start();},250);
},
//Countdown
startTime : function(){
-= 1;
var _this = this;
('time').innerHTML = ;
if( > 0){
setTimeout(function(){_this.startTime()},1000);
}
},
//Reset game settings
reset : function(){
= 61;
= [];
= 0;
= {};
= {};
= null;
(0);
}
}
//Game start function
function GameStart(){
if( > 0 && != 61){
alert("The game has not ended yet, so you can't start over!");
return;
}
();
();
();
();
}