Skip to content

Commit 185532d

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

1 file changed

Lines changed: 65 additions & 27 deletions

File tree

app.py

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,81 @@
11
from flask import Flask, render_template_string
2+
import random
23

34
app = Flask(__name__)
45

5-
# Simple attractive HTML page
66
HTML_PAGE = """
77
<!DOCTYPE html>
88
<html lang="en">
99
<head>
1010
<meta charset="UTF-8">
1111
<meta name="viewport" content="width=device-width, initial-scale=1.0">
12-
<title>Azure Flask Demo</title>
12+
<title>Rock Paper Scissors - Azure Demo</title>
1313
<style>
1414
body {
1515
font-family: Arial, sans-serif;
16-
background: linear-gradient(135deg, #4facfe, #00f2fe);
16+
background: linear-gradient(135deg, #667eea, #764ba2);
1717
height: 100vh;
1818
display: flex;
19-
align-items: center;
2019
justify-content: center;
20+
align-items: center;
2121
margin: 0;
22+
color: #fff;
2223
}
23-
.card {
24-
background: rgba(255,255,255,0.9);
25-
padding: 30px 40px;
26-
border-radius: 15px;
27-
box-shadow: 0px 8px 20px rgba(0,0,0,0.2);
24+
.game {
2825
text-align: center;
29-
max-width: 400px;
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);
3030
}
3131
h1 {
32-
color: #0078D4;
33-
margin-bottom: 15px;
32+
margin-bottom: 20px;
3433
}
35-
p {
36-
font-size: 18px;
37-
color: #444;
38-
}
39-
.btn {
40-
display: inline-block;
41-
margin-top: 20px;
34+
.choices button {
35+
margin: 10px;
4236
padding: 10px 20px;
43-
background: #0078D4;
37+
border: none;
38+
background: #ff9800;
4439
color: white;
45-
text-decoration: none;
4640
border-radius: 8px;
41+
cursor: pointer;
42+
font-size: 16px;
4743
transition: 0.3s;
4844
}
49-
.btn:hover {
50-
background: #005a9e;
45+
.choices button:hover {
46+
background: #e68900;
47+
}
48+
#result {
49+
margin-top: 20px;
50+
font-size: 20px;
51+
font-weight: bold;
5152
}
5253
</style>
5354
</head>
5455
<body>
55-
<div class="card">
56-
<h1>🚀 Azure Flask Demo</h1>
57-
<p>This web app is deployed on <b>Azure App Service</b> using GitHub!</p>
58-
<a class="btn" href="https://github.com" target="_blank">View on GitHub</a>
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>
5965
</div>
66+
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+
});
77+
}
78+
</script>
6079
</body>
6180
</html>
6281
"""
@@ -65,5 +84,24 @@
6584
def home():
6685
return render_template_string(HTML_PAGE)
6786

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+
68105
if __name__ == "__main__":
69106
app.run(host="0.0.0.0", port=8000)
107+

0 commit comments

Comments
 (0)