summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriainp5 <iain.pearce.ip@gmail.com>2024-06-27 09:02:19 +0100
committerGitHub <noreply@github.com>2024-06-27 09:02:19 +0100
commit0debf00f1c5c4251b4c43b9e1c9de902b100fcfb (patch)
tree2613365bfbb1eaefb9a06fdbebb3f1abb65dd151
parent603f2cb1e9784b38d03b7ddf925d0a0d46eacee8 (diff)
download1989-dawn-of-freedom-0debf00f1c5c4251b4c43b9e1c9de902b100fcfb.tar.gz
Feat: removed game mechanics
-rw-r--r--play.js464
1 files changed, 7 insertions, 457 deletions
diff --git a/play.js b/play.js
index d838f84..27692bc 100644
--- a/play.js
+++ b/play.js
@@ -78,8 +78,8 @@ function createMap() {
spaceArea.style.top = y + 'px';
spaceArea.style.width = w + 'px';
spaceArea.style.height = h + 'px';
- spaceArea.addEventListener('click', changeInfl)
- spaceArea.addEventListener('click', finishSupportCheck)
+ //spaceArea.addEventListener('click', changeInfl)
+ //spaceArea.addEventListener('click', finishSupportCheck)
/*if (space.demInfl > 0 && space.demInfl - space.comInfl >= space.stability) {
const img = document.createElement('img')
@@ -126,462 +126,12 @@ function createMap() {
});
}
-
+//setup()
createMap()
console.log('Hello')
-console.log(game)
-
-function changeInfl() {}
-function finishSupportCheck() {}
-
-
-/* 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 => {
- if (card < 100) {
- const img = document.createElement('img')
- img.src = `cards/e${card}.gif`
- img.className='handCard'
- img.alt = `Card ${card}`
- img.addEventListener('click', playCard)
- handDiv.appendChild(img)
- }
- else {
- const img = document.createElement('img')
- img.src = `cards2/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')
-
- if (playedCard<100) {
- activeCard.src = `cards/e${playedCard}.gif`
- } else {
- activeCard.src = `cards2/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)
+console.log('game:',game)
+console.log('strategy deck', game.strategy_deck)
- 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;
-}
+//function changeInfl() {}
+//function finishSupportCheck() {}
-startNewRound()
-*/