-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontrol.js
116 lines (102 loc) · 2.79 KB
/
control.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
108
109
110
111
112
113
114
115
116
mapDisplay = new ROT.Display({
width:MAP_WIDTH, height:MAP_HEIGHT,
layout:"rect", forceSquareRatio: false
});
sideBarDisplay = new ROT.Display({
width:SIDEBAR_WIDTH, height:MAP_HEIGHT,
layout:"rect", fg: "#0E4", forceSquareRatio: false
});
bottomBarDisplay = new ROT.Display({
width:MAP_WIDTH+SIDEBAR_WIDTH, height:COMBAT_LOG_LENGTH,
layout:"rect", fg: "#0E4", forceSquareRatio: false
});
popUpDisplay = new ROT.Display({
width:80, height:23,
layout:"rect", fg: "#0E4"
});
var combatLog = [];
function selectOption(situation, options)
{
this.situation = situation;
this.options = options;
}
selectOption.prototype = {
handleEvent: function(event) {
options = this.options;
if(options.length > 26)
alert("Too many options");
var selectedIndex = event.keyCode - 65; //keypress 'a' corresponds to index 0 here.
if(selectedIndex >= options.length)
return;
for(var i = 0; i < options.length; i++)
{
if(selectedIndex == i) {
window.removeEventListener('keydown', this);
clearPopup();
options[i].o();
}
}
},
presentOptions: function() {
s = this.situation;
s += "\n";
for(var i = 0; i < this.options.length; i++)
{
s += "\n" + String.fromCharCode(97 + i) + ") " + this.options[i].t;
}
document.getElementById('stuffOnTop').style.display = 'initial';
popUpDisplay.clear();
popUpDisplay.drawText(1, 1, s);
},
run: function() {
this.presentOptions();
window.addEventListener('keydown', this);
}
};
getAcknowledgement = function(string, callbackFunction)
{
document.getElementById('stuffOnTop').style.display = 'initial';
popUpDisplay.clear();
popUpDisplay.drawText(1, 1, string + "\n\n(press ENTER to continue)");
cf = function(event) {
event.preventDefault();
if (event.keyCode == 13) {
window.removeEventListener('keydown', cf);
clearPopup();
callbackFunction();
}
};
window.addEventListener('keydown', cf);
}
getConfirmation = function(string, callbackFunction1, callbackFunction2)
{
document.getElementById('stuffOnTop').style.display = 'initial';
popUpDisplay.clear();
popUpDisplay.drawText(1, 1, string + " Do you accept?\n\n(Y)es or (N)o");
cf = function(event) {
if(event.keyCode == 89)//y
{
window.removeEventListener('keydown', cf);
clearPopup();
callbackFunction1();
}
if(event.keyCode == 78)//n
{
window.removeEventListener('keydown', cf);
clearPopup();
callbackFunction2();
}
};
window.addEventListener('keydown', cf);
}
gameOver = function(string)
{
document.getElementById('stuffOnTop').style.display = 'initial';
popUpDisplay.clear();
popUpDisplay.drawText(1, 1, string);
cf = function(event) {
event.preventDefault();
window.removeEventListener('keydown', cf);
};
window.addEventListener('keydown', cf);
}