summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--play.html21
-rw-r--r--rules.js116
-rw-r--r--ui.js34
3 files changed, 144 insertions, 27 deletions
diff --git a/play.html b/play.html
index f25e54a..c91b9bd 100644
--- a/play.html
+++ b/play.html
@@ -46,9 +46,25 @@
border-radius: 12px;
}
+.card_info .card {
+ margin: 15px auto;
+ width: 100px;
+ height: 140px;
+ border-radius: 5px;
+}
+
+.card_info .card:hover {
+ transform: scale(2) translateY(-30px);
+}
+
.role_info {
- display: flex;
- justify-content: center;
+ padding: 5px 20px;
+ background-color: gainsboro;
+ white-space: pre-wrap;
+}
+
+.role_info.card_info {
+ background-color: silver;
}
/* MAP */
@@ -261,6 +277,7 @@
<div class="role_name">United States (<span class="role_user">$USER</span>)</div>
<div class="role_info" id="us_info">0 cards in hand</div>
</div>
+ <div class="role_info card_info"><div id="active_card" class="card show tr_card_back"></div></div>
</div>
<div class="grid_log">
diff --git a/rules.js b/rules.js
index 4717160..b984fb7 100644
--- a/rules.js
+++ b/rules.js
@@ -378,9 +378,11 @@ function count_pieces(list, where) {
function discard_card(player, card, reason = "") {
log("");
- log(game.active + " discards \"" + CARD_NAMES[card] + "\"" + reason + ".");
+ // log(game.active + " discards \"" + CARD_NAMES[card] + "\"" + reason + ".");
+ log(game.active + " discards a card" + reason + ".");
remove_from_array(player.hand, card);
player.discard.push(card);
+ game.active_card = game.active;
}
function play_card(player, card) {
@@ -389,6 +391,7 @@ function play_card(player, card) {
remove_from_array(player.hand, card);
if (!should_remove_after_play(card))
player.discard.push(card);
+ game.active_card = card;
}
function deploy(piece_name, space) {
@@ -413,6 +416,43 @@ function move_all_pieces(list, from, to) {
}
}
+function fire(what, n_dice) {
+ let hits = 0;
+ for (let i = 0; i < n_dice; ++i) {
+ let roll = roll_d6();
+ if (roll == 6)
+ ++hits;
+ log(what + " fires " + roll + ".");
+ }
+ return hits;
+}
+
+function intercept(what, n) {
+ let hits = 0;
+ for (let i = 0; i < n; ++i) {
+ let a = roll_d6();
+ let b = roll_d6();
+ if (a == 6) ++hits;
+ if (b == 6) ++hits;
+ log(what + " intercepts " + a + ", " + b + ".");
+ }
+ return hits;
+}
+
+function capture(what, n) {
+ let hits = 0;
+ for (let i = 0; i < n; ++i) {
+ let roll = roll_d6();
+ if (roll >= 5) ++hits;
+ log(what + " captures " + roll + ".");
+ }
+ return hits;
+}
+
+function count_swedish_frigates(where) {
+ return count_pieces(SE_FRIGATES, where);
+}
+
function count_american_frigates(where) {
return count_pieces(US_FRIGATES, where);
}
@@ -622,7 +662,7 @@ states.tripolitan_play = {
},
card_pirate_raid: function (c) {
discard_card(game.tr, c, " to Pirate Raid with the corsairs from Tripoli");
- end_tripolitan_play();
+ goto_pirate_raid(TRIPOLI_HARBOR, TRIPOLI_PATROL_ZONE);
},
pass: function () {
log("");
@@ -631,6 +671,46 @@ states.tripolitan_play = {
}
}
+function goto_pirate_raid(harbor, patrol_zone) {
+ game.where = patrol_zone;
+ interception_roll(harbor, patrol_zone);
+ capture_roll(harbor);
+ game.where = null;
+ end_tripolitan_play();
+}
+
+function interception_roll(harbor, patrol_zone) {
+ let n_se = count_swedish_frigates(patrol_zone);
+ let n_us = count_american_frigates(patrol_zone);
+ let n_tr = count_tripolitan_corsairs(harbor);
+ let n_al = count_allied_corsairs(harbor);
+ let hits = 0;
+ hits += intercept("Swedish frigate", n_se);
+ hits += intercept("US frigate", n_us);
+ if (hits > n_tr + n_al)
+ hits = n_tr + n_al;
+ log(hits + " corsairs sink.");
+ if (n_tr > 0)
+ for (let i = 0; i < hits; ++i)
+ move_one_piece(TR_CORSAIRS, harbor, TRIPOLITAN_SUPPLY);
+ else
+ for (let i = 0; i < hits; ++i)
+ move_one_piece(AL_CORSAIRS, harbor, TRIPOLITAN_SUPPLY);
+}
+
+function capture_roll(harbor) {
+ let hits = 0;
+ hits += capture("Tripolitan corsair", count_tripolitan_corsairs(harbor));
+ hits += capture("Allied corsair", count_allied_corsairs(harbor));
+ log(hits + " merchant ships captured.");
+
+ game.tr.gold += hits;
+ if (game.tr.gold > 12)
+ game.tr.gold = 12;
+
+ // TODO: check victory
+}
+
function goto_move_up_to_n_american_frigates(n) {
game.moves = n;
game.active = US;
@@ -700,7 +780,7 @@ states.move_us_frigate_to = {
prompt: function (view, current) {
if (is_inactive_player(current))
return view.prompt = "United States: Move up to " + game.moves + " frigates.";
- view.prompt = "United States: Move up to " + game.moves + " frigates. Select a destation.";
+ view.prompt = "United States: Move up to " + game.moves + " frigates. Select a destination.";
for (let space of FRIGATE_SPACES)
if (space != game.where)
gen_action(view, 'space', space);
@@ -775,17 +855,6 @@ states.select_combat = {
},
}
-function fire(space, what, n_dice) {
- let hits = 0;
- for (let i = 0; i < n_dice; ++i) {
- let roll = roll_d6();
- if (roll == 6)
- ++hits;
- log(what + " fires " + roll + ".");
- }
- return hits;
-}
-
function goto_naval_battle() {
log("Naval battle in " + SPACES[game.where] + ".");
// TODO: battle cards
@@ -802,15 +871,15 @@ function naval_battle_round() {
let tr_hitpoints = n_tr_frigates * 2 + n_tr_corsairs + n_al_corsairs;
game.n_tr_hits = 0;
- game.n_tr_hits += fire(game.where, "US frigate", 2 * n_us_frigates);
- game.n_tr_hits += fire(game.where, "US gunboat", 1 * n_us_gunboats);
+ game.n_tr_hits += fire("US frigate", 2 * n_us_frigates);
+ game.n_tr_hits += fire("US gunboat", 1 * n_us_gunboats);
if (game.n_tr_hits > tr_hitpoints)
game.n_tr_hits = tr_hitpoints;
game.n_us_hits = 0;
- game.n_us_hits += fire(game.where, "Tripolitan frigate", 2 * n_tr_frigates);
- game.n_us_hits += fire(game.where, "Tripolitan corsair", 1 * n_tr_corsairs);
- game.n_us_hits += fire(game.where, "Allied corsair", 1 * n_al_corsairs);
+ game.n_us_hits += fire("Tripolitan frigate", 2 * n_tr_frigates);
+ game.n_us_hits += fire("Tripolitan corsair", 1 * n_tr_corsairs);
+ game.n_us_hits += fire("Allied corsair", 1 * n_al_corsairs);
if (game.n_us_hits > us_hitpoints)
game.n_us_hits = us_hitpoints;
@@ -990,8 +1059,8 @@ function naval_bombardment_round() {
let n_infantry = count_tripolitan_infantry(game.where);
let n_hits = 0;
- n_hits += fire(game.where, "US frigate", 2 * n_frigates);
- n_hits += fire(game.where, "US gunboat", 1 * n_gunboats);
+ n_hits += fire("US frigate", 2 * n_frigates);
+ n_hits += fire("US gunboat", 1 * n_gunboats);
if (n_hits > n_infantry)
n_hits = n_infantry;
@@ -1034,7 +1103,7 @@ exports.setup = function (scenario, players) {
hand: [],
deck: [],
discard: [],
- coins: 0,
+ gold: 0,
},
derne_captured: 0,
where: null,
@@ -1153,7 +1222,7 @@ exports.view = function(state, current) {
deck: game.tr.deck.length,
discard: game.tr.discard.length,
hand: game.tr.hand.length,
- coins: game.tr.coins,
+ gold: game.tr.gold,
},
us: {
core: game.us.core,
@@ -1161,6 +1230,7 @@ exports.view = function(state, current) {
discard: game.us.discard.length,
hand: game.us.hand.length,
},
+ card: game.active_card,
where: game.where,
};
diff --git a/ui.js b/ui.js
index 205d42c..2a1fbc8 100644
--- a/ui.js
+++ b/ui.js
@@ -133,13 +133,43 @@ function update_cards() {
/* MAP AND PIECE LAYOUT */
+function tr_info() {
+ let text = "";
+ if (game.tr.hand == 1)
+ text += "1 card in hand";
+ else
+ text += game.tr.hand + " cards in hand";
+ text += "\n$" + game.tr.gold;
+ return text;
+}
+
+function us_info() {
+ let text = "";
+ if (game.us.hand == 1)
+ text += "1 card in hand";
+ else
+ text += game.us.hand + " cards in hand";
+ return text;
+}
+
function on_update() {
show_action_button("#button_pass", "pass");
show_action_button("#button_next", "next");
show_action_button("#button_undo", "undo");
- update_year_marker(game.year);
+
+ document.getElementById("tr_info").textContent = tr_info();
+ document.getElementById("us_info").textContent = us_info();
+
+ if (game.card == "United States")
+ document.getElementById("active_card").className = "card show us_card_back";
+ else if (game.card == "Tripolitania")
+ document.getElementById("active_card").className = "card show tr_card_back";
+ else if (game.card < 27)
+ document.getElementById("active_card").className = "card show us_card_" + game.card;
+ else
+ document.getElementById("active_card").className = "card show tr_card_" + (game.card-27);
+
update_season_marker(game.season);
- update_pieces(game.location);
update_pieces();
update_cards();
update_spaces();