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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
|
const dem = 0
const com = 1
const dem_name= "Democrat"
const com_name= "Communist"
const stability=0
const US_tiananmen=0
const USSR_tiananmen=0
const toolbar = document.getElementById('toolbar')
const vpMarker = document.getElementById('vp')
const mapContainer = document.querySelector('.map')
let handActive=0
let doInfl=0
let doSupportCheck=0
let availableOps=0
let demTSTPos=0
let comTSTPos=0
let demTSTPrev=0
let comTSTPrev=0
let turn=1
let actionRound=1
let supportCheckTargetName=''
let supportCheckTargetCountry=0
let vp = 0
let germanyRevolution=0
let polandRevolution=0
let czechRevolution=0
let hungaryRevolution=0
let romaniaRevolution=0
let buglariaRevolution=0
let germanyHeld=0
let polandHeld=0
let czechHeld=0
let hungaryHeld=0
let romaniaHeld=0
let bulgariaHeld=0
const countryNames= [
null,
"East Germany",
"Poland",
"Czechoslovakia",
"Hungary",
"Romania",
"Bulgaria"
]
const overlay = document.getElementById('overlay');
const spaceNameElement = document.getElementById('space-name');
const spaceCharacteristicsElement = document.getElementById('space-characteristics');
// Event listener to track mouse movement over the map
document.querySelector('.map').addEventListener('mousemove', function(event) {
const x = event.offsetX; // X-coordinate of mouse relative to container
const y = event.offsetY; // Y-coordinate of mouse relative to container
spaceCharacteristicsElement.innerText = `X: ${x}, Y: ${y}`;
})
// Create map areas dynamically based on coordinates
function createMap() {
mapContainer.querySelectorAll('.space-area').forEach(spaceArea => {
spaceArea.remove()
})
spaces.forEach((space) => {
if (space && space.box) {
const { x, y, h, w } = space.box;
const spaceArea = document.createElement('div');
spaceArea.classList.add('space-area', space.country)
spaceArea.id=space.name;
spaceArea.style.left = x + 'px';
spaceArea.style.top = y + 'px';
spaceArea.style.width = w + 'px';
spaceArea.style.height = h + 'px';
spaceArea.addEventListener('click', changeInfl)
spaceArea.addEventListener('click', finishSupportCheck)
spaceArea.querySelectorAll('img').forEach(img => {
img.remove();
});
spaceArea.querySelectorAll('p').forEach(p => {
p.remove();
});
if (space.demInfl > 0 && space.demInfl - space.comInfl >= space.stability) {
const img = document.createElement('img')
img.classList.add('demInfl', space.country)
img.id=space.name
img.src = `images/US_${space.demInfl}.gif`
spaceArea.appendChild(img)
} else if (space.demInfl > 0) {
const img = document.createElement('img')
img.classList.add('demInfl', space.country)
img.id=space.name
img.src = `images/USd_blank.gif`
spaceArea.appendChild(img)
const demInflValue = document.createElement('p')
demInflValue.className='demInflValue'
demInflValue.id=space.name
demInflValue.innerText=space.demInfl
spaceArea.appendChild(demInflValue)
}
spaceArea.querySelectorAll('img.comInfl').forEach(img => {
img.remove(); })
if (space.comInfl === 0) {
spaceArea.querySelectorAll('img.comInfl').forEach(img => {
img.remove(); })
} else if (space.comInfl > 0 && space.comInfl - space.demInfl >= space.stability) {
const img = document.createElement('img')
img.className='comInfl'
img.id=space.name
img.src = `images/SV_${space.comInfl}.gif`
spaceArea.appendChild(img)
} else if (space.comInfl > 0) {
const img = document.createElement('img')
img.className='comInfl'
img.id=space.name
img.src = `images/SVd_blank.gif`
spaceArea.appendChild(img)
const comInflValue = document.createElement('p')
comInflValue.className='comInflValue'
comInflValue.id=space.name
comInflValue.innerText=space.comInfl
spaceArea.appendChild(comInflValue)
}
mapContainer.appendChild(spaceArea);
}
});
}
/* Create hands */
const handLimit = 8;
const comHandLimit = 8; //Will be needed for Presidential Visit
const hand =[];
const discard =[];
/* Step 1 create a draw deck */
const deck = cards
.filter(card => card.period === 1)
.map(card => card.number);
console.log(deck);
function drawCards(deck, handLimit) {
while (hand.length < handLimit && deck.length >0) {
let randomIndex = Math.floor(Math.random()*deck.length);
let drawnCard = deck.splice(randomIndex, 1)[0];
hand.push(drawnCard)
}
console.log('Hand: ', hand)
}
drawCards(deck, handLimit);
function displayHand(hand) {
const handDiv = document.getElementById('hand');
hand.forEach(card => {
const img = document.createElement('img')
img.src = `images/e${card}.gif`
img.className='handCard'
img.alt = `Card ${card}`
img.addEventListener('click', playCard)
handDiv.appendChild(img)
})
}
displayHand(hand);
/*---------- INFLUENCE ON THE BOARD ---------------*/
/*---------- INITIALIZE GAME ---------------*/
function startNewRound() {
toolbar.querySelectorAll('button').forEach(button => {
button.remove();
});
createMap()
const prompt = document.createElement('p');
prompt.textContent = 'Select a card';
prompt.id='prompt';
toolbar.appendChild(prompt);
handActive=1;
}
function playCard(event) {
if (handActive===1) {
/* Update the toolbar */
toolbar.querySelectorAll('button').forEach(button => {
button.remove();
});
clearPrompt()
const buttonOps = document.createElement('button');
buttonOps.textContent = 'Add Influence';
buttonOps.id='button';
buttonOps.onclick = influence;
toolbar.appendChild(buttonOps);
const buttonEvent = document.createElement('button');
buttonEvent.textContent = 'Play for event';
buttonEvent.id='button';
buttonEvent.onclick = event;
toolbar.appendChild(buttonEvent);
const buttonSC = document.createElement('button');
buttonSC.textContent = 'Play for a Support Check';
buttonSC.id='button';
buttonSC.onclick = supportCheck;
toolbar.appendChild(buttonSC);
const buttonTian = document.createElement('button');
buttonTian.textContent = 'Play to the Tiananmen Square Track';
buttonTian.id='button';
buttonTian.onclick = tiananmenSquareTrack;
toolbar.appendChild(buttonTian);
const buttonPoland = document.createElement('button');
buttonPoland.textContent = 'Score Poland';
buttonPoland.id='button';
buttonPoland.onclick = scorePoland;
toolbar.appendChild(buttonPoland);
/* Update the hand */
const getLink = event.target.src;
const match = getLink.match(/\/e(\d+)\.gif$/);
const playedCard = parseInt(match[1]);
//const playedCard = parseFloat(event.target.src.split('e')[1].split('.gif')[0]);
console.log('playedCard: ', playedCard)
console.log('match: ', match)
console.log('playedCard: ', playedCard)
const indexToRemove = hand.indexOf(playedCard);
if (indexToRemove !== -1) {
hand.splice(indexToRemove, 1);
discard.push(playedCard);
event.target.remove();
handActive=0;
availableOps=getOpsValue(playedCard)
console.log('Available ops: ', availableOps)
const playedCardName=getCardName(playedCard)
console.log('Played card name: ', playedCardName)
const eventPanel = document.getElementById('events');
const activeCard = document.createElement('img')
activeCard.src = `images/e${playedCard}.gif`
activeCard.className='playedCard'
activeCard.alt = `Card ${playedCard}`
eventPanel.appendChild(activeCard)
}
console.log('New Hand:', hand);
console.log('Discard:', discard);
}
}
function influence() {
clearPrompt()
clearButtons()
const prompt=document.getElementById('prompt')
prompt.innerText='Add Influence'
doInfl=1
}
function getOpsValue(cardNumber) {
const cardOps = cards.find(card => card.number === cardNumber);
return cardOps ? cardOps.ops : null; // Return null if the card is not found
}
function getCardName(cardNumber) {
const cardName = cards.find(card => card.number === cardNumber);
return cardName ? cardName.name : null; // Return null if the card is not found
}
function rolld6() {
const d6 = Math.floor(Math.random()*6+1)
return d6;
}
function event() {}
function supportCheck() {
clearPrompt()
clearButtons()
const prompt=document.getElementById('prompt')
prompt.innerText='Select First Target'
doSupportCheck=2
}
function finishSupportCheck(event) {
if (doSupportCheck>0) {
doSupportCheck--
const roll = rolld6()
console.log('You rolled a: ',roll)
const spaceName = event.target.id;
console.log('spaceName: ', spaceName)
const spaceCountry = parseInt(event.target.classList[1]); // The country of the clicked space, 2nd element in the classList.
console.log('spaceCountry: ', spaceCountry)
const space = spaces.find(space => space && space.name === spaceName && space.country === spaceCountry); // Find the corresponding space object.
const stability=space.stability * 2
const supportCheckValue = availableOps + roll
const startingOppInf = space.comInfl
const initialChange = supportCheckValue - stability
console.log('support check value =',availableOps, ' ops + ', roll,' + from roll = ', supportCheckValue)
console.log('stability: ', stability)
console.log('change: ', initialChange)
console.log('starting opp inf: ', startingOppInf)
if (space) {
if (supportCheckValue > stability){
if (space.comInfl - initialChange >= 0) {
space.comInfl -=initialChange
console.log('new Com influence: ', space.comInfl)
} else {
space.comInfl = 0
console.log('new Com influence: ', space.comInfl)
const remainingChange = initialChange-startingOppInf
space.demInfl += remainingChange
}
}
}
const prompt=document.getElementById('prompt')
if (doSupportCheck===1) {
prompt.innerText='Select Second Target'
}
if (doSupportCheck===0) {
endRound()
}
createMap()
}
}
function tiananmenSquareTrack() {
clearButtons ()
const buttonRoll = document.createElement('button');
buttonRoll.textContent = 'Roll a Die';
buttonRoll.id='button';
buttonRoll.onclick = finishTiananmenSquareTrack;
toolbar.appendChild(buttonRoll);
}
function finishTiananmenSquareTrack() {
const demTSTMarker=document.getElementById('dem-TST')
const roll = rolld6()
console.log('You rolled a: ',roll)
const attemptTST = availableOps+roll+demTSTPrev
console.log('Total TST attempt value: ', attemptTST)
if (attemptTST >= demTST[demTSTPos]) {
console.log('TST success')
demTSTPos++
demTSTMarker.style.left=`38px`
} else {
console.log('TST fail')
demTSTPrev=1
}
clearButtons()
clearEvents()
const endRound = document.createElement('button');
endRound.textContent = 'End Action Round';
endRound.id='button';
endRound.onclick = endActionRound;
toolbar.appendChild(endRound);
}
function clearButtons () {
toolbar.querySelectorAll('button').forEach(button => {
button.remove();
});
}
function clearEvents () {
events.querySelectorAll('img').forEach(img => {
img.remove()
})
}
function clearPrompt() {
const prompt=document.getElementById('prompt')
prompt.innerText=''
}
function endActionRound() {
clearButtons()
clearEvents()
actionRound++
const actionRoundTracker=document.querySelector('.action-round-tracker')
const actionRoundPos= 511+actionRound*42
console.log('Action Round Position: ', actionRoundPos)
actionRoundTracker.style.left=actionRoundPos+'px'
startNewRound()
}
function changeInfl(event) {
if (availableOps>0 && doInfl===1) {
const spaceName = event.target.id;
console.log('spaceName: ', spaceName)
const spaceCountry = parseInt(event.target.classList[1]); // The country of the clicked space, 2nd element in the classList.
console.log('spaceCountry: ', spaceCountry)
const space = spaces.find(space => space && space.name === spaceName && space.country === spaceCountry); // Find the corresponding space object.
if (space) {
space.demInfl++
availableOps--
}
if (availableOps===0) {
clearPrompt()
endRound()
doInfl=0
}
}
createMap()
}
function endRound() {
clearPrompt()
clearButtons()
const endRound = document.createElement('button');
endRound.textContent = 'End Action Round';
endRound.id='button';
endRound.onclick = endActionRound;
toolbar.appendChild(endRound);
}
function scorePoland() {
let demVP = 0
let comVP = 0
const demPresence = spaces.filter(space => space && space.country === 2 && space.demCtrl === 1)
const comPresence = spaces.filter(space => space && space.country === 2 && space.comCtrl === 1)
if (demPresence.length>0) {
demVP+=3
}
if (comPresence.length>0) {
comVP+=3
}
const demBattlegroundCheck = spaces.filter(space => space && space.country === 2 && space.demCtrl === 1 && space.battleground === 1)
demBattlegrounds = demBattlegroundCheck.length
demVP += demBattlegrounds
const comBattlegroundCheck = spaces.filter(space => space && space.country === 2 && space.comCtrl === 1 && space.battleground === 1)
comBattlegrounds = demBattlegroundCheck.length
comVP += comBattlegrounds
const demDomination = demBattlegrounds > comBattlegrounds && demPresence > comPresence
const comDomination = comBattlegrounds > demBattlegrounds && comPresence > demPresence
if (demDomination) {
demVP += 3
}
if (comDomination) {
comVP += 3
}
const demControl = demBattlegrounds === 6 && demPresence > comPresence
const comControl = demBattlegrounds === 6 && comPresence > demPresence
if (demControl) {
demVP += 3
}
if (comControl) {
comVP += 3
}
if (polandRevolution===0) {
polandHeld++
comVP += polandHeld*3
const img = document.createElement('img')
img.classList.add('powerToken', 2)
img.src = `images/SV_1.gif`
mapContainer.appendChild(img)
}
changeVP = demVP - comVP
vp += changeVP
console.log('Democrats have presence: ', demPresence, ' ', demBattlegrounds, ' battlegrounds')
console.log('Democrat VP: ', demVP)
console.log('Communist VP: ', comVP)
console.log('change VP: ', changeVP)
console.log('VP: ', vp)
console.log('vp =ve odd: ', isPositiveAndOdd(vp))
const vpSteps = Math.ceil(Math.abs(vp)/2)
if (vp === 0) {
vpMarker.style.top = '1912px'
vpMarker.style.left = '661px'
} else if (isPositiveAndEven(vp)) {
vpMarker.style.top = '1937px'
const vpMarkerPos = 666 + vpSteps*50
vpMarker.style.left = vpMarkerPos + 'px'
} else if (isPositiveAndOdd(vp)) {
vpMarker.style.top = '1889px'
const vpMarkerPos = 642 + vpSteps*50
vpMarker.style.left = vpMarkerPos + 'px'
} else if (isNegativeAndEven(vp)) {
vpMarker.style.top = '1889px'
const vpMarkerPos = 656 - vpSteps*50
vpMarker.style.left = vpMarkerPos + 'px'
} else if (isNegativeAndOdd(vp)) {
vpMarker.style.top = '1937px'
const vpMarkerPos = 679 - vpSteps*50
vpMarker.style.left = vpMarkerPos + 'px'
}
createMap()
endRound()
}
function isPositiveAndEven(number) {
return number > 0 && number % 2 === 0;
}
function isPositiveAndOdd(number) {
return number > 0 && number % 2 !== 0;
}
function isNegativeAndEven(number) {
return number < 0 && number % 2 === 0;
}
function isNegativeAndOdd(number) {
return number < 0 && number % 2 !== 0;
}
startNewRound()
|