Skip to content

Commit 9919594

Browse files
create a basic board
Signed-off-by: Jonathan Irvin <djfoxyslpr@gmail.com>
1 parent 3335f83 commit 9919594

File tree

3 files changed

+1884
-0
lines changed

3 files changed

+1884
-0
lines changed

main.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
from nicegui import ui
2+
import random
3+
import datetime
4+
import logging
5+
6+
# Set up logging
7+
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
8+
9+
# List of 24 phrases (excluding the center "FREE MEAT")
10+
phrases = [
11+
"CAN'T HAVE NICE THINGS", "TECHNO BABBLE", "HELL YEAH!", "WE GET A RAID", "NOICE",
12+
"POSITION ONE", "HOWS MY AUDIO", "SOMEONE REDEEMS HYDRATE", "THREATEN GOOD TIME", "MENTIONS MODS",
13+
"SAYS TEXAS", "SPINS BONUS WHEEL", "JOIN DISCORD", "HOLY SMOKES",
14+
"SAYS CATS OR DOGS", "DOOT DOOTS", "MAKES AIR QUOTES", "TALKS ABOUT ELLEE", "ZOOM",
15+
"SIGHT LINES", "TALKS ABOUT PALIA", "SAYS DISCORD", "DANCE PARTY", "THATS NUTS!"
16+
]
17+
18+
# Use today's date as the seed for deterministic shuffling
19+
today_seed = datetime.date.today().strftime("%Y%m%d")
20+
random.seed(int(today_seed)) # Everyone gets the same shuffle per day
21+
22+
# Shuffle and create the 5x5 board:
23+
shuffled_phrases = random.sample(phrases, 24) # Random but fixed order per day
24+
shuffled_phrases.insert(12, "FREE MEAT") # Center slot
25+
board = [shuffled_phrases[i:i+5] for i in range(0, 25, 5)]
26+
27+
# Track clicked tiles and store chip references
28+
clicked_tiles = set()
29+
tile_buttons = {} # {(row, col): chip}
30+
31+
# Function to create the Bingo board UI
32+
def create_bingo_board():
33+
logging.info("Creating Bingo board")
34+
ui.label("Commit Bingo!").classes("text-3xl font-bold mt-4 text-yellow-400")
35+
ui.label(f"Seed: {today_seed}").classes("text-md text-gray-300")
36+
37+
with ui.element("div").classes("flex justify-center items-center w-full"):
38+
with ui.grid(columns=5).classes("gap-2 mt-4"):
39+
for row_idx, row in enumerate(board):
40+
for col_idx, phrase in enumerate(row):
41+
# Create a clickable card for this cell with reduced padding and centered content.
42+
card = ui.card().classes("p-2 bg-yellow-500 hover:bg-yellow-400 rounded-lg w-full flex items-center justify-center").style("cursor: pointer; aspect-ratio: 1;")
43+
with card:
44+
with ui.column().classes("flex flex-col items-center justify-center gap-0 w-full"):
45+
# Split the phrase into words and make each word a separate label.
46+
for word in phrase.split():
47+
tile = ui.label(word).classes("text-lg text-center")
48+
tile.style("font-family: 'Super Carnival', sans-serif; padding: 0; margin: 0;")
49+
# Save the card reference.
50+
tile_buttons[(row_idx, col_idx)] = card
51+
# When the card is clicked, toggle its state.
52+
card.on("click", lambda e, r=row_idx, c=col_idx: toggle_tile(r, c))
53+
54+
# Toggle tile click state (for example usage)
55+
def toggle_tile(row, col):
56+
key = (row, col)
57+
if key in clicked_tiles:
58+
logging.debug(f"Tile at {key} unclicked")
59+
clicked_tiles.remove(key)
60+
tile_buttons[key].style("background: #facc15; border: none;")
61+
else:
62+
logging.debug(f"Tile at {key} clicked")
63+
clicked_tiles.add(key)
64+
tile_buttons[key].style("color: #22c55e; border: 15px solid #15803d;")
65+
66+
check_winner()
67+
68+
# Check for Bingo win condition
69+
def check_winner():
70+
for i in range(5):
71+
if all((i, j) in clicked_tiles for j in range(5)) or all((j, i) in clicked_tiles for j in range(5)):
72+
ui.notify("BINGO!", color="green", duration=5)
73+
return
74+
if all((i, i) in clicked_tiles for i in range(5)) or all((i, 4 - i) in clicked_tiles for i in range(5)):
75+
ui.notify("BINGO!", color="green", duration=5)
76+
77+
# Set up NiceGUI page and head elements
78+
ui.page("/")
79+
ui.add_head_html('<link href="https://fonts.cdnfonts.com/css/super-carnival" rel="stylesheet">')
80+
create_bingo_board()
81+
ui.run(port=8080, title="Commit Bingo", dark=True)

0 commit comments

Comments
 (0)