This commit is contained in:
cnrenil 2024-09-21 21:12:44 +08:00
parent 983bb7ff5f
commit a1551cec3b
3 changed files with 10 additions and 4 deletions

6
app.py
View File

@ -1,4 +1,4 @@
from flask import Flask, render_template, session, redirect, url_for from flask import Flask, render_template, send_from_directory, session, redirect, url_for
app = Flask(__name__) app = Flask(__name__)
app.secret_key = 'jiangsir' # 用于加密session的密钥 app.secret_key = 'jiangsir' # 用于加密session的密钥
@ -17,5 +17,9 @@ def admin_can_list_root():
session['user'] = 'guest' session['user'] = 'guest'
return "No admin!!" return "No admin!!"
@app.route('/assets/<path:filename>')
def assets(filename):
return send_from_directory('assets', filename)
if __name__ == '__main__': if __name__ == '__main__':
app.run(debug=True, use_reloader=False, host='0.0.0.0', port=80) app.run(debug=True, use_reloader=False, host='0.0.0.0', port=80)

BIN
assets/bg.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

View File

@ -7,11 +7,12 @@
<style> <style>
body { body {
text-align: center; text-align: center;
background-color: #f0f0f0; background-image: url('assets/bg.webp'); /* 设置背景图片 */
background-size: cover; /* 背景图片覆盖整个页面 */
} }
canvas { canvas {
border: 1px solid #000; border: 1px solid #000;
background-color: #fff; background-color: rgba(135,206,250, 0.6);
} }
#message { #message {
font-size: 24px; font-size: 24px;
@ -30,7 +31,7 @@
</style> </style>
</head> </head>
<body> <body>
<h1>Snake Game,please use your keyboard to control the snake!!!</h1> <h1>Snake Game, please use your keyboard to control the snake!!!</h1>
<canvas id="gameCanvas" width="400" height="400"></canvas> <canvas id="gameCanvas" width="400" height="400"></canvas>
<div id="message">Score: 0</div> <div id="message">Score: 0</div>
<button id="restart" onclick="restartGame()">Restart</button> <button id="restart" onclick="restartGame()">Restart</button>
@ -38,6 +39,7 @@
<script> <script>
const canvas = document.getElementById('gameCanvas'); const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext('2d');
ctx.globalAlpha = 0.6;
const box = 20; const box = 20;
let snake = [{ x: 9 * box, y: 10 * box }]; let snake = [{ x: 9 * box, y: 10 * box }];
let food = { let food = {