-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathadventure.js
107 lines (90 loc) · 2.79 KB
/
adventure.js
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
function Adventure(startX, startY, endX, endY, bound){
this.coord = new Thing(startX, startY);
this.beginning = new Thing(startX, startY);
this.end = new Thing(endX, endY);
this.bound = bound;
this.burns = new Thing(2,5);
};
function Thing(x, y) {
this.x = x;
this.y = y;
};
Adventure.prototype.atPosition = function(xDel, yDel, character){
return (this.coord.x === character.x + xDel) && (this.coord.y === character.y + yDel);
}
Adventure.prototype.mov = function(xDel, yDel, x, y, bound) {
if(this.atPosition(xDel, yDel, this.end)){
this.coord.x += x;
this.coord.y += y;
this.hideAbe(xDel, yDel);
this.killAbe();
dead.play();
alert("Whuuthaa!!??");
}
else if(this.atPosition(xDel, yDel, this.burns)){
this.reset();
}
else if (this.coord.y === bound && yDel != 0) {
holdon.play();
alert("D'oh!!!");
}
else if (this.coord.x === bound && xDel != 0) {
coon.play();
alert("D'oh!!!");
}
else {
this.coord.x += x;
this.coord.y += y;
this.hideAbe(xDel, yDel);
this.setPlayer();
};
}
Adventure.prototype.reset = function() {
adventure.hideAbe(0,0);
adventure.coord.x = adventure.beginning.x;
adventure.coord.y = adventure.beginning.y;
adventure.updateDisplay();
}
Adventure.prototype.makeGrid = function(){
for (var i = 0; i <= this.bound; i++){
document.write("<div class=\"row\">");
for (var k = 0; k <= this.bound; k++){
document.write("<div id="+"\""+i+k+"\""+"class=\"col-xs-3 cell\"></div>");
};
document.write("</div>");
};
this.updateDisplay();
}
Adventure.prototype.updateDisplay = function(){
this.setPlayer();
this.target();
this.setBurns();
}
Adventure.prototype.killAbe = function () {
document.getElementById(this.end.y.toString() +
this.end.x.toString()).innerHTML = "<img src='dead.jpg' class='img'></img>";
};
Adventure.prototype.target = function(){
document.getElementById(this.end.y.toString() +
this.end.x.toString()).innerHTML = "<img src='retire.png' class='img'></img>";
};
Adventure.prototype.setPlayer = function(){
document.getElementById(this.coord.y.toString() +
this.coord.x.toString()).innerHTML = "<img src='small_abe.png' class='img'></img>";
};
Adventure.prototype.setBurns = function(){
document.getElementById(adventure.burns.y.toString() +
adventure.burns.x.toString()).innerHTML = "<img src='burns.png' class='img'></img>";
};
Adventure.prototype.hideAbe = function (xChange, yChange) {
document.getElementById((this.coord.y +
yChange).toString() + (this.coord.x + xChange).toString()).innerHTML = "";
};
// function endGame(){
// if((this.setBurns.x === this.setPlayer.x) && (this.setBurns.y === this.setPlayer.y)){
// console.log("Abe is dead!");
// }
// else {
// console.log("Abe lives!");
// }
// }