-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.js
191 lines (168 loc) · 7.21 KB
/
init.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
"use strict";
// Init start Hexes
const hexAll = Array.from(document.querySelectorAll(`.hex`));
let hexRow = Array.from(document.querySelectorAll(`.hex-row`));
hexRow = hexRow.map((m) => Array.from(m.children));
//Create all HEXES on the board
hexAll.forEach((el) => {
const newHex = new Hex(el, undefined, false, undefined, false);
el.hex = newHex;
});
let player;
let player1;
let player2;
let player3;
// hexAll[2].troops = new Troops(hexAll[2], `green`);
// hexAll[2].troops.soldiers = [
// new Cavalry(hexAll[2], `green`),
// new Infantry(hexAll[2], `green`),
// new Merchant(hexAll[2], `green`),
// new Merchant(hexAll[2], `green`),
// ];
// hexAll[2].troops.calcSize();
// hexAll[2].troops.showSoldierHex();
// hexAll[4].troops = new Troops(hexAll[4], `green`);
// hexAll[4].troops.soldiers = [
// new Elephant(hexAll[4], `green`),
// new Elephant(hexAll[4], `green`),
// new Cavalry(hexAll[4], `green`),
// new Cavalry(hexAll[4], `green`),
// ];
// hexAll[4].troops.calcSize();
// hexAll[4].troops.showSoldierHex();
// Array of 4 land piece. One big array of 12 cafelkas. Each one has 4 Hexes of land//
const hexArea = [];
const hexInRow = hexAll.length / 6; //!!!!!!!Devine by 6 only when you have 6 HEX ROWS on the map!!!!!!!!!!!!
const gather4hex = function (x) {
const arr4hex = [
hexAll[x],
hexAll[x + 1],
hexAll[x + hexInRow],
hexAll[x + hexInRow + 1],
];
hexArea.push(arr4hex);
};
for (let i = 0; i < hexAll.length / 6; i = i + 2) {
gather4hex(i);
}
for (let i = (hexAll.length / 6) * 2; i < (hexAll.length / 6) * 3; i = i + 2) {
gather4hex(i);
}
for (let i = (hexAll.length / 6) * 4; i < (hexAll.length / 6) * 5; i = i + 2) {
gather4hex(i);
}
// Array of 4 land piece. One big array of 12 cafelkas. Each one has 4 Hexes of land//
//SET PLAYER, CREATE FIRST MERCHANT for each user. playersNumber must be SET well!!!
setPlayer.addEventListener(`click`, function () {
this.style.display = `none`;
const num = Math.ceil(playersNumber / onlineUsers.size);
let color;
if (onlineUsers.size === 3) color = `blue`;
else if (onlineUsers.size === 2) color = `red`;
else if (onlineUsers.size === 1) color = `green`;
else alert(`Liczba graczy musi wynosic 1-3`);
//set individual player for each user
player = new Player(UUID, num, color, false, 0);
// player.setSkills();
window.tree = new Tree();
window.cost = new Cost();
// Make start Hexes for All Players
if (player.nr === 1) {
hexAll[0].hex = new Hex(hexAll[0], `grass`, true, `food`, true);
hexAll[1].hex = new Hex(hexAll[1], `forest`, true, `wood`, true);
hexAll[6].hex = new Hex(hexAll[6], `mountain`, true, `stone`, true);
hexAll[7].hex = new Hex(hexAll[7], `plain`, true, `food`, false);
hexAll[0].classList.add(`class-${hexAll[0].hex.land}`);
hexAll[1].classList.add(`class-${hexAll[1].hex.land}`);
hexAll[6].classList.add(`class-${hexAll[6].hex.land}`);
hexAll[7].classList.add(`class-${hexAll[7].hex.land}`);
}
if (player.nr === 2) {
hexAll[35].hex = new Hex(hexAll[35], `grass`, true, `food`, true);
hexAll[34].hex = new Hex(hexAll[34], `forest`, true, `wood`, true);
hexAll[29].hex = new Hex(hexAll[29], `mountain`, true, `stone`, true);
hexAll[28].hex = new Hex(hexAll[28], `plain`, true, `food`, false);
hexAll[35].classList.add(`class-${hexAll[35].hex.land}`);
hexAll[34].classList.add(`class-${hexAll[34].hex.land}`);
hexAll[29].classList.add(`class-${hexAll[29].hex.land}`);
hexAll[28].classList.add(`class-${hexAll[28].hex.land}`);
}
if (player.nr === 3) {
hexAll[5].hex = new Hex(hexAll[5], `grass`, true, `food`, true);
hexAll[11].hex = new Hex(hexAll[11], `forest`, true, `wood`, true);
hexAll[4].hex = new Hex(hexAll[4], `mountain`, true, `stone`, true);
hexAll[10].hex = new Hex(hexAll[10], `plain`, true, `food`, false);
hexAll[5].classList.add(`class-${hexAll[5].hex.land}`);
hexAll[11].classList.add(`class-${hexAll[11].hex.land}`);
hexAll[4].classList.add(`class-${hexAll[4].hex.land}`);
hexAll[10].classList.add(`class-${hexAll[10].hex.land}`);
}
//set active turn to first player
if (player.nr === 1) {
player.action = 3;
startGame.style.display = `inline-block`;
}
checkActionFirst();
//add individual merchant for each user (seen only for current user)
if (player.nr == 1) {
player1 = player;
hexAll[0].troops = new Troops(hexAll[0], player.color);
hexAll[0].troops.soldiers.push(new Merchant(hexAll[0], player.color));
hexAll[0].troops.calcSize();
hexAll[0].troops.showSoldierHex();
} else if (player.nr == 2) {
player2 = player;
hexAll[35].troops = new Troops(hexAll[35], player.color);
hexAll[35].troops.soldiers.push(new Merchant(hexAll[35], player.color));
hexAll[35].troops.calcSize();
hexAll[35].troops.showSoldierHex();
} else if (player.nr == 3) {
player3 = player;
hexAll[5].troops = new Troops(hexAll[5], player.color);
hexAll[5].troops.soldiers.push(new Merchant(hexAll[5], player.color));
hexAll[5].troops.calcSize();
hexAll[5].troops.showSoldierHex();
}
// show start resource
for (let i = 0; i < window.p1GlobalResourceDiv.length; i++) {
window[`p` + player.nr + `GlobalResourceDiv`][i].innerHTML =
player.resource[res[i]];
}
// Show player name and whole playerGlobalHud
window[`p` + player.nr + `Global`].children[0].innerHTML = UUID;
window[`p` + player.nr + `Global`].children[0].style.backgroundColor =
player.color;
window[`p` + player.nr + `ActionValue`].textContent = player.action;
window[`p` + player.nr + `Global`].style.display = `block`;
});
// ------------------------------------------------------------------------ //
// Testing soldiers //
const hexes = document.querySelectorAll(`.hex`);
console.log(hexes);
// hexes[0].childNodes[0].classList.add(`soldierHex`, `elephantgreen`);
// hexes[0].childNodes[2].classList.add(`soldierHex`, `elephantgreen`);
// hexes[0].childNodes[6].classList.add(`soldierHex`, `elephantgreen`);
// hexes[0].childNodes[8].classList.add(`soldierHex`, `elephantgreen`);
const bb = () => {
hexes[0].childNodes[4].classList.add(`towngreen`);
hexes[0].childNodes[1].classList.add(`market`);
hexes[0].childNodes[3].classList.add(`fortress`);
hexes[0].childNodes[5].classList.add(`academy`);
hexes[0].childNodes[7].classList.add(`obelisk`);
hexes[1].childNodes[4].classList.add(`towngreen`);
hexes[1].childNodes[3].classList.add(`market`);
hexes[1].childNodes[1].classList.add(`fortress`);
hexes[1].childNodes[7].classList.add(`academy`);
hexes[1].childNodes[5].classList.add(`obelisk`);
hexes[2].childNodes[4].classList.add(`towngreen`);
hexes[2].childNodes[3].classList.add(`observatory`);
hexes[2].childNodes[1].classList.add(`port`);
hexes[2].childNodes[7].classList.add(`temple`);
hexes[2].childNodes[5].classList.add(`port`);
hexes[3].childNodes[4].classList.add(`towngreen`);
hexes[3].childNodes[1].classList.add(`observatory`);
hexes[3].childNodes[5].classList.add(`port`);
hexes[3].childNodes[3].classList.add(`temple`);
hexes[3].childNodes[7].classList.add(`port`);
};
// bb();