Don't include final 5 in row sum

This commit is contained in:
Amanda Graven 2025-12-13 14:36:43 +01:00
parent 80865ace7d
commit 1213b0bd8f
2 changed files with 15 additions and 16 deletions

View file

@ -1,7 +1,7 @@
/* https://pajasevi.github.io/CSSnowflakes/ */ /* https://pajasevi.github.io/CSSnowflakes/ */
.snowflake { .snowflake {
color: #fff; color: #fff;
font-size: 1em; font-size: 1.5em;
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
text-shadow: 0 0 5px #000; text-shadow: 0 0 5px #000;
} }

View file

@ -53,6 +53,7 @@ fn main() {
fn App() -> Element { fn App() -> Element {
let mut rows = use_signal(State::default); let mut rows = use_signal(State::default);
let longest = use_memo(move || rows.read().longest()); let longest = use_memo(move || rows.read().longest());
let row_finished = use_memo(move || rows.read().row_finished());
let snow = true; let snow = true;
rsx! { rsx! {
document::Link { rel: "icon", href: FAVICON } document::Link { rel: "icon", href: FAVICON }
@ -82,7 +83,7 @@ fn App() -> Element {
} }
tbody { tbody {
tr { tr {
th { colspan: 100, "Game 1" } th { colspan: 100, "Why 5?" }
} }
for row in &rows.read().rows { for row in &rows.read().rows {
tr { tr {
@ -91,12 +92,16 @@ fn App() -> Element {
} }
td { td {
class: "number", class: "number",
colspan: (max(19, longest()).saturating_sub(row.len())).to_string() colspan: (max(19, longest() + 1).saturating_sub(row.len())).to_string()
} }
td { td {
class: "number", class: "number",
b { b {
{row.iter().copied().sum::<u16>().to_string()} if row.len() <= 1 {
{row.iter().sum::<u16>().to_string()}
} else {
{row.iter().take_while(|&&n| n != 5).sum::<u16>().to_string()}
}
} }
} }
} }
@ -105,21 +110,15 @@ fn App() -> Element {
} }
div { div {
class: "controls", class: "controls",
if rows.read().row_finished() { div {
div { class: "number-buttons",
class: "number-buttons", for n in 1..=6 {
for n in 1..=6 { button { disabled: row_finished(), "{n}" }
button { disabled: true, "{n}" }
}
} }
}
if row_finished() {
button { onclick: move |_| rows.write().new_row(), "Start new row" } button { onclick: move |_| rows.write().new_row(), "Start new row" }
} else { } else {
div {
class: "number-buttons",
for n in 1..=6 {
button { onclick: move |_| rows.write().push(n), "{n}" }
}
}
button { onclick: move |_| rows.write().roll(), "Roll" } button { onclick: move |_| rows.write().roll(), "Roll" }
} }
} }