Skip to content

Commit c933e2c

Browse files
authored
Update app.py
1 parent 185532d commit c933e2c

1 file changed

Lines changed: 80 additions & 84 deletions

File tree

app.py

Lines changed: 80 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,95 @@
11
from flask import Flask, render_template_string
2-
import random
32

43
app = Flask(__name__)
54

65
HTML_PAGE = """
76
<!DOCTYPE html>
87
<html lang="en">
98
<head>
10-
<meta charset="UTF-8">
11-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
12-
<title>Rock Paper Scissors - Azure Demo</title>
13-
<style>
14-
body {
15-
font-family: Arial, sans-serif;
16-
background: linear-gradient(135deg, #667eea, #764ba2);
17-
height: 100vh;
18-
display: flex;
19-
justify-content: center;
20-
align-items: center;
21-
margin: 0;
22-
color: #fff;
23-
}
24-
.game {
25-
text-align: center;
26-
background: rgba(0,0,0,0.5);
27-
padding: 30px;
28-
border-radius: 15px;
29-
box-shadow: 0 8px 20px rgba(0,0,0,0.3);
30-
}
31-
h1 {
32-
margin-bottom: 20px;
33-
}
34-
.choices button {
35-
margin: 10px;
36-
padding: 10px 20px;
37-
border: none;
38-
background: #ff9800;
39-
color: white;
40-
border-radius: 8px;
41-
cursor: pointer;
42-
font-size: 16px;
43-
transition: 0.3s;
44-
}
45-
.choices button:hover {
46-
background: #e68900;
47-
}
48-
#result {
49-
margin-top: 20px;
50-
font-size: 20px;
51-
font-weight: bold;
52-
}
53-
</style>
9+
<meta charset="UTF-8">
10+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
11+
<title>Emoji Catch Game - Azure Demo</title>
12+
<style>
13+
body {
14+
margin: 0;
15+
display: flex;
16+
justify-content: center;
17+
align-items: center;
18+
height: 100vh;
19+
background: linear-gradient(135deg, #ff9966, #ff5e62);
20+
font-family: Arial, sans-serif;
21+
}
22+
canvas {
23+
background: #fff;
24+
border-radius: 10px;
25+
box-shadow: 0 6px 20px rgba(0,0,0,0.3);
26+
}
27+
#score {
28+
position: absolute;
29+
top: 20px;
30+
left: 50%;
31+
transform: translateX(-50%);
32+
font-size: 24px;
33+
color: white;
34+
font-weight: bold;
35+
}
36+
</style>
5437
</head>
5538
<body>
56-
<div class="game">
57-
<h1>✊ ✋ ✌ Rock Paper Scissors</h1>
58-
<p>Choose one:</p>
59-
<div class="choices">
60-
<button onclick="play('rock')">Rock</button>
61-
<button onclick="play('paper')">Paper</button>
62-
<button onclick="play('scissors')">Scissors</button>
63-
</div>
64-
<div id="result"></div>
65-
</div>
39+
<div id="score">Score: 0</div>
40+
<canvas id="gameCanvas" width="400" height="600"></canvas>
41+
42+
<script>
43+
const canvas = document.getElementById("gameCanvas");
44+
const ctx = canvas.getContext("2d");
45+
46+
let basket = { x: 160, y: 550, width: 80, height: 20 };
47+
let emojis = ["🍕","🎩","🚀","🐱","🍔","⚡","🌈","🎮"];
48+
let falling = [];
49+
let score = 0;
6650
67-
<script>
68-
function play(choice) {
69-
fetch(`/play?choice=${choice}`)
70-
.then(response => response.json())
71-
.then(data => {
72-
document.getElementById("result").innerHTML =
73-
"You chose: " + data.user + "<br>" +
74-
"Computer chose: " + data.computer + "<br><br>" +
75-
"<b>" + data.result + "</b>";
76-
});
51+
function drawBasket() {
52+
ctx.fillStyle = "#0078D4";
53+
ctx.fillRect(basket.x, basket.y, basket.width, basket.height);
54+
}
55+
56+
function drawEmojis() {
57+
ctx.font = "28px Arial";
58+
falling.forEach(e => {
59+
ctx.fillText(e.emoji, e.x, e.y);
60+
});
61+
}
62+
63+
function updateEmojis() {
64+
falling.forEach(e => e.y += 3);
65+
falling = falling.filter(e => {
66+
if (e.y > basket.y && e.x > basket.x && e.x < basket.x + basket.width) {
67+
score += 10;
68+
document.getElementById("score").innerText = "Score: " + score;
69+
return false;
7770
}
78-
</script>
71+
return e.y < 600;
72+
});
73+
if (Math.random() < 0.03) {
74+
falling.push({ emoji: emojis[Math.floor(Math.random()*emojis.length)], x: Math.random()*370, y: 0 });
75+
}
76+
}
77+
78+
function gameLoop() {
79+
ctx.clearRect(0, 0, 400, 600);
80+
drawBasket();
81+
drawEmojis();
82+
updateEmojis();
83+
requestAnimationFrame(gameLoop);
84+
}
85+
86+
document.addEventListener("keydown", (e) => {
87+
if (e.key === "ArrowLeft" && basket.x > 0) basket.x -= 20;
88+
if (e.key === "ArrowRight" && basket.x < 320) basket.x += 20;
89+
});
90+
91+
gameLoop();
92+
</script>
7993
</body>
8094
</html>
8195
"""
@@ -84,24 +98,6 @@
8498
def home():
8599
return render_template_string(HTML_PAGE)
86100

87-
@app.route("/play")
88-
def play():
89-
from flask import request, jsonify
90-
user_choice = request.args.get("choice")
91-
choices = ["rock", "paper", "scissors"]
92-
comp_choice = random.choice(choices)
93-
94-
if user_choice == comp_choice:
95-
result = "It's a Tie!"
96-
elif (user_choice == "rock" and comp_choice == "scissors") or \
97-
(user_choice == "paper" and comp_choice == "rock") or \
98-
(user_choice == "scissors" and comp_choice == "paper"):
99-
result = "🎉 You Win!"
100-
else:
101-
result = "😢 You Lose!"
102-
103-
return jsonify({"user": user_choice, "computer": comp_choice, "result": result})
104-
105101
if __name__ == "__main__":
106102
app.run(host="0.0.0.0", port=8000)
107103

0 commit comments

Comments
 (0)