Skip to content

Commit

Permalink
Added tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorterrill committed Jul 8, 2016
1 parent 791c4e6 commit e62e230
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 41 deletions.
2 changes: 1 addition & 1 deletion client/public/build.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/public/build.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/public/build.js.map

Large diffs are not rendered by default.

Binary file added client/public/img/token-exhaust.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/public/img/token-first.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/public/img/token-status.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/public/img/token-wound.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions client/src/components/game/board.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@
justify-content:space-around;
}
.board__first {
display:inline-block;
vertical-align:top;
width: 100px;
height:140px;
img {
max-width:100%;
margin-top: 25px;
}
}
.board--opponent {
border-bottom:1px dashed #CCC;
}
Expand All @@ -50,6 +62,9 @@
<div class="board__row">
<stack type="discard" face="up" :cards="player.discard"></stack>
<stack type="deck" face="down" :cards="player.deck"></stack>
<div class="board__first" v-if="player.isFirstPlayer">
<img src="/img/token-first.png" title="First Player" />
</div>
</div>
<div class="board__row">
<stack type="conjurations" face="down" :cards="player.conjurations"></stack>
Expand Down
134 changes: 96 additions & 38 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function getGameName(gameId) {
return players.join(' vs. ');
}

// -----------------------------------------------------------[ GET GAME STATE ]
// -----------------------------------------------------------[ GET FULL GAME STATE ]
function getGameState(gameId) {
return activeGames[gameId];
}
Expand All @@ -139,6 +139,7 @@ function sendGameState(gameId) {
}

// -----------------------------------------------------------[ SEND ACTIONS ]
// update the actions menu for a player (or all players)
// playerSocketId is optional, if not sent it will go to all players in the game
function sendActions(gameId, action, playerSocketId) {

Expand All @@ -147,6 +148,7 @@ function sendActions(gameId, action, playerSocketId) {
case 'requestFirstFive':
_.each(activeGames[gameId].players, function(playerData, playerSocketId) {
activeGames[gameId].players[playerSocketId].actions = {
status: 'chooseFirstFive',
message: 'Choose your First Five by moving 5 cards from your deck into your hand.',
buttons: [{
text: 'Submit First Five',
Expand All @@ -158,6 +160,7 @@ function sendActions(gameId, action, playerSocketId) {

case 'firstFiveInvalid':
activeGames[gameId].players[playerSocketId].actions = {
status: 'chooseFirstFive',
message: 'Your First Five were invalid. Please re-submit.',
buttons: [{
text: 'Submit First Five',
Expand All @@ -167,18 +170,37 @@ function sendActions(gameId, action, playerSocketId) {
break;

case 'firstFiveValid':

activeGames[gameId].players[playerSocketId].actions = {
status: 'waitingFirstFive',
message: 'Your First Five were submitted. Waiting for your opponent(s).',
buttons: []
};
//check if we need to start play
advanceGameStatusWhenReady(gameId);
break;

case 'preparePhase':
_.each(activeGames[gameId].players, function(playerData, playerSocketId) {
activeGames[gameId].players[playerSocketId].actions = {
status: 'preparePhase',
message: 'PREPARE PHASE: Roll dice, discard cards, draw up to five.',
buttons: [{
text: 'Roll all dice',
action: 'rollAllDice'
}, {
text: 'Draw up to five',
action: 'drawToFive'
}]
};
});
break;

default:
activeGames[gameId].players[playerSocketId].actions = {
message: 'An error has occured.',
buttons: []
};

}

sendGameState(gameId);
Expand Down Expand Up @@ -224,6 +246,14 @@ function chatToGame(gameId, sender, msg) {
server.to(gameId).emit('chat');
}


// _____ __ __ ______ _____ ______ _______ _ _ _____
// / ____| /\ | \/ | ____| / ____| ____|__ __| | | | __ \
// | | __ / \ | \ / | |__ | (___ | |__ | | | | | | |__) |
// | | |_ | / /\ \ | |\/| | __| \___ \| __| | | | | | | ___/
// | |__| |/ ____ \| | | | |____ ____) | |____ | | | |__| | |
// \_____/_/ \_\_| |_|______| |_____/|______| |_| \____/|_|

// -----------------------------------------------------------[ VALIDATE DECKLIST ]
// Check the decklist, adding conjurations if needed
// If the deck is invalid, send an error
Expand Down Expand Up @@ -339,7 +369,7 @@ function validateDecklist(decklist, gameId, playerSocketId) {
buildDeck(decklist, gameId, playerSocketId);

//if this was the last decklist to be validated, we should start the game!
checkGameStatus(gameId);
advanceGameStatusWhenReady(gameId);

//add the modified decklist (w/conjurations added)
validationResults.decklist = JSON.stringify(decklist);
Expand Down Expand Up @@ -391,7 +421,7 @@ function buildDeck(decklist, gameId, playerSocketId) {
dice.push({
type: type,
face: 'basic',
exhausted: false
exhausted: true
});
}
});
Expand Down Expand Up @@ -445,6 +475,13 @@ function validateFirstFive(gameId, playerSocketId) {
return valid;
}

// _____ __ __ ______ _____ _______ _____ ____ _ _ _____
// / ____| /\ | \/ | ____| /\ / ____|__ __|_ _/ __ \| \ | |/ ____|
// | | __ / \ | \ / | |__ / \ | | | | | || | | | \| | (___
// | | |_ | / /\ \ | |\/| | __| / /\ \| | | | | || | | | . ` |\___ \
// | |__| |/ ____ \| | | | |____ / ____ \ |____ | | _| || |__| | |\ |____) |
// \_____/_/ \_\_| |_|______| /_/ \_\_____| |_| |_____\____/|_| \_|_____/

// -----------------------------------------------------------[ SHUFFLE ANY STACK OF CARDS ]
// randomizes the deck using the Fisher-Yates Shuffle (http://bost.ocks.org/mike/shuffle/)
function shuffleStack(stack) {
Expand Down Expand Up @@ -541,51 +578,72 @@ function moveCardTo(gameId, card, destinationType, destination, destinationOwner

}

// -----------------------------------------------------------[ CHECK GAME STATUS ]
// -----------------------------------------------------------[ ADVANCE GAME STATUS ]
// Compare number of players to max players to see if waiting
// If the status is changing, update the game round
function checkGameStatus(gameId) {
function advanceGameStatusWhenReady(gameId) {

//don't keep running this check if the game is already in play
if (activeGames[gameId].status === 'inPlay') {
return false;
}
//determine what to check based on current game status
switch (activeGames[gameId].status) {

var numPlayers = _.keys(activeGames[gameId].players).length;
var numReadyPlayers = 0;
case 'inPlay':
//if it's in play already, why are we even here?
return false;
break;

//if we have fewer than the player cap, we're waiting
if (activeGames[gameId].maxPlayers > numPlayers) {
activeGames[gameId].status = 'waiting';
} else {
//if we have the player cap, and everyone's validated their decklists, we're ready
_.each(activeGames[gameId].players, function(player, playerSocketId) {
if (player.deck && player.deck.length === 30) {
numReadyPlayers++;
}
});
case 'waiting':
//if we have fewer than the player cap, we're still waiting
var numPlayers = _.keys(activeGames[gameId].players).length;
if (activeGames[gameId].maxPlayers > numPlayers) {
//still waiting
return false;

if (numReadyPlayers === numPlayers) {

//initialize first five phase
if (activeGames[gameId].gameRound === -1) {
activeGames[gameId].gameRound = 0;
activeGames[gameId].status = 'firstFive';

//tell the players we need some action
sendActions(gameId, 'requestFirstFive');

} else {
//start the regular rounds
//if we have the player cap, check if everyone's validated their decklists
var numReadyPlayers = 0;
_.each(activeGames[gameId].players, function(player, playerSocketId) {
if (player.deck && player.deck.length === 30) {
numReadyPlayers++;
}
});

//all players are ready
if (numReadyPlayers === numPlayers) {
//initialize first five phase
if (activeGames[gameId].gameRound === -1) {
activeGames[gameId].gameRound = 0;
activeGames[gameId].status = 'firstFive';

//tell the players we need some action
sendActions(gameId, 'requestFirstFive');
}
}
}
break;

case 'firstFive':
//check if everyone's submitted their first five
var allFirstFivesValidated = true;
_.each(activeGames[gameId].players, function(playerData, playerSocketId) {
if (activeGames[gameId].players[playerSocketId].actions.status !== 'waitingFirstFive') {
allFirstFivesValidated = false;
}
});

if (allFirstFivesValidated) {
//move on to first round
activeGames[gameId].gameRound = 1;
activeGames[gameId].status = 'inPlay';

//tell the players we need some action
sendActions(gameId, 'preparePhase');
}
break;

} else {
//players are choosing their decks
activeGames[gameId].status = 'setup';
}
default:
break;
}

}


Expand Down Expand Up @@ -664,7 +722,7 @@ server.on('connection', function(socket){
activeGames[gameId].gameName = getGameName(gameId);

//if we have enough players to begin it's go time
checkGameStatus(gameId);
advanceGameStatusWhenReady(gameId);

//send the updated game list to everyone
server.emit('gameList', getGameList());
Expand Down

0 comments on commit e62e230

Please sign in to comment.