-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
157 lines (119 loc) · 3.89 KB
/
main.py
File metadata and controls
157 lines (119 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import random
import csv
from datetime import datetime
# ===============================
# かんたん翻訳ヘルパ(最低限)
# ===============================
TEXT = {
"ACT1": "培地設計",
"ACT2": "衛生巡回",
"ACT3": "菌糸ネットワーク探索",
"ACT4": "業務終了",
"P3": "まいたけ",
"MONEY_LABEL": "¥",
}
def t(key):
return TEXT.get(key, key)
def money_fmt(x):
return f"{x:,}"
# ===============================
# Logger
# ===============================
class GameLogger:
def __init__(self, filepath="run_log.csv"):
self.filepath = filepath
self.fieldnames = ["timestamp", "day", "action", "hp", "mp", "money"]
with open(self.filepath, "w", newline="", encoding="utf-8") as f:
writer = csv.DictWriter(f, fieldnames=self.fieldnames)
writer.writeheader()
def log(self, day, player, facility, action="", event=""):
row = {
"timestamp": datetime.now().isoformat(timespec="seconds"),
"day": day,
"action": action,
"hp": player.HP,
"mp": player.MP,
"money": player.money,
}
with open(self.filepath, "a", newline="", encoding="utf-8") as f:
writer = csv.DictWriter(f, fieldnames=self.fieldnames)
writer.writerow(row)
# ===============================
# Facility
# ===============================
class Facility:
def __init__(self):
self.name = "しいたけファーム"
self.pfas_level = 10
def display_info(self):
print(f"胞子汚染度: {self.pfas_level}")
def check_for_event(self):
if self.pfas_level > 50:
return "SPORE_CRISIS"
return None
# ===============================
# Player
# ===============================
class Player:
def __init__(self):
self.name = t("P3")
self.HP = 100
self.MP = 50
self.money = 0
def display_status(self):
print(f"HP:{self.HP} MP:{self.MP} 収支:{self.money}")
def do_menu_planning(self, facility):
self.money += 1000
self.MP -= 3
def do_hygiene_check(self, facility):
facility.pfas_level -= 5
self.MP -= 3
def do_special_trip(self, day):
self.MP -= 5
# ===============================
# レポート生成
# ===============================
def generate_reports(_):
print("レポート生成完了")
# ===============================
# メインゲーム
# ===============================
def start_game():
logger = GameLogger()
player = Player()
facility = Facility()
day = 1
logger.log(day, player, facility, action="start_game")
while player.HP > 0 and player.MP > 0 and day <= 10:
print(f"\n--- DAY {day} ---")
player.display_status()
facility.display_info()
print("\n--- 今日の行動を選択してください ---")
print(f"1: {t('ACT1')}")
print(f"2: {t('ACT2')}")
print(f"3: {t('ACT3')}")
print(f"4: {t('ACT4')}")
choice = input("番号を入力: ")
if choice == "1":
player.do_menu_planning(facility)
logger.log(day, player, facility, action="culture_planning")
elif choice == "2":
player.do_hygiene_check(facility)
logger.log(day, player, facility, action="hygiene_patrol")
elif choice == "3":
player.do_special_trip(day)
logger.log(day, player, facility, action="mycelium_trip")
elif choice == "4":
print("業務終了")
logger.log(day, player, facility, action="end_day")
day += 1
continue
else:
print("無効な入力")
day += 1
generate_reports("run_log.csv")
# ===============================
# 起動スイッチ(超重要)
# ===============================
if __name__ == "__main__":
start_game()