Spaces:
Running
Running
Commit ·
d61350b
1
Parent(s): 44db301
Restore Zhang Qijun project progress
Browse files
projects/2026Fall進階專題六午/張棨竣/校園謎案調查局/main.py
CHANGED
|
@@ -1,90 +1,114 @@
|
|
| 1 |
-
"""
|
| 2 |
|
| 3 |
-
|
| 4 |
"""
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
LOCATIONS = {
|
| 9 |
-
"1": {
|
| 10 |
-
"name": "六年13班教室",
|
| 11 |
-
"scene": "凌亂的座位,窗戶也碎掉了。",
|
| 12 |
-
"evidence": "玻璃碎片",
|
| 13 |
-
},
|
| 14 |
-
"2": {
|
| 15 |
-
"name": "操場的空地",
|
| 16 |
-
"scene": "地面有血跡,有人刻意用落葉阻擋的痕跡。",
|
| 17 |
-
"evidence": " 小鳥的羽毛"
|
| 18 |
-
},
|
| 19 |
-
"3": {
|
| 20 |
-
"name": "洗手台",
|
| 21 |
-
"scene": "沒有關的水龍頭,後方的垃圾桶閃著光。",
|
| 22 |
-
"evidence": "在桶子裡的水壺",
|
| 23 |
-
},
|
| 24 |
-
}
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
evidence_bag = []
|
| 27 |
|
| 28 |
|
| 29 |
def investigate(location_id):
|
| 30 |
-
"""調查地點
|
| 31 |
-
# TODO 1:確認 location_id 是否存在於 LOCATIONS。
|
| 32 |
if location_id not in LOCATIONS:
|
| 33 |
-
print("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
return
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
print(f"{
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
evidence_bag.append(location_id)
|
| 41 |
|
| 42 |
def show_evidence():
|
| 43 |
-
"""
|
| 44 |
-
# TODO 4:沒有證物時顯示提示;否則以 1 開始編號列出。
|
| 45 |
if not evidence_bag:
|
| 46 |
-
print("
|
| 47 |
return
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
|
| 53 |
def make_deduction():
|
| 54 |
-
"""
|
| 55 |
-
if len(evidence_bag) <
|
| 56 |
-
print(f"
|
|
|
|
| 57 |
return False
|
| 58 |
|
| 59 |
-
print("\n哪一個說法最符合
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
answer = input("你的推理:").strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
|
| 66 |
-
print("推理判定還沒完成。")
|
| 67 |
return False
|
| 68 |
|
| 69 |
|
| 70 |
def show_menu():
|
| 71 |
print(f"\n=== 校園謎案調查局:{CASE_TITLE} ===")
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
print("
|
| 75 |
-
print("4. 查看證物袋")
|
| 76 |
print("5. 提出推理")
|
| 77 |
-
print("6. 離開")
|
| 78 |
|
| 79 |
|
| 80 |
def main():
|
| 81 |
-
print("
|
| 82 |
|
| 83 |
while True:
|
| 84 |
show_menu()
|
| 85 |
choice = input("請選擇:").strip()
|
| 86 |
|
| 87 |
-
if
|
|
|
|
|
|
|
| 88 |
investigate(choice)
|
| 89 |
elif choice == "4":
|
| 90 |
show_evidence()
|
|
@@ -92,10 +116,10 @@ def main():
|
|
| 92 |
if make_deduction():
|
| 93 |
break
|
| 94 |
elif choice == "6":
|
| 95 |
-
print("案件暫停
|
| 96 |
break
|
| 97 |
else:
|
| 98 |
-
print("請輸入 1~6。")
|
| 99 |
|
| 100 |
|
| 101 |
if __name__ == "__main__":
|
|
|
|
| 1 |
+
"""Lesson 4:校園謎案調查局。
|
| 2 |
|
| 3 |
+
保留 case_data.json 中的案件故事,讓玩家能探索、查看線索並完成推理。
|
| 4 |
"""
|
| 5 |
|
| 6 |
+
import json
|
| 7 |
+
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
|
| 10 |
+
DATA_PATH = Path(__file__).with_name("case_data.json")
|
| 11 |
+
with DATA_PATH.open(encoding="utf-8") as data_file:
|
| 12 |
+
CASE_DATA = json.load(data_file)
|
| 13 |
+
|
| 14 |
+
CASE_TITLE = CASE_DATA["title"]
|
| 15 |
+
LOCATIONS = CASE_DATA["locations"]
|
| 16 |
+
CONCLUSIONS = CASE_DATA["conclusions"]
|
| 17 |
evidence_bag = []
|
| 18 |
|
| 19 |
|
| 20 |
def investigate(location_id):
|
| 21 |
+
"""調查地點;尚未取得必要線索時,提示玩家先完成前置調查。"""
|
|
|
|
| 22 |
if location_id not in LOCATIONS:
|
| 23 |
+
print("找不到這個地點,請輸入選單上的編號。")
|
| 24 |
+
return
|
| 25 |
+
|
| 26 |
+
location = LOCATIONS[location_id]
|
| 27 |
+
missing = [
|
| 28 |
+
evidence_id
|
| 29 |
+
for evidence_id in location.get("requires", [])
|
| 30 |
+
if evidence_id not in evidence_bag
|
| 31 |
+
]
|
| 32 |
+
if missing:
|
| 33 |
+
print(location.get("locked_text", "你還缺少必要線索,先調查其他地點。"))
|
| 34 |
+
return
|
| 35 |
+
|
| 36 |
+
print(f"\n【調查地點:{location['name']}】")
|
| 37 |
+
print(f"現場狀況:{location['scene']}")
|
| 38 |
+
|
| 39 |
+
evidence = location["evidence"]
|
| 40 |
+
evidence_id = evidence["id"]
|
| 41 |
+
if evidence_id in evidence_bag:
|
| 42 |
+
print("這裡已經調查過了,沒有新的線索。")
|
| 43 |
return
|
| 44 |
+
|
| 45 |
+
evidence_bag.append(evidence_id)
|
| 46 |
+
print(f"取得線索:{evidence['name']}")
|
| 47 |
+
print(evidence["detail"])
|
| 48 |
+
|
|
|
|
| 49 |
|
| 50 |
def show_evidence():
|
| 51 |
+
"""顯示已取得的線索與線索細節。"""
|
|
|
|
| 52 |
if not evidence_bag:
|
| 53 |
+
print("目前還沒有線索,先選擇地點進行調查。")
|
| 54 |
return
|
| 55 |
+
|
| 56 |
+
print("\n=== 線索紀錄 ===")
|
| 57 |
+
evidence_by_id = {
|
| 58 |
+
location["evidence"]["id"]: location["evidence"]
|
| 59 |
+
for location in LOCATIONS.values()
|
| 60 |
+
}
|
| 61 |
+
for number, evidence_id in enumerate(evidence_bag, start=1):
|
| 62 |
+
evidence = evidence_by_id[evidence_id]
|
| 63 |
+
print(f"{number}. {evidence['name']}:{evidence['detail']}")
|
| 64 |
|
| 65 |
|
| 66 |
def make_deduction():
|
| 67 |
+
"""線索不足時擋下結案;答錯可繼續調查與推理。"""
|
| 68 |
+
if len(evidence_bag) < len(LOCATIONS):
|
| 69 |
+
print(f"線索不足:目前 {len(evidence_bag)}/{len(LOCATIONS)}。")
|
| 70 |
+
print("先完成各地點調查,再回來提出推理。")
|
| 71 |
return False
|
| 72 |
|
| 73 |
+
print("\n哪一個說法最符合目前找到的線索?")
|
| 74 |
+
for number, conclusion in CONCLUSIONS.items():
|
| 75 |
+
print(f"{number}. {conclusion}")
|
| 76 |
+
|
| 77 |
answer = input("你的推理:").strip()
|
| 78 |
+
if not answer:
|
| 79 |
+
print("你還沒有輸入答案,請選擇一個說法。")
|
| 80 |
+
return False
|
| 81 |
+
if answer not in CONCLUSIONS:
|
| 82 |
+
print(f"請輸入 {', '.join(CONCLUSIONS)}。")
|
| 83 |
+
return False
|
| 84 |
+
|
| 85 |
+
if answer == CASE_DATA["correct_answer"]:
|
| 86 |
+
print(f"\n{CASE_DATA['success']}")
|
| 87 |
+
return True
|
| 88 |
|
| 89 |
+
print("這個說法還無法解釋所有線索,再查看一次線索紀錄吧。")
|
|
|
|
| 90 |
return False
|
| 91 |
|
| 92 |
|
| 93 |
def show_menu():
|
| 94 |
print(f"\n=== 校園謎案調查局:{CASE_TITLE} ===")
|
| 95 |
+
for location_id, location in LOCATIONS.items():
|
| 96 |
+
print(f"{location_id}. 調查{location['name']}")
|
| 97 |
+
print("4. 查看線索紀錄")
|
|
|
|
| 98 |
print("5. 提出推理")
|
| 99 |
+
print("6. 暫停調查並離開")
|
| 100 |
|
| 101 |
|
| 102 |
def main():
|
| 103 |
+
print(CASE_DATA["intro"])
|
| 104 |
|
| 105 |
while True:
|
| 106 |
show_menu()
|
| 107 |
choice = input("請選擇:").strip()
|
| 108 |
|
| 109 |
+
if not choice:
|
| 110 |
+
print("你還沒有輸入,請選擇選單上的編號。")
|
| 111 |
+
elif choice in LOCATIONS:
|
| 112 |
investigate(choice)
|
| 113 |
elif choice == "4":
|
| 114 |
show_evidence()
|
|
|
|
| 116 |
if make_deduction():
|
| 117 |
break
|
| 118 |
elif choice == "6":
|
| 119 |
+
print("案件暫停,感謝你的調查。")
|
| 120 |
break
|
| 121 |
else:
|
| 122 |
+
print("找不到這個選項,請輸入 1~6。")
|
| 123 |
|
| 124 |
|
| 125 |
if __name__ == "__main__":
|