Spaces:
Running
Running
jiang buqing
commited on
Commit
·
2e254f6
1
Parent(s):
51fe0af
1. 删除放弃按钮
Browse files2. 新游戏必须猜出来才能按
- .gitignore +3 -1
- app.py +12 -10
- static/css/style.css +8 -0
- static/js/app.js +21 -38
- templates/index.html +0 -1
.gitignore
CHANGED
@@ -32,4 +32,6 @@ Thumbs.db
|
|
32 |
.idea/
|
33 |
.vscode/
|
34 |
*.swp
|
35 |
-
*.swo
|
|
|
|
|
|
32 |
.idea/
|
33 |
.vscode/
|
34 |
*.swp
|
35 |
+
*.swo
|
36 |
+
|
37 |
+
Semantic_Hunter.code-workspace
|
app.py
CHANGED
@@ -86,9 +86,18 @@ def game_status():
|
|
86 |
@app.route('/new-game', methods=['POST'])
|
87 |
def new_game():
|
88 |
global game_state
|
89 |
-
|
90 |
-
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
@app.route('/guess', methods=['POST'])
|
94 |
def guess():
|
@@ -135,13 +144,6 @@ def guess():
|
|
135 |
|
136 |
return jsonify(response)
|
137 |
|
138 |
-
@app.route('/give-up', methods=['POST'])
|
139 |
-
def give_up():
|
140 |
-
return jsonify({
|
141 |
-
"status": "success",
|
142 |
-
"secret_word": game_state["secret_word"]
|
143 |
-
})
|
144 |
-
|
145 |
if __name__ == '__main__':
|
146 |
port = int(os.environ.get("PORT", 7860))
|
147 |
print(f"启动服务器在端口: {port}")
|
|
|
86 |
@app.route('/new-game', methods=['POST'])
|
87 |
def new_game():
|
88 |
global game_state
|
89 |
+
|
90 |
+
# 检查是否有人已经猜对了
|
91 |
+
has_correct_guess = any(guess["is_correct"] for guess in game_state["guesses"])
|
92 |
+
|
93 |
+
# 只有在已经猜中的情况下才重置游戏
|
94 |
+
if has_correct_guess:
|
95 |
+
# 重置游戏状态
|
96 |
+
game_state = initialize_game_state()
|
97 |
+
return jsonify({"status": "success", "message": "新游戏已开始"})
|
98 |
+
else:
|
99 |
+
# 不重置游戏状态
|
100 |
+
return jsonify({"status": "success", "message": "游戏仍在进行中"})
|
101 |
|
102 |
@app.route('/guess', methods=['POST'])
|
103 |
def guess():
|
|
|
144 |
|
145 |
return jsonify(response)
|
146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
if __name__ == '__main__':
|
148 |
port = int(os.environ.get("PORT", 7860))
|
149 |
print(f"启动服务器在端口: {port}")
|
static/css/style.css
CHANGED
@@ -76,6 +76,14 @@ h1 {
|
|
76 |
transform: translateY(-2px);
|
77 |
}
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
.btn-primary {
|
80 |
background-color: var(--highlight-color);
|
81 |
color: var(--primary-color);
|
|
|
76 |
transform: translateY(-2px);
|
77 |
}
|
78 |
|
79 |
+
.btn:disabled {
|
80 |
+
background-color: #4b5563;
|
81 |
+
color: #9ca3af;
|
82 |
+
cursor: not-allowed;
|
83 |
+
opacity: 0.6;
|
84 |
+
transform: none;
|
85 |
+
}
|
86 |
+
|
87 |
.btn-primary {
|
88 |
background-color: var(--highlight-color);
|
89 |
color: var(--primary-color);
|
static/js/app.js
CHANGED
@@ -11,7 +11,6 @@ class SemanticHunterUI {
|
|
11 |
this.messageArea = document.getElementById('message-area');
|
12 |
this.guessesList = document.getElementById('guesses-list');
|
13 |
this.newGameBtn = document.getElementById('new-game-btn');
|
14 |
-
this.giveUpBtn = document.getElementById('give-up-btn');
|
15 |
this.itemsPerPage = 7;
|
16 |
}
|
17 |
|
@@ -254,22 +253,6 @@ class SemanticHunterAPI {
|
|
254 |
throw new Error('无法连接到服务器');
|
255 |
}
|
256 |
}
|
257 |
-
|
258 |
-
// 放弃游戏
|
259 |
-
async giveUp() {
|
260 |
-
try {
|
261 |
-
const response = await fetch('/give-up', {
|
262 |
-
method: 'POST',
|
263 |
-
headers: {
|
264 |
-
'Content-Type': 'application/json'
|
265 |
-
}
|
266 |
-
});
|
267 |
-
return await response.json();
|
268 |
-
} catch (error) {
|
269 |
-
console.error('放弃游戏时出错:', error);
|
270 |
-
throw new Error('无法连接到服务器');
|
271 |
-
}
|
272 |
-
}
|
273 |
}
|
274 |
|
275 |
/**
|
@@ -286,6 +269,9 @@ class SemanticHunterGame {
|
|
286 |
this.allGuesses = []; // 所有猜测历史
|
287 |
this.currentPage = 1; // 当前分页
|
288 |
|
|
|
|
|
|
|
289 |
// 初始化事件监听器
|
290 |
this.initEventListeners();
|
291 |
|
@@ -300,7 +286,6 @@ class SemanticHunterGame {
|
|
300 |
if (e.key === 'Enter') this.submitGuess();
|
301 |
});
|
302 |
this.ui.newGameBtn.addEventListener('click', () => this.initGame());
|
303 |
-
this.ui.giveUpBtn.addEventListener('click', () => this.giveUp());
|
304 |
}
|
305 |
|
306 |
// 加载游戏状态 - 从后端获取当前状态
|
@@ -330,6 +315,9 @@ class SemanticHunterGame {
|
|
330 |
this.ui.showMessage('游戏开始! 尝试猜测秘密词语!');
|
331 |
}
|
332 |
|
|
|
|
|
|
|
333 |
// 清空输入框并聚焦
|
334 |
this.ui.clearAndFocusInput();
|
335 |
} else {
|
@@ -352,6 +340,9 @@ class SemanticHunterGame {
|
|
352 |
this.latestGuess = null;
|
353 |
this.currentPage = 1;
|
354 |
this.ui.showMessage('新游戏开始! 尝试猜测秘密词语!');
|
|
|
|
|
|
|
355 |
} else {
|
356 |
this.ui.showError(data.message || '初始化游戏时出错');
|
357 |
}
|
@@ -393,6 +384,9 @@ class SemanticHunterGame {
|
|
393 |
this.ui.showMessage(`相似度: ${data.similarity}%`);
|
394 |
}
|
395 |
|
|
|
|
|
|
|
396 |
// 清空输入框并聚焦
|
397 |
this.ui.clearAndFocusInput();
|
398 |
} else {
|
@@ -403,26 +397,6 @@ class SemanticHunterGame {
|
|
403 |
}
|
404 |
}
|
405 |
|
406 |
-
// 放弃游戏
|
407 |
-
async giveUp() {
|
408 |
-
if (!this.gameActive) {
|
409 |
-
this.ui.showError('游戏已结束,请点击新游戏');
|
410 |
-
return;
|
411 |
-
}
|
412 |
-
|
413 |
-
try {
|
414 |
-
const data = await this.api.giveUp();
|
415 |
-
if (data.status === 'success') {
|
416 |
-
this.gameActive = false;
|
417 |
-
this.ui.showError(`你放弃了! 秘密词语是: ${data.secret_word}`);
|
418 |
-
} else {
|
419 |
-
this.ui.showError(data.message || '放弃游戏时出错');
|
420 |
-
}
|
421 |
-
} catch (error) {
|
422 |
-
this.ui.showError(error.message);
|
423 |
-
}
|
424 |
-
}
|
425 |
-
|
426 |
// 更新猜测列表 - 同时处理最新猜测和历史猜测
|
427 |
updateGuessList(guesses, latestGuess) {
|
428 |
// 渲染猜测列表
|
@@ -436,6 +410,15 @@ class SemanticHunterGame {
|
|
436 |
});
|
437 |
}
|
438 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
439 |
}
|
440 |
|
441 |
// 当DOM内容加载完成时初始化游戏
|
|
|
11 |
this.messageArea = document.getElementById('message-area');
|
12 |
this.guessesList = document.getElementById('guesses-list');
|
13 |
this.newGameBtn = document.getElementById('new-game-btn');
|
|
|
14 |
this.itemsPerPage = 7;
|
15 |
}
|
16 |
|
|
|
253 |
throw new Error('无法连接到服务器');
|
254 |
}
|
255 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
256 |
}
|
257 |
|
258 |
/**
|
|
|
269 |
this.allGuesses = []; // 所有猜测历史
|
270 |
this.currentPage = 1; // 当前分页
|
271 |
|
272 |
+
// 初始设置新游戏按钮为禁用状态
|
273 |
+
this.ui.newGameBtn.disabled = true;
|
274 |
+
|
275 |
// 初始化事件监听器
|
276 |
this.initEventListeners();
|
277 |
|
|
|
286 |
if (e.key === 'Enter') this.submitGuess();
|
287 |
});
|
288 |
this.ui.newGameBtn.addEventListener('click', () => this.initGame());
|
|
|
289 |
}
|
290 |
|
291 |
// 加载游戏状态 - 从后端获取当前状态
|
|
|
315 |
this.ui.showMessage('游戏开始! 尝试猜测秘密词语!');
|
316 |
}
|
317 |
|
318 |
+
// 更新新游戏按钮状态
|
319 |
+
this.updateNewGameButton();
|
320 |
+
|
321 |
// 清空输入框并聚焦
|
322 |
this.ui.clearAndFocusInput();
|
323 |
} else {
|
|
|
340 |
this.latestGuess = null;
|
341 |
this.currentPage = 1;
|
342 |
this.ui.showMessage('新游戏开始! 尝试猜测秘密词语!');
|
343 |
+
|
344 |
+
// 更新新游戏按钮状态
|
345 |
+
this.updateNewGameButton();
|
346 |
} else {
|
347 |
this.ui.showError(data.message || '初始化游戏时出错');
|
348 |
}
|
|
|
384 |
this.ui.showMessage(`相似度: ${data.similarity}%`);
|
385 |
}
|
386 |
|
387 |
+
// 更新新游戏按钮状态
|
388 |
+
this.updateNewGameButton();
|
389 |
+
|
390 |
// 清空输入框并聚焦
|
391 |
this.ui.clearAndFocusInput();
|
392 |
} else {
|
|
|
397 |
}
|
398 |
}
|
399 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
400 |
// 更新猜测列表 - 同时处理最新猜测和历史猜测
|
401 |
updateGuessList(guesses, latestGuess) {
|
402 |
// 渲染猜测列表
|
|
|
410 |
});
|
411 |
}
|
412 |
}
|
413 |
+
|
414 |
+
// 更新新游戏按钮状态
|
415 |
+
updateNewGameButton() {
|
416 |
+
// 检查是否有正确的猜测
|
417 |
+
const hasCorrectGuess = this.allGuesses.some(guess => guess.is_correct);
|
418 |
+
|
419 |
+
// 只有在游戏已结束(有正确猜测)时,新游戏按钮才可用
|
420 |
+
this.ui.newGameBtn.disabled = !hasCorrectGuess;
|
421 |
+
}
|
422 |
}
|
423 |
|
424 |
// 当DOM内容加载完成时初始化游戏
|
templates/index.html
CHANGED
@@ -16,7 +16,6 @@
|
|
16 |
<h1>词猎人 <span class="subtitle">| Semantic Hunter</span></h1>
|
17 |
<div class="controls">
|
18 |
<button id="new-game-btn" class="btn"><i class="fas fa-sync-alt"></i> 新游戏</button>
|
19 |
-
<button id="give-up-btn" class="btn btn-danger"><i class="fas fa-flag"></i> 放弃</button>
|
20 |
</div>
|
21 |
</header>
|
22 |
|
|
|
16 |
<h1>词猎人 <span class="subtitle">| Semantic Hunter</span></h1>
|
17 |
<div class="controls">
|
18 |
<button id="new-game-btn" class="btn"><i class="fas fa-sync-alt"></i> 新游戏</button>
|
|
|
19 |
</div>
|
20 |
</header>
|
21 |
|