Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -107,65 +107,144 @@ def start_vs_computer():
|
|
107 |
def reset_current_game():
|
108 |
game.reset_game(game.vs_computer)
|
109 |
return update_interface()
|
110 |
-
|
111 |
CSS = """
|
112 |
body, .gradio-container {
|
113 |
background: #fff0f5 !important;
|
114 |
padding: 1rem 1.5rem;
|
115 |
box-sizing: border-box;
|
116 |
min-height: 100vh;
|
|
|
|
|
|
|
|
|
117 |
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
118 |
-
color: #
|
119 |
}
|
120 |
|
121 |
-
/*
|
122 |
-
|
123 |
-
font-size: clamp(
|
124 |
color: #db2777;
|
|
|
|
|
125 |
font-weight: 700;
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
text-align: center;
|
127 |
-
margin-bottom:
|
128 |
user-select: none;
|
129 |
}
|
130 |
|
131 |
-
/*
|
132 |
-
#
|
133 |
-
|
134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
text-align: center;
|
136 |
-
margin
|
137 |
user-select: none;
|
138 |
-
padding: 0 8px;
|
139 |
-
line-height: 1.4;
|
140 |
}
|
141 |
|
142 |
-
/* Player legend */
|
143 |
-
|
144 |
-
font-size: clamp(
|
145 |
-
color: #
|
146 |
margin-top: 0.5rem;
|
147 |
user-select: none;
|
148 |
-
|
149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
}
|
151 |
"""
|
152 |
|
153 |
-
with gr.Blocks(css=CSS) as demo:
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
|
159 |
-
# Buttons placeholder (not functional here)
|
160 |
with gr.Row():
|
161 |
with gr.Column(scale=1, min_width=220):
|
162 |
-
gr.Markdown("### ๐ฎ Choose Game Mode", elem_id="
|
163 |
-
gr.Button("๐ฅ Play vs Friend", elem_classes=["neat-button"])
|
164 |
-
gr.Button("๐ค Play vs Computer", elem_classes=["neat-button"])
|
165 |
-
gr.Button("๐ Reset Game", elem_classes=["neat-button"])
|
166 |
|
167 |
gr.Markdown("""
|
168 |
-
<div
|
169 |
<ul>
|
170 |
<li><strong>Player 1:</strong> โ</li>
|
171 |
<li><strong>Player 2 / Computer:</strong> โญ</li>
|
@@ -173,4 +252,28 @@ with gr.Blocks(css=CSS) as demo:
|
|
173 |
</div>
|
174 |
""")
|
175 |
|
176 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
def reset_current_game():
|
108 |
game.reset_game(game.vs_computer)
|
109 |
return update_interface()
|
|
|
110 |
CSS = """
|
111 |
body, .gradio-container {
|
112 |
background: #fff0f5 !important;
|
113 |
padding: 1rem 1.5rem;
|
114 |
box-sizing: border-box;
|
115 |
min-height: 100vh;
|
116 |
+
display: flex;
|
117 |
+
justify-content: center;
|
118 |
+
align-items: center;
|
119 |
+
flex-direction: column;
|
120 |
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
121 |
+
color: #5b021f;
|
122 |
}
|
123 |
|
124 |
+
/* Heading and subtext */
|
125 |
+
h1 {
|
126 |
+
font-size: clamp(1.8rem, 5vw, 2.5rem);
|
127 |
color: #db2777;
|
128 |
+
margin-bottom: 0.2rem;
|
129 |
+
text-align: center;
|
130 |
font-weight: 700;
|
131 |
+
user-select: none;
|
132 |
+
}
|
133 |
+
|
134 |
+
.subtext {
|
135 |
+
font-size: clamp(1rem, 3vw, 1.1rem);
|
136 |
+
color: #9d174d;
|
137 |
text-align: center;
|
138 |
+
margin-bottom: 1.5rem;
|
139 |
user-select: none;
|
140 |
}
|
141 |
|
142 |
+
/* Board container: perfect square, responsive */
|
143 |
+
#board-container {
|
144 |
+
display: grid;
|
145 |
+
grid-template-columns: repeat(3, 1fr);
|
146 |
+
grid-template-rows: repeat(3, 1fr);
|
147 |
+
gap: 12px;
|
148 |
+
width: 90vw;
|
149 |
+
max-width: 480px;
|
150 |
+
height: 90vw;
|
151 |
+
max-height: 480px;
|
152 |
+
margin: 0 auto 1.5rem auto;
|
153 |
+
}
|
154 |
+
|
155 |
+
/* Buttons fill cells fully, keep perfect squares */
|
156 |
+
.game-btn {
|
157 |
+
width: 100%;
|
158 |
+
height: 100%;
|
159 |
+
font-size: clamp(2rem, 6vw, 3.5rem) !important;
|
160 |
+
border-radius: 12px !important;
|
161 |
+
background: #fff0f5 !important;
|
162 |
+
border: 2px solid #f9a8d4 !important;
|
163 |
+
transition: background 0.2s ease-in-out;
|
164 |
+
padding: 0;
|
165 |
+
display: flex;
|
166 |
+
justify-content: center;
|
167 |
+
align-items: center;
|
168 |
+
user-select: none;
|
169 |
+
}
|
170 |
+
.game-btn:hover {
|
171 |
+
background: #fbcfe8 !important;
|
172 |
+
border-color: #ec4899 !important;
|
173 |
+
}
|
174 |
+
|
175 |
+
/* Mode Buttons */
|
176 |
+
.neat-button {
|
177 |
+
padding: 12px 16px;
|
178 |
+
border-radius: 8px;
|
179 |
+
font-size: clamp(0.9rem, 3vw, 1.1rem);
|
180 |
+
margin: 6px 0;
|
181 |
+
background: #fce7f3;
|
182 |
+
border: 1px solid #f472b6;
|
183 |
+
color: #be185d;
|
184 |
+
font-weight: 600;
|
185 |
+
width: 100%;
|
186 |
+
box-sizing: border-box;
|
187 |
+
user-select: none;
|
188 |
+
}
|
189 |
+
.neat-button:hover {
|
190 |
+
background: #f9a8d4;
|
191 |
+
border-color: #ec4899;
|
192 |
+
cursor: pointer;
|
193 |
+
}
|
194 |
+
|
195 |
+
/* Status */
|
196 |
+
#status {
|
197 |
+
font-size: clamp(1rem, 4vw, 1.2rem);
|
198 |
+
font-weight: bold;
|
199 |
+
color: #db2777;
|
200 |
text-align: center;
|
201 |
+
margin: 1rem 0;
|
202 |
user-select: none;
|
|
|
|
|
203 |
}
|
204 |
|
205 |
+
/* Player legend text */
|
206 |
+
.player-legend {
|
207 |
+
font-size: clamp(0.85rem, 3vw, 1rem);
|
208 |
+
color: #831843;
|
209 |
margin-top: 0.5rem;
|
210 |
user-select: none;
|
211 |
+
}
|
212 |
+
|
213 |
+
@media (max-width: 768px) {
|
214 |
+
#board-container {
|
215 |
+
width: 90vw;
|
216 |
+
height: 90vw;
|
217 |
+
max-width: 320px;
|
218 |
+
max-height: 320px;
|
219 |
+
gap: 8px;
|
220 |
+
}
|
221 |
+
.game-btn {
|
222 |
+
font-size: clamp(1.8rem, 7vw, 2.5rem) !important;
|
223 |
+
}
|
224 |
+
.neat-button {
|
225 |
+
font-size: clamp(0.85rem, 4vw, 1rem);
|
226 |
+
}
|
227 |
+
#status {
|
228 |
+
font-size: clamp(0.95rem, 4vw, 1.1rem);
|
229 |
+
}
|
230 |
}
|
231 |
"""
|
232 |
|
233 |
+
with gr.Blocks(title="Tic Tac Toe", css=CSS) as demo:
|
234 |
+
gr.Markdown("""
|
235 |
+
<h1>๐ TIC TAC TOE</h1>
|
236 |
+
<p class="subtext">Play solo or with a friend โ may the best player win!</p>
|
237 |
+
""")
|
238 |
|
|
|
239 |
with gr.Row():
|
240 |
with gr.Column(scale=1, min_width=220):
|
241 |
+
gr.Markdown("### ๐ฎ Choose Game Mode", elem_id="status")
|
242 |
+
vs_friend_btn = gr.Button("๐ฅ Play vs Friend", elem_classes=["neat-button"])
|
243 |
+
vs_computer_btn = gr.Button("๐ค Play vs Computer", elem_classes=["neat-button"])
|
244 |
+
reset_btn = gr.Button("๐ Reset Game", elem_classes=["neat-button"])
|
245 |
|
246 |
gr.Markdown("""
|
247 |
+
<div class="player-legend">
|
248 |
<ul>
|
249 |
<li><strong>Player 1:</strong> โ</li>
|
250 |
<li><strong>Player 2 / Computer:</strong> โญ</li>
|
|
|
252 |
</div>
|
253 |
""")
|
254 |
|
255 |
+
with gr.Column(scale=2, min_width=300):
|
256 |
+
status_display = gr.Markdown("๐ฎ Select a game mode to begin", elem_id="status")
|
257 |
+
|
258 |
+
with gr.Column(elem_id="board-container"):
|
259 |
+
btn0 = gr.Button("", elem_classes=["game-btn"])
|
260 |
+
btn1 = gr.Button("", elem_classes=["game-btn"])
|
261 |
+
btn2 = gr.Button("", elem_classes=["game-btn"])
|
262 |
+
btn3 = gr.Button("", elem_classes=["game-btn"])
|
263 |
+
btn4 = gr.Button("", elem_classes=["game-btn"])
|
264 |
+
btn5 = gr.Button("", elem_classes=["game-btn"])
|
265 |
+
btn6 = gr.Button("", elem_classes=["game-btn"])
|
266 |
+
btn7 = gr.Button("", elem_classes=["game-btn"])
|
267 |
+
btn8 = gr.Button("", elem_classes=["game-btn"])
|
268 |
+
|
269 |
+
buttons = [btn0, btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8]
|
270 |
+
all_outputs = buttons + [status_display]
|
271 |
+
|
272 |
+
for i, btn in enumerate(buttons):
|
273 |
+
btn.click(fn=lambda i=i: handle_click(i), outputs=all_outputs)
|
274 |
+
|
275 |
+
vs_friend_btn.click(fn=start_vs_friend, outputs=all_outputs)
|
276 |
+
vs_computer_btn.click(fn=start_vs_computer, outputs=all_outputs)
|
277 |
+
reset_btn.click(fn=reset_current_game, outputs=all_outputs)
|
278 |
+
|
279 |
+
demo.launch()
|