{
"id": "298",
"prompt": "Volleyball scoreboard: the top two thirds is two giant tap zones - left half +1 TEAM A, right half +1 TEAM B - with a white dot marking the serving side, which flips every 2 total points so ((a+b)/2)%2 picks it. An UNDO button takes back only the most recent point (remember the last scorer in a slot and clear it after one undo). First team to 11 swaps to a winner screen with the final score and tap-to-reset.",
"solution_rl": "fn frame(t: i32) {\n let w: i32 = host::display::width();\n host::display::clear(0x0d0f13);\n let a: i32 = host::display::state_get(1);\n let b: i32 = host::display::state_get(2);\n let down: i32 = host::display::pointer_down();\n let prev: i32 = host::display::state_get(0);\n host::display::state_set(0, down);\n let mut click: i32 = 0;\n if down == 1 && prev == 0 {\n click = 1;\n }\n\n if host::display::state_get(4) == 1 {\n if a > b {\n host::display::draw_string(130, 180, \"TEAM A WINS\", 0xffcc33, 3);\n } else {\n host::display::draw_string(130, 180, \"TEAM B WINS\", 0x33ff88, 3);\n }\n host::display::draw_number(170, 260, a, 0xffffff, 4);\n host::display::draw_string(240, 268, \"TO\", 0x556677, 2);\n host::display::draw_number(300, 260, b, 0xffffff, 4);\n host::display::draw_string(160, 380, \"TAP FOR A NEW SET\", 0x556677, 1);\n if click == 1 {\n host::display::state_set(1, 0);\n host::display::state_set(2, 0);\n host::display::state_set(3, 0);\n host::display::state_set(4, 0);\n }\n } else {\n host::display::fill_rect(0, 0, w / 2 - 2, 340, 0x1c1a10);\n host::display::fill_rect(w / 2 + 2, 0, w / 2 - 2, 340, 0x101c14);\n host::display::draw_string(90, 30, \"TEAM A\", 0xffcc33, 2);\n host::display::draw_number(90, 90, a, 0xffffff, 8);\n host::display::draw_string(346, 30, \"TEAM B\", 0x33ff88, 2);\n host::display::draw_number(346, 90, b, 0xffffff, 8);\n\n let serve: i32 = ((a + b) / 2) % 2;\n if serve == 0 {\n host::display::fill_rect(110, 250, 20, 20, 0xffffff);\n } else {\n host::display::fill_rect(366, 250, 20, 20, 0xffffff);\n }\n host::display::draw_string(200, 300, \"DOT = SERVING\", 0x556677, 1);\n\n host::display::fill_rect(196, 400, 120, 60, 0x232833);\n host::display::draw_string(224, 420, \"UNDO\", 0xffffff, 2);\n host::display::draw_string(140, 480, \"FIRST TO 11 TAKES THE SET\", 0x556677, 1);\n\n if click == 1 {\n let px: i32 = host::display::pointer_x();\n let py: i32 = host::display::pointer_y();\n if py < 340 {\n if px < w / 2 {\n host::display::state_set(1, a + 1);\n host::display::state_set(3, 1);\n if a + 1 >= 11 {\n host::display::state_set(4, 1);\n }\n } else {\n host::display::state_set(2, b + 1);\n host::display::state_set(3, 2);\n if b + 1 >= 11 {\n host::display::state_set(4, 1);\n }\n }\n } else if px >= 196 && px < 316 && py >= 400 && py < 460 {\n let last: i32 = host::display::state_get(3);\n if last == 1 && a > 0 {\n host::display::state_set(1, a - 1);\n host::display::state_set(3, 0);\n } else if last == 2 && b > 0 {\n host::display::state_set(2, b - 1);\n host::display::state_set(3, 0);\n }\n }\n }\n }\n host::display::present();\n}\n",
"tags": [
"app",
"scoreboard",
"interaction"
]
}