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

added draw all and sort in case of decks.length > 1 #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ DECK_DEFINITONS =
{ name: "Ancient Artillery"
, cards:
[ [false, "46", "* %attack% -1", "** %range% +2"]
, [true, "71", "* %attack% +0", "** All adjacent enemies suffer 2 dammage"]
, [true, "71", "* %attack% +0", "** All adjacent enemies suffer 2 dammage"]
, [true, "71", "* %attack% +0", "** All adjacent enemies suffer 2 damage"]
, [true, "71", "* %attack% +0", "** All adjacent enemies suffer 2 damage"]
, [false, "37", "* %push% 1", "** Target all adjacent enemies", "* %attack% -1", "** %range% -1", "** Area effect"]
, [false, "37", "* %push% 1", "** Target all adjacent enemies", "* %attack% -1", "** %range% -1", "** Area effect"]
, [false, "17", "* %push% 2", "** Target all adjacent enemies", "* %shield% 2", "* %attack% -2"]
Expand Down Expand Up @@ -350,6 +350,17 @@ DECK_DEFINITONS =
}
];

//proposal how to shape up the stats
ENEMIES = [
{ name: "Inox Archer"
,levels:[
["2", "2", "3", "1", "0"] //lvl 0 stats (move, attack, range, shield, retaliate)
,["2", "2", "3", "1", "0"] //lvl 1 stats
]
,deck: "Archer"
}
];


// empty template
/*
Expand Down
58 changes: 51 additions & 7 deletions logic.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@

var do_shuffles = true;

function UICard(front_element, back_element)
function UICard(front_element, back_element, initiative)
{
var card = {};

card.back = back_element;
card.front = front_element;
card.initiative = initiative;

card.flip_up = function(faceup)
{
Expand Down Expand Up @@ -166,7 +167,7 @@ function load_deck(deck_definition)
var card_back = create_card_back(deck_definition.name);

var card = {
ui: new UICard(card_front, card_back),
ui: new UICard(card_front, card_back, initiative),
shuffle_next: shuffle
};

Expand Down Expand Up @@ -240,14 +241,38 @@ function must_reshuffle(deck)
}
}

//function to draw all cards at once for the round (reshuffles are now automatic and not an additional click, otherwise it doesn't work...)
function draw_cards(decks)
{
var container = document.getElementById("tableau");
var items = [];
for(var i = 0; i < decks.length; i++){
var init = draw_card(decks[i]);
deckContainer = document.getElementById(decks[i].name);
container.removeChild(deckContainer);
items.push({el: deckContainer, initiative: init});
}

//sorting decks to show them in order of initiative.
items.sort(function(a, b){
return a.initiative - b.initiative;
});
//re-adding them in order
for(var i = 0; i < items.length; i++){
container.appendChild(items[i].el);
}

}


function draw_card(deck)
{
if (must_reshuffle(deck))
{
reshuffle(deck);
}
else
{


for (var i = 0; i < deck.discard.length; i++)
{
var card = deck.discard[i];
Expand All @@ -268,7 +293,9 @@ function draw_card(deck)
card.ui.removeClass("draw");
card.ui.addClass("discard");
deck.discard.unshift(card);
}

return parseInt(card.ui.initiative);

}

function load(card_database)
Expand Down Expand Up @@ -303,13 +330,28 @@ function apply_deck_selection(decks)
var container = document.getElementById("tableau");
container.innerHTML = ""; // TODO use deck.discard_deck instead

//no "Draw all" deck if there's only one deck!
if(decks.length > 1){

//deal with all decks together
var deck_space = document.createElement("div");
deck_space.className = "card-container";
container.appendChild(deck_space);
var card_back = create_card_back("draw all and sort initiative");
card_back.className="card back up";
deck_space.appendChild(card_back);
deck_space.onclick = draw_cards.bind(null, decks);
}

for (var i = 0; i < decks.length; i++)
{
var deck = decks[i];

var deck_space = document.createElement("div");
deck_space.className = "card-container";
container.appendChild(deck_space);
deck_space.id = deck.name;
container.appendChild(deck_space);

var deck = decks[i];
place_deck(deck, deck_space);
reshuffle(deck);
deck_space.onclick = draw_card.bind(null, deck);
Expand All @@ -319,6 +361,8 @@ function apply_deck_selection(decks)
container.removeChild(deck_space);
}
}



// Rescale card text if necessary
refresh_ui(decks);
Expand Down