-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandomEngine.js
More file actions
33 lines (29 loc) · 988 Bytes
/
randomEngine.js
File metadata and controls
33 lines (29 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Window.RandomEngine = function RandomEngine(characters){
this.Characters = characters;
this.counter = 0;
this.newDirection = function(index){
/*From this point on you can get the name and type of character
*this.Characters[3].getcharacterType()
*this.Characters[2].getCharacterDirection()
*
*/
var ghost = this.Characters[index];
if(ghost.getStuckStatus()){
var charDirection = ghost.getCharacterDirection(),
charPreviousDirection = ghost.getPreviousCharacterDirection(),
ranDirection = this.compareDirections(charDirection,charPreviousDirection,ghost);
ghost.setNewDirection(ranDirection);
}
else {
if (this.counter > this.getRandomNumber(5000)) {
ghost.setNewDirection(this.getRandomDirection(1,4));
this.counter = 0;
}
else {
this.counter++;
}
}
}
};
//The Egine is the base class
Window.RandomEngine.prototype = new Window.Engine;