-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
140 lines (115 loc) · 3.39 KB
/
main.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// MAIN.JS
// Alex Breyfogle c2015
// UI Overlay Globals
var main_ui;
var dev_ui;
var mil_ui;
var res_ui;
// Country Click Handling & Drawing Globals
var current_context = "home";
var canvas;
var ctx;
// Context Specific UI Globals
var bank_ui;
var research_ui;
var attack_stat_ui;
var attack_list_ui;
// Displays information for always on UI
function setConstUI(p){
bank_ui.innerHTML = p.bank;
research_ui.innerHTML = p.research;
}
// Initialize game components
function init(){
canvas = document.getElementById('myCanvas');
ctx = canvas.getContext('2d');
//connect navigation ui
main_ui = document.getElementById("main-ui");
dev_ui = document.getElementById("dev-ui");
mil_ui = document.getElementById("mil-ui");
res_ui = document.getElementById("res-ui");
dev_ui.style.display = "none";
mil_ui.style.display = "none";
res_ui.style.display = "none";
//connect player ui
bank_ui = document.getElementById("bank_ui");
research_ui = document.getElementById("research_ui");
attack_stat_ui = [];
attack_stat_ui["val"] = $("#attack_stat_ui").children(".val").get(0);
attack_stat_ui["costL"] = $("#attack_stat_ui").children(".costL").get(0);
attack_stat_ui["costW"] = $("#attack_stat_ui").children(".costW").get(0);
attack_stat_ui["costA"] = $("#attack_stat_ui").children(".costA").get(0);
attack_list_ui = document.getElementById("attack_list_ui");
//connect markers
initmarkers(game);
update();
setInterval(update, tstep);
//return 0;
}
// reset ui and context variables
function reset_context(){
//close context specific ui
main_ui.style.display = "none";
dev_ui.style.display = "none";
mil_ui.style.display = "none";
res_ui.style.display = "none";
//clear potential attack stats
attack_stat_ui["costL"].innerHTML = "-";
attack_stat_ui["costW"].innerHTML = "-";
attack_stat_ui["costA"].innerHTML = "-";
attack_stat_ui["val"].innerHTML = "-";
//clear attack list
attack_list_ui.innerHTML = "";
//reset clicks
first_click = true;
pending_attack = null;
//clear canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);
}
function refresh_context(){
if(current_context == "mil"){ mil(); }
else if(current_context == "dev"){ dev(); }
else if(current_context == "res"){ res(); }
else if(current_context == "home"){ home(); }
}
// UI navigation functions
function home(){
reset_context();
main_ui.style.display = "block";
current_context = "home";
display_attacks(game);
}
function dev(){
reset_context();
dev_ui.style.display = "block";
current_context = "dev";
}
function mil(){
reset_context();
mil_ui.style.display = "block";
current_context = "mil";
display_attacks(game);
list_attacks(game);
}
function res(){
reset_context();
res_ui.style.display = "block";
current_context = "res";
}
function list_attacks(gb){
for(i = 0; i < gb.attacks.length; i++){
var a = gb.attacks[i];
if(a.owner == current_user){
attack_list_ui.innerHTML += a.c1 + " -> " + a.c2 + '<br><div style="color:red" onclick="remove_attack(' + a.c1 + ',' + a.c2 + ')">X</div>';
}
}
}
function show_potential_attack_stats(attack){
var land_cost = 8;
var water_cost = 10;
var air_cost = 4;
attack_stat_ui["costL"].innerHTML = "L: " + attack.dist["land"] * land_cost;
attack_stat_ui["costW"].innerHTML = "W: " + attack.dist["water"] * water_cost;
attack_stat_ui["costA"].innerHTML = "A: " + attack.dist["air"] * air_cost;
attack_stat_ui["val"].innerHTML = attack.c1 + " attacking " + attack.c2;
}