Skip to content

Commit 696209b

Browse files
[投稿] 添加脚本: 网吧模拟器(1.0) — by Daoyu268
1 parent 2deb7b1 commit 696209b

1 file changed

Lines changed: 159 additions & 0 deletions

File tree

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
import random
2+
3+
# 安全清屏(只打印换行,不调用os.system)
4+
def clear():
5+
print("\n" * 50)
6+
7+
class InternetCafeSimulator:
8+
def __init__(self):
9+
self.money = 200
10+
self.computers = 5
11+
self.occupied = 0
12+
self.hour = 8
13+
self.day = 1
14+
self.repair_cost = 30
15+
self.broken = 0
16+
self.queue = 0
17+
self.price_per_hour = 5
18+
19+
def print_status(self):
20+
clear()
21+
print("=" * 40)
22+
print("🎮 终端网吧模拟器")
23+
print("=" * 40)
24+
print(f"第 {self.day} 天 | 当前时间: {self.hour}:00")
25+
print(f"金钱: {self.money} 元")
26+
available = self.computers - self.occupied - self.broken
27+
print(f"电脑总数: {self.computers} 台 | 可用: {available} 台")
28+
print(f"正在使用: {self.occupied} 台 | 损坏: {self.broken} 台")
29+
print(f"排队顾客: {self.queue} 人")
30+
print(f"上网单价: {self.price_per_hour} 元/小时")
31+
print("=" * 40)
32+
33+
def time_pass(self):
34+
self.hour += 1
35+
if self.hour >= 24:
36+
self.hour = 0
37+
self.day += 1
38+
39+
if random.randint(1, 3) == 1:
40+
add = random.randint(0, 3)
41+
self.queue += add
42+
43+
if random.randint(1, 8) == 1:
44+
available = self.computers - self.occupied - self.broken
45+
if available > 0 and self.broken < self.computers // 3 + 1:
46+
self.broken += 1
47+
print("\n⚠️ 有一台电脑突然坏了!")
48+
49+
def use_computer(self):
50+
available = self.computers - self.occupied - self.broken
51+
if available <= 0:
52+
print("\n❌ 没有可用电脑!")
53+
input("按回车继续...")
54+
return
55+
56+
use = min(available, self.queue)
57+
if use == 0:
58+
print("\n❌ 没人来上网!")
59+
input("按回车继续...")
60+
return
61+
62+
self.occupied += use
63+
self.queue -= use
64+
earn = use * self.price_per_hour
65+
self.money += earn
66+
print(f"\n{use} 人开始上网!收入 {earn} 元")
67+
input("按回车继续...")
68+
69+
def kick_customers(self):
70+
if self.occupied == 0:
71+
print("\n❌ 没人在上网!")
72+
input("按回车继续...")
73+
return
74+
kick_num = random.randint(1, self.occupied)
75+
self.occupied -= kick_num
76+
self.queue += kick_num // 2
77+
print(f"\n⚠️ 你踢走了 {kick_num} 人,口碑变差了!")
78+
input("按回车继续...")
79+
80+
def repair_computer(self):
81+
if self.broken == 0:
82+
print("\n✅ 没有坏电脑!")
83+
input("按回车继续...")
84+
return
85+
if self.money < self.repair_cost:
86+
print("\n❌ 钱不够修电脑!")
87+
input("按回车继续...")
88+
return
89+
self.money -= self.repair_cost
90+
self.broken -= 1
91+
print("\n✅ 修好一台电脑!")
92+
input("按回车继续...")
93+
94+
def buy_computer(self):
95+
cost = 150
96+
if self.money < cost:
97+
print("\n❌ 钱不够买新电脑!")
98+
input("按回车继续...")
99+
return
100+
self.money -= cost
101+
self.computers += 1
102+
print("\n✅ 购买了一台新电脑!")
103+
input("按回车继续...")
104+
105+
def change_price(self):
106+
try:
107+
new_price = int(input("\n输入新的每小时价格: "))
108+
if 1 <= new_price <= 50:
109+
self.price_per_hour = new_price
110+
print("✅ 价格已修改!")
111+
else:
112+
print("价格必须在1~50之间")
113+
except:
114+
print("输入无效!")
115+
input("按回车继续...")
116+
117+
def close_cafe(self):
118+
self.occupied = 0
119+
self.queue = 0
120+
print("\n✅ 网吧打烊,所有人清场!")
121+
input("按回车继续...")
122+
123+
def main(self):
124+
while True:
125+
self.print_status()
126+
print("\n【菜单】")
127+
print("1. 接待顾客(开始上网)")
128+
print("2. 踢走顾客")
129+
print("3. 维修电脑")
130+
print("4. 购买新电脑")
131+
print("5. 修改上网价格")
132+
print("6. 打烊清场")
133+
print("7. 时间快进1小时")
134+
print("0. 退出游戏")
135+
choice = input("\n请选择操作: ")
136+
137+
if choice == "1":
138+
self.use_computer()
139+
elif choice == "2":
140+
self.kick_customers()
141+
elif choice == "3":
142+
self.repair_computer()
143+
elif choice == "4":
144+
self.buy_computer()
145+
elif choice == "5":
146+
self.change_price()
147+
elif choice == "6":
148+
self.close_cafe()
149+
elif choice == "7":
150+
self.time_pass()
151+
elif choice == "0":
152+
print("\n感谢游玩网吧模拟器!")
153+
break
154+
else:
155+
input("输入无效,按回车重试...")
156+
157+
if __name__ == "__main__":
158+
game = InternetCafeSimulator()
159+
game.main()

0 commit comments

Comments
 (0)