Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scoring system and scoreboard implementation #74

Merged
merged 1 commit into from Jun 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions contracts.js
Expand Up @@ -123,6 +123,7 @@ let tradeContracts = {
this.contractsArray[chosenFort].contracts[deliveryGoods].team = gameManagement.turn;
this.contractsArray[chosenFort].totalOpen -=1;
this.contractsArray[chosenFort].totalActive +=1;

},

// Method to track continuance and countdown of contract
Expand All @@ -143,6 +144,9 @@ let tradeContracts = {
IDtradeRoute = resourceManagement.resourcePieces[l].goods + '_' + k;
let closedTradeRoute = document.getElementById(IDtradeRoute);
closedTradeRoute.remove();
// Remove score from team
gameScore.workScores('Trading', gameManagement.turn, this.contractsArray[k].name, ((this.contractsArray[k].contracts[resourceManagement.resourcePieces[l].goods].contractPath.length - 1) * -1) );
// Reset contractsArray
this.contractsArray[k].contracts[resourceManagement.resourcePieces[l].goods] = {created: false, struck: 'unopen', team: 'none', initial: 0, renewal: 0, timeRemaining: 0};
this.contractsArray[k].totalActive -=1;
this.contractsArray[k].totalUnopen +=1;
Expand Down Expand Up @@ -285,11 +289,12 @@ let tradeContracts = {
this.contractsArray[chosenFort].contracts[localGoods].resourceRow = localStartRow;
this.contractsArray[chosenFort].contracts[localGoods].resourceCol = localStartCol;
this.contractsArray[chosenFort].contracts[localGoods].contractPath = localPath;
console.log(this.contractsArray[chosenFort]);

// creates the SVG path for the trade route
gameBoard.tradeRoute(localPath, gameManagement.turn, chosenFort, localGoods);

// Processes the score (all the information is in this method)
gameScore.workScores('Trading', gameManagement.turn, this.contractsArray[chosenFort].name, this.tradePath[harbour.harbourEndRow][harbour.harbourEndCol].distance);
},

// Method to seacrh for route around obstacles
Expand Down Expand Up @@ -447,7 +452,6 @@ let tradeContracts = {
// ---------------------------------------------------------

drawContracts: function() {
console.log(this.contractsArray);
if(workFlow == 1) {console.log('Contracts (right) dashboard drawn: ' + (Date.now() - launchTime)); }
// Finds the stockDashboard holder in the left hand panel
let contractDashboardNode = document.querySelector('div.contractDashboard');
Expand Down Expand Up @@ -477,7 +481,6 @@ let tradeContracts = {
} else {

for (var j = 0; j < resourceManagement.resourcePieces.length; j++) {
//console.log(this.contractsArray[i].contracts[resourceManagement.resourcePieces[j].goods].created);
if(this.contractsArray[i].contracts[resourceManagement.resourcePieces[j].goods].created) {

// Div to hold contract is created and icon added
Expand Down Expand Up @@ -525,6 +528,7 @@ let tradeContracts = {
}
}
}
console.log(this.contractsArray);
},


Expand Down
6 changes: 1 addition & 5 deletions dashboard.js
Expand Up @@ -58,7 +58,7 @@ let stockDashboard = {
stockDashboard.pieceTotals[h].pieces[stockDashboard.pieceTypes[k].type] = {quantity: counter, goods: piecesGoods, stock: piecesStock};
}
}
console.log('pieceTotals', stockDashboard.pieceTotals);
//console.log('pieceTotals', stockDashboard.pieceTotals);
},

// Method to populate stock dashboard on left-hand panel
Expand Down Expand Up @@ -164,7 +164,6 @@ let stockDashboard = {
if (this.pieceTypes[k].category == 'Transport') {
//divTypeIcon.setAttribute('class', additionalClass);
divTypeIcon.classList.add(additionalClass);
console.log(divTypeIcon.classList);
}
divType.appendChild(divTypeIcon);

Expand Down Expand Up @@ -199,9 +198,6 @@ let stockDashboard = {
for (var h = 0; h < gameManagement.teamArray.length; h++) {
this.goodsTotals.push({team: gameManagement.teamArray[h], land: {wood: 0, iron: 0, stone: 0}, sea: {wood: 0, iron: 0, stone: 0}, total: {wood: 0, iron: 0, stone: 0}});
}
console.log(this.goodsTotals);
console.log(this.pieceTypes[0].goods);
console.log(this.goodsTotals[0].land[this.pieceTypes[0].goods]);
},

goodsStockTake: function() {
Expand Down
3 changes: 1 addition & 2 deletions gamemanagement.js
@@ -1,5 +1,4 @@
// Game management object
// A very basic starting point just allowing simple rotation of turns

let gameManagement = {

Expand Down Expand Up @@ -62,7 +61,7 @@ let gameManagement = {
// --------------------
optionsArray: [
{ variable: 'speed', active: 'fast', options: [{text: 'slow', active: false, constant: 1.5}, {text: 'medium', active: false, constant: 1}, {text: 'fast', active: true, constant: 0.6}] },
{ variable: 'dev', options: [{text: 'workflow', active: true}, {text: 'transitions', active: false}] },
{ variable: 'dev', options: [{text: 'workflow', active: false}, {text: 'transitions', active: false}] },
],


Expand Down
6 changes: 5 additions & 1 deletion index.html
Expand Up @@ -23,7 +23,8 @@

<!-- Fixed header with padding underneath-->
<div class="the_header over_text top">

<div class="scoreBoard">
</div>
</div>

<!-- Corners added to allow side panels to be exandable -->
Expand Down Expand Up @@ -136,6 +137,9 @@
<!-- The building object -->
<script src='build.js'></script>

<!-- The building object -->
<script src='scoring.js'></script>

<!-- The main javascript file -->
<script src='main.js'></script>

Expand Down
16 changes: 13 additions & 3 deletions main.js
Expand Up @@ -55,15 +55,18 @@ for (var a = 0; a < sideCollection.length; a++) {
sideCollection[a].style.fontSize = (0.6 * screenReduction) + 'em';
}

let headFootCollection = document.querySelectorAll(' .the_header, .the_footer, .commentary, .building');

let headFootCollection = document.querySelectorAll('.the_header, .the_footer, .commentary, .building');
for (var c = 0; c < headFootCollection.length; c++) {

headFootCollection[c].style.width = (screenWidth - 2*surroundSize) + 'px';
headFootCollection[c].style.left = surroundSize + 'px';
headFootCollection[c].style.fontSize = (0.8 * screenReduction) + 'em';
}

let scoreHeader = document.querySelector('.the_header');
scoreHeader.style.fontSize = (0.6 * screenReduction) + 'em';
scoreHeader.style.top = '-15%';

// Setting up game layers

// boardMarkNode is board holder in document
Expand Down Expand Up @@ -92,6 +95,9 @@ boardMarkNode.appendChild(moonLayer);
// Finds the stockDashboard holder in the left hand panel
let stockDashboardNode = document.querySelector('div.stockDashboard');

// Finds the stockDashboard holder in the left hand panel
let scoreBoardNode = document.querySelector('div.scoreBoard');

// Function to set up board and resource deck and allocate resources
function boardSetUp(row, col, gridSize, boardShape) {
gameBoard.populateBoardArray(row, col, boardShape);
Expand Down Expand Up @@ -218,9 +224,10 @@ function nextTurn() {
needleDirection = compass.directionArray[windDirection].needle;
needle.style.transform = 'rotate(' + needleDirection + 'deg)';

// Comment and building bars reset
// Comment and building and scoreboard bars reset
commentary.style.bottom = '-10%';
building.style.bottom = '-15%';
scoreHeader.style.top = '-15%';

// End turn button colour is changed
endTurn.setAttribute('class', gameManagement.turn + ' team_fill team_stroke');
Expand Down Expand Up @@ -479,6 +486,7 @@ function boardHandler(event) {
firstLineComment.insertAdjacentText('beforeend', ' - ' + pieceMovement.movementArray[startEnd].pieces.goods + ": " + pieceMovement.movementArray[startEnd].pieces.stock);
}
building.style.bottom = '-15%';
scoreHeader.style.top = '-15%';
commentary.style.bottom = 0;

// commentary event handler for goods
Expand Down Expand Up @@ -582,6 +590,7 @@ function boardHandler(event) {
boardMarkNode.appendChild(gameBoard.createActionTile(pieceMovement.movementArray.start.row, pieceMovement.movementArray.start.col, gameBoard.boardArray[pieceMovement.movementArray.start.row][pieceMovement.movementArray.start.col].pieces.type, gameBoard.boardArray[pieceMovement.movementArray.start.row][pieceMovement.movementArray.start.col].pieces.team,
'tile' + Number((pieceMovement.movementArray.start.row)*1000 + (pieceMovement.movementArray.start.col)), boardSurround + tileBorder/2 + (gridSize + tileBorder * 2) * pieceMovement.movementArray.start.row, boardSurround + tileBorder/2 + (gridSize + tileBorder * 2) * pieceMovement.movementArray.start.col, 1, gameBoard.boardArray[pieceMovement.movementArray.start.row][pieceMovement.movementArray.start.col].pieces.direction));
startEnd = 'start';
gameScore.workScores('Exploring', gameManagement.turn, pieceMovement.movementArray.start.pieces.type);

// Loading of goods
} else if ((pieceMovement.movementArray.start.pieces.category == 'Resources' || pieceMovement.movementArray.start.pieces.category == 'Settlements') && pieceMovement.movementArray.end.pieces.category == 'Transport') {
Expand Down Expand Up @@ -636,6 +645,7 @@ function boardHandler(event) {
gameBoard.repairShip(newShip, gameManagement.turn, pieceMovement.movementArray.start.pieces.type, 3);
}
buildItem.constructionPayment(pieceMovement.movementArray.start.pieces.type);
gameScore.workScores('Building', gameManagement.turn, pieceMovement.movementArray.start.pieces.type);
// Piece movement
} else if (pieceMovement.movementArray.start.pieces.category == 'Transport') {
endTurn.removeEventListener('click', nextTurn);
Expand Down
6 changes: 2 additions & 4 deletions movement.js
Expand Up @@ -67,7 +67,6 @@ let pieceMovement = {
//if (displayActive) {
// gameBoard.boardArray[localStartRow][localStartCol].activeStatus = 'inactive';
//}
console.log('completed find path slice', this.findPath.slice(0));
},

initialisefindPath: function(localStartRow, localStartCol) {
Expand Down Expand Up @@ -460,10 +459,9 @@ let pieceMovement = {
if(gameBoard.boardArray[this.movementArray.end.row+i][this.movementArray.end.col+j].terrain == 'land' && !gameBoard.boardArray[this.movementArray.end.row+i][this.movementArray.end.col+j].pieces.populatedSquare) {
// If so - picks a reource card type using resourceManagement.pickFromResourceDeck() and updates boardArray to this tile tile with unoccupied team
deckCard = resourceManagement.pickFromResourceDeck();
console.log(deckCard);
//randomProduction = Math.floor(Math.random() * (deckCard.maxProduction)) + 1;
gameBoard.boardArray[this.movementArray.end.row+i][this.movementArray.end.col+j].pieces = {populatedSquare: true, category: 'Resources', type: deckCard.type, direction: '0', used: 'unused', damageStatus: 5, team: 'Unclaimed', goods: deckCard.goods, stock: 0, production: deckCard.production};
console.log(gameBoard.boardArray[this.movementArray.end.row+i][this.movementArray.end.col+j]);
let randomStock = Math.floor(Math.random() * 3);
gameBoard.boardArray[this.movementArray.end.row+i][this.movementArray.end.col+j].pieces = {populatedSquare: true, category: 'Resources', type: deckCard.type, direction: '0', used: 'unused', damageStatus: 5, team: 'Unclaimed', goods: deckCard.goods, stock: randomStock, production: deckCard.production};
// and then creates an SVG resource tile for the land space
boardMarkNode.appendChild(gameBoard.createActionTile(this.movementArray.end.row+i, this.movementArray.end.col+j, gameBoard.boardArray[this.movementArray.end.row+i][this.movementArray.end.col+j].pieces.type, gameBoard.boardArray[this.movementArray.end.row+i][this.movementArray.end.col+j].pieces.team,
'tile' + Number((this.movementArray.end.row+i)*1000 + (this.movementArray.end.col+j)), boardSurround + tileBorder/2 + (gridSize + tileBorder * 2) * (this.movementArray.end.row+i), boardSurround + tileBorder/2 + (gridSize + tileBorder * 2) * (this.movementArray.end.col+j), 1, gameBoard.boardArray[this.movementArray.end.row+i][(this.movementArray.end.col+j)].pieces.direction));
Expand Down
4 changes: 4 additions & 0 deletions pieces.css
Expand Up @@ -402,6 +402,7 @@
}

.Blue.team_stroke {
color: #0099cc;
stroke: #00394d;
}

Expand All @@ -416,6 +417,7 @@
}

.Orange.team_stroke {
color: #bd5d0f;
stroke: #472306;
}

Expand All @@ -429,6 +431,7 @@
}

.Red.team_stroke {
color: #a52746;
stroke: #3e0f1a;
}

Expand All @@ -442,6 +445,7 @@
}

.Green.team_stroke {
color: #34987d;
stroke: #14392f;
}

Expand Down
3 changes: 0 additions & 3 deletions resource.js
Expand Up @@ -37,13 +37,10 @@ let resourceManagement = {
}

let numberDesert = unoccupiedIslands - unDesertCount;
//console.log(numberDesert);

for (var j = 0; j < numberDesert; j++) {
this.resourceDeck.push({type: 'desert', goods: 'none'});
}
console.log(this.resourceDeck);

},

// Method to find total number of unoccupied land tiles on board at start
Expand Down