diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-07-28 01:17:08 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-11-17 13:11:26 +0100 |
commit | 1251e90775534849ef2f57a70a808d4626ccbf6d (patch) | |
tree | b51a31f1cda38e2aa89d568082c25f97e06854d6 | |
parent | 152e57f0799754cc8b0c06f264c14c66102d29f6 (diff) | |
download | rommel-in-the-desert-1251e90775534849ef2f57a70a808d4626ccbf6d.tar.gz |
Mulligan.
-rw-r--r-- | play.html | 5 | ||||
-rw-r--r-- | play.js | 3 | ||||
-rw-r--r-- | rules.js | 85 |
3 files changed, 78 insertions, 15 deletions
@@ -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 { @@ -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") @@ -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) |