TM Again
by Sam Fereday
JavaScript
/// Turn taking and card data
// Card
var Card = function(){
this.x = 0;
this.y = 0;
this.claimed = false;
this.used = false;
};
// Some cards for each player
var aCards = [new Card, new Card, new Card];
var bCards = [new Card, new Card, new Card];
// Players constructor
var Actor = function(){
this.isTurn = 0;
};
// Some players
var a = new Actor;
a.name = "a";
a.cards = aCards;
var b = new Actor;
b.name = "b";
b.cards = bCards;
// An array to hold them
var actArray = [a, b];
var currentPlayer, lastPlayer;
// Get someone to take a turn
var flag = 1;
function turnTaker()
{
if(currentPlayer.name === lastPlayer.name) {
console.log("Something very bad just happened.");
return;
}
flag *= -1;
currentPlayer = flag > 0 ? actArray[0] : actArray[1];
lastPlayer = currentPlayer;
}
/// Grid placement and battle stuff
/*
let's make this easy and use cardinals for now.
So you place a card.
Card gets a score.
Score determines direction checked.
If direction checked has a card that isn't ours, we battle it.
*/
var cols = 3;
var rows = 3;
var gridCache = [];
var GridTile = function(){
this.x = x;
this.y = y;
this.occupied = false;
this.occupiedByCard = false;
this.ownerId = "";
this.click = function(currentCard, currentUser){
if(placeMode && !this.occupied) {
this.occupied = true;
this.occupiedByCard = currentCard;
this.ownerId = currentUser.id;
currentCard.used = true;
// ... apply a card sprite to cell also (duplicate from card list)
}
};
};
// Generate the grid
for(var i = 0; i < cols; i++) {
for(var j = 0; j < rows; j++) {
var t = new GridTile();
t.x = i;
t.y = j;
gridCache.push(t);
}
}
function validTile(x, y) {
return gridCache[x][y] || {};
}
// Battle stuff
var battleCache = []; // Empties each time a player has their turn.
function placedAt(card, x, y) {
// Reset cache queue
battleCache.length = 0;
//...