-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
303 lines (286 loc) · 9.33 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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
function vegrehajt(mit) {
switch (mit) {
case "/töröl" :
localStorage.clear()
location.reload()
break;
}
}
function betolt() {
alapozas()
if (localStorage.vanmentes) {
muhelyek = JSON.parse(localStorage.muhelyek)
hazak = JSON.parse(localStorage.hazak)
varak = JSON.parse(localStorage.varak)
bevetelek = JSON.parse(localStorage.bevetelek)
svg = JSON.parse(localStorage.svg)
document.getElementById("svg").innerHTML = svg
document.getElementById("arany").innerHTML = bevetelek.arany
document.getElementById("ellatmany").innerHTML = bevetelek.ellatmany
} else {ment()}
}
function ment() {
localStorage.vanmentes = true
localStorage.hazak = JSON.stringify(hazak)
localStorage.muhelyek = JSON.stringify(muhelyek)
localStorage.varak = JSON.stringify(varak)
localStorage.bevetelek = JSON.stringify(bevetelek)
localStorage.svg = JSON.stringify(document.getElementById("svg").innerHTML)
document.getElementById("arany").innerHTML = bevetelek.arany
document.getElementById("ellatmany").innerHTML = bevetelek.ellatmany
}
function ujkatona() {
if ((bevetelek.ellatmany - 50) < 0) {
alert("nincs elég adagnyi ellátmányod")
return false
}
let vár = varak.find((item) => folyamatidja == item.id)
bevetelek.ellatmany -= 50
vár.katona += 5
document.getElementById("katonaszam").innerText = vár.katona
ment()
}
hazak = []
varak = []
muhelyek = []
beallitasok = {
trend: {
hazszine:"red"
},
hazgyujtesido: 6000,
muhelygyujtesido: 6000
}
bevetelek = {
arany:3000,
ellatmany:3000,
aranyhely:3000,
ellatmanyhely:3000,
}
function adogyujt(id) {
let ido = new Date()
let most = ido.getTime()
let haz = hazak.find((item) => id == item.id)
if (haz.utolsobegyujtes) {
let elteltido = most - haz.utolsobegyujtes
let ado = Math.floor(elteltido / 6000)
if (bevetelek.arany + ado > bevetelek.aranyhely) {
ado = ado - ((ado + bevetelek.arany) - bevetelek.aranyhely)
alert("megtelt a raktárad")
}
bevetelek.arany += ado
}
haz.utolsobegyujtes = most
ment()
}
function ellatmanygyujt(id) {
let ido = new Date()
let most = ido.getTime()
let haz = muhelyek.find((item) => id == item.id)
if (haz.utolsobegyujtes) {
let elteltido = most - haz.utolsobegyujtes
let adag = Math.floor(elteltido / 6000)
if (bevetelek.ellatmany + adag > bevetelek.ellatmanyhely) {
adag = adag - ((adag + bevetelek.ellatmany) - bevetelek.ellatmanyhely)
alert("megtelt a raktárad")
}
bevetelek.ellatmany += adag
}
haz.utolsobegyujtes = most
ment()
}
function varmenu(id) {
kivár = varak.find((item) => item.id == id)
folyamatidja = id
document.getElementById("katonaszam").innerText = kivár.katona
document.getElementById("varmenu").style.display = 'block'
}
function epites(bejovoid) {
document.getElementById("plusz").style.display = 'block'
folyamatidja = bejovoid
}
function tovabbhaz() {
if (((bevetelek.arany - 100) < 0) || ((bevetelek.ellatmany - 100) < 0)) {
alert("nincs elég Aranyad és/vagy Ellátmányod")
return false
}
bevetelek.arany -= 100
bevetelek.ellatmany -= 100
document.getElementById("plusz").style.display = 'none'
let bejovoid = folyamatidja
let alap = document.getElementById(bejovoid)
let svg = document.getElementById("svg")
svg.innerHTML += '<g id="' + bejovoid + 'haza" onclick="adogyujt(this.id)" title="Ház"> \
<rect \
fill="green" \
stroke="black" \
stroke-width="5" \
width="60" \
height="60" \
x="' + Number(alap.x.baseVal.value + 0) + '" \
y="' + Number(alap.y.baseVal.value + 0) + '" \
/> \
<rect \
fill="'+ beallitasok.trend.hazszine +'" \
width="40" \
height="40" \
x="' + Number(alap.x.baseVal.value + 10) + '" \
y="' + Number(alap.y.baseVal.value + 10) + '" \
stroke="black" \
stroke-width="5" /> \
<line x1="' + Number(alap.x.baseVal.value + 30) + '" y1="' + Number(alap.y.baseVal.value + 10) + '" x2="' + Number(alap.x.baseVal.value + 30) + '" y2="' + Number(alap.y.baseVal.value + 50) + '" stroke="black" stroke-width="5" /> \
<rect \
width="10" \
height="10" \
x="' + Number(alap.x.baseVal.value + 35) + '" \
y="' + Number(alap.y.baseVal.value + 25) + '" /> \
\
</g>'
let haz = {}
haz.id = bejovoid + "haza"
hazak.push(haz)
adogyujt(haz.id)
}
function tovabbvar() {
if (((bevetelek.arany - 300) < 0) || ((bevetelek.ellatmany - 300) < 0)) {
alert("nincs elég Aranyad és/vagy Ellátmányod")
return false
}
bevetelek.arany -= 300
bevetelek.ellatmany -= 300
document.getElementById("plusz").style.display = 'none'
let bejovoid = folyamatidja
let alap = document.getElementById(bejovoid)
let svg = document.getElementById("svg")
svg.innerHTML += '<g id="' + bejovoid + 'vara" onclick="varmenu(this.id)"> \
<rect \
y="' + Number(alap.y.baseVal.value + 0) + '" \
x="' + Number(alap.x.baseVal.value + 0) + '" \
height="60" \
width="60" \
fill="green" \
stroke="black" \
stroke-width="2"/> \
<rect \
y="' + Number(alap.y.baseVal.value + 5) + '" \
x="' + Number(alap.x.baseVal.value + 5) + '" \
height="50" \
width="50" \
fill="gray" \
stroke="black" \
stroke-width="2"/> \
<rect \
y="' + Number(alap.y.baseVal.value + 0) + '" \
x="' + Number(alap.x.baseVal.value + 0) + '" \
height="15" \
width="15" \
fill="gray" \
stroke="black" \
stroke-width="2"/> \
\
<rect \
y="' + Number(alap.y.baseVal.value + 45) + '" \
x="' + Number(alap.x.baseVal.value + 0) + '" \
height="15" \
width="15" \
fill="gray" \
stroke="black" \
stroke-width="2"/> \
\
<rect \
y="' + Number(alap.y.baseVal.value + 0) + '" \
x="' + Number(alap.x.baseVal.value + 45) + '" \
height="15" \
width="15" \
fill="gray" \
stroke="black" \
stroke-width="2"/> \
<rect \
y="' + Number(alap.y.baseVal.value + 45) + '" \
x="' + Number(alap.x.baseVal.value + 45) + '" \
height="15" \
width="15" \
fill="gray" \
stroke="black" \
stroke-width="2"/> \
\
<rect \
y="' + Number(alap.y.baseVal.value + 0) + '" \
x="' + Number(alap.x.baseVal.value + 25) + '" \
height="10" \
width="10" \
fill="gray" \
stroke="black" \
stroke-width="2"/> \
<rect \
y="' + Number(alap.y.baseVal.value + 25) + '" \
x="' + Number(alap.x.baseVal.value + 0) + '" \
height="10" \
width="10" \
fill="gray" \
stroke="black" \
stroke-width="2"/> \
<rect \
y="' + Number(alap.y.baseVal.value + 25) + '" \
x="' + Number(alap.x.baseVal.value + 50) + '" \
height="10" \
width="10" \
fill="gray" \
stroke="black" \
stroke-width="2"/> \
<rect \
y="' + Number(alap.y.baseVal.value + 50) + '" \
x="' + Number(alap.x.baseVal.value + 25) + '" \
height="10" \
width="10" \
fill="gray" \
stroke="black" \
stroke-width="2"/> \
</g>'
let vár = {}
vár.id = bejovoid + "vara"
vár.katona = 0
varak.push(vár)
ment()
}
function tovabbmuhely() {
if (((bevetelek.arany - 100) < 0) || ((bevetelek.ellatmany - 100) < 0)) {
alert("nincs elég Aranyad és/vagy Ellátmányod")
return false
}
bevetelek.arany -= 100
bevetelek.ellatmany -= 100
document.getElementById("plusz").style.display = 'none'
let bejovoid = folyamatidja
let alap = document.getElementById(bejovoid)
let svg = document.getElementById("svg")
svg.innerHTML += '<g id="' + bejovoid + 'muhelye" onclick="ellatmanygyujt(this.id)"> \
<rect \
fill="green" \
stroke="black" \
stroke-width="5" \
width="60" \
height="60" \
x="' + Number(alap.x.baseVal.value) + '" \
y="' + Number(alap.y.baseVal.value) + '" \
/> \
<rect \
fill="brown" \
width="40" \
height="40" \
x="' + Number(alap.x.baseVal.value + 10) + '" \
y="' + Number(alap.y.baseVal.value + 10) + '" \
stroke="black" \
stroke-width="5" /> \
<line x1="' + Number(alap.x.baseVal.value + 30) + '" y1="' + Number(alap.y.baseVal.value + 10) + '" x2="' + Number(alap.x.baseVal.value + 30) + '" y2="' + Number(alap.y.baseVal.value + 50) + '" stroke="black" stroke-width="5" /> \
<rect \
width="10" \
height="10" \
x="' + Number(alap.x.baseVal.value + 35) + '" \
y="' + Number(alap.y.baseVal.value + 25) + '" /> \
\
</g>'
let haz = {}
haz.id = bejovoid + "muhelye"
muhelyek.push(haz)
ellatmanygyujt(haz.id)
}