summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--play.html5
-rw-r--r--play.js3
-rw-r--r--rules.js85
3 files changed, 78 insertions, 15 deletions
diff --git a/play.html b/play.html
index b496f89..8a8167c 100644
--- a/play.html
+++ b/play.html
@@ -36,14 +36,13 @@ header.your_turn { background-color: orange; }
/* CARDS */
.hand {
- margin: 0 auto;
+ margin: 24px;
display: flex;
flex-wrap: wrap;
- //justify-content: center;
+ justify-content: center;
min-height: 350px;
max-width: 2672px;
gap: 20px;
- padding: 24px;
}
.card {
diff --git a/play.js b/play.js
index fbfcbf3..069ae81 100644
--- a/play.js
+++ b/play.js
@@ -701,6 +701,9 @@ function on_update() {
else
ui.cards.forEach(elt => elt.classList.remove("action"))
+ action_button("discard", "Discard")
+ action_button("keep", "Keep")
+
action_button("select_all", "Select all")
action_button("overrun", "Overrun")
diff --git a/rules.js b/rules.js
index c65c84e..0810eb6 100644
--- a/rules.js
+++ b/rules.js
@@ -445,6 +445,19 @@ function update_presence() {
presence_allied[unit_hex(u)] |= 2
}
+function has_friendly_unit_in_month(month) {
+ for (let u = first_friendly_unit; u <= last_friendly_unit; ++u)
+ if (unit_hex(u) === hexdeploy + month)
+ return true
+ return false
+}
+
+function for_each_friendly_unit_in_month(month, fn) {
+ for (let u = first_friendly_unit; u <= last_friendly_unit; ++u)
+ if (unit_hex(u) === hexdeploy + month)
+ fn(u)
+}
+
function has_axis_unit(x) {
if (presence_invalid)
update_presence()
@@ -823,6 +836,8 @@ function count_hp_in_rout() {
// === SUPPLY CARDS ===
+// TODO: reshuffle!
+
function draw_supply_card(pile) {
let x = random(pile[0] + pile[1])
if (x < pile[0]) {
@@ -3583,10 +3598,18 @@ function end_month() {
delete game.bardia_captured
delete game.benghazi_captured
delete game.tobruk_captured
+ // TODO: check end game and victory
+ throw new Error("end month not done yet")
}
// === DEPLOYMENT ===
+function goto_free_deployment() {
+ game.state = 'free_deployment'
+ if (!has_friendly_unit_in_month(SCENARIOS[game.scenario].start))
+ end_free_deployment()
+}
+
states.free_deployment = {
inactive: "free deployment",
prompt() {
@@ -3628,16 +3651,20 @@ states.free_deployment = {
},
next() {
clear_undo()
- if (is_axis_player()) {
- set_enemy_player()
- log_h2("Allied Deployment")
- } else {
- end_free_deployment()
- }
+ end_free_deployment()
}
}
function end_free_deployment() {
+ set_enemy_player()
+ if (has_friendly_unit_in_month(SCENARIOS[game.scenario].start)) {
+ log_h2("Allied Deployment")
+ } else {
+ goto_initial_supply_cards()
+ }
+}
+
+function goto_initial_supply_cards() {
game.phasing = AXIS
set_active_player()
@@ -3645,8 +3672,42 @@ function end_free_deployment() {
deal_axis_supply_cards(scenario.axis_initial_supply)
deal_allied_supply_cards(scenario.allied_initial_supply)
- // TODO: mulligan
+ game.state = 'initial_supply_cards'
+}
+
+states.initial_supply_cards = {
+ prompt() {
+ view.prompt = `Setup: You may discard your entire hand and redraw a new one.`
+ gen_action('discard')
+ gen_action('keep')
+ },
+ discard() {
+ let scenario = SCENARIOS[game.scenario]
+ if (is_axis_player()) {
+ log_br()
+ log(`Axis player drew a new hand.`)
+ game.axis_hand[0] = 0
+ game.axis_hand[1] = 0
+ deal_axis_supply_cards(scenario.axis_initial_supply)
+ set_enemy_player()
+ } else {
+ log_br()
+ log(`Allied player drew a new hand.`)
+ game.allied_hand[0] = 0
+ game.allied_hand[1] = 0
+ deal_allied_supply_cards(scenario.allied_initial_supply)
+ begin_game()
+ }
+ },
+ keep() {
+ if (is_axis_player())
+ set_enemy_player()
+ else
+ begin_game()
+ },
+}
+function begin_game() {
log_br()
log_h1(`Month ${game.month}`)
log_br()
@@ -4099,8 +4160,8 @@ function setup(name) {
log_h2("Axis Deployment")
game.phasing = AXIS
set_active_player()
- game.state = 'free_deployment'
- game.selected = -1
+
+ goto_free_deployment()
}
// === PUBLIC FUNCTIONS ===
@@ -4110,7 +4171,7 @@ exports.roles = [ "Axis", "Allied" ]
exports.scenarios = Object.keys(SCENARIOS)
exports.setup = function (seed, scenario, options) {
- game = {
+ load_state({
seed: seed,
log: [],
undo: [],
@@ -4123,7 +4184,7 @@ exports.setup = function (seed, scenario, options) {
scenario: scenario,
month: 0,
- draw_pile: [ 14, 28 ], // 14 dummy supply + 28 real supply
+ draw_pile: [ 28, 14 ], // 28 real supply + 14 dummy supply
axis_hand: [ 0, 0 ],
allied_hand: [ 0, 0 ],
@@ -4179,7 +4240,7 @@ exports.setup = function (seed, scenario, options) {
battle: 0,
hits: null,
flash: null,
- }
+ })
setup(scenario)