roulette-game 1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of roulette-game might be problematic. Click here for more details.

@@ -0,0 +1,296 @@
1
+ # 主程序(没错,运行它!)
2
+ __version__ = "1.0" # 版本说明(没什么用)
3
+
4
+ # 外部导入
5
+ cannotuseGUI = False
6
+ from random import shuffle
7
+ from time import sleep
8
+ import pygame
9
+ from traceback import print_exc
10
+ from os import chdir
11
+ # 模块导入
12
+ from roles import *
13
+ from data import *
14
+ try:
15
+ from sprites import Button
16
+ except:
17
+ print("警告!无法导入sprites.py,无法使用窗口模式!")
18
+ cannotuseGUI = True
19
+ # 以下是主程序
20
+ chdir(DIR)
21
+ health = [2,4,6]
22
+ buckshots = [ # 子弹(1代表实,0代表空)
23
+ [
24
+ [1,0,0],
25
+ [1,1,0,0]
26
+ ],
27
+ [
28
+ [1,0],
29
+ [1,1,0,0,0],
30
+ [1,1,1,0,0,0],
31
+ [1,1,1,1,0,0,0,0]
32
+ ],
33
+ [
34
+ [1,1,1,1,1,0,0,0],
35
+ [1,1,1,1,0,0,0,0],
36
+ [1,1,1,0],
37
+ [1,1,1,1,0,0,0,0]
38
+ ]
39
+ ]
40
+ try:
41
+ if cannotuseGUI:
42
+ mode = 2
43
+ else:
44
+ mode = int(input("请选择模式(壳程序按0(更为稳定),窗口按1(游戏体验更好)):"))
45
+ if mode:
46
+ FPS = int(input("请设置帧率(如果设的太高您的计算机可能运行不了,区间:1~200):"))
47
+ assert FPS >= 1 and FPS <= 200,"FPS out of range"
48
+ pygame.init()
49
+ # 以下是一些关于pygame的一些常量声明
50
+ # 以下是初始化
51
+ clock = pygame.time.Clock() # 初始化时钟
52
+ screen = pygame.display.set_mode((1400,850)) # 屏幕(窗口)初始化
53
+ pygame.display.set_caption("Buckshot Roulette") # 设置标题
54
+ background = pygame.image.load(BACKGROUND) # 加载背景图
55
+ gunimage = pygame.image.load(GUN) # 加载霰弹枪图片
56
+ charge = pygame.image.load(CHARGE) # 加载血量图片
57
+ blank = pygame.image.load(BLANK) # 加载空弹图片
58
+ liveround = pygame.image.load(LIVEROUND) # 加载实弹图片
59
+ dealershootself = pygame.image.load(SHOOTSELF) # 加载恶魔射击自己时的图片
60
+ dealershootplayer = pygame.image.load(SHOOTPLAYER) # 加载恶魔射击玩家时的图片
61
+ buckshotlocation = blank.get_rect() # 获取子弹显示位置
62
+ shootlocation = dealershootself.get_rect() # 获取恶魔射击时的位置
63
+ chargelocation = charge.get_rect() # 获取血量显示位置
64
+ gunimage.set_alpha(0) # 完全透明(此图是为了绘制边框)
65
+ gun = Button(675,300,gunimage,1) # 加载按钮(Button类的定义在sprites.py)
66
+ pygame.mixer.music.load(BGM) # 加载背景音乐(BGM)
67
+ liveplayermusic = pygame.mixer.Sound(LIVEPLAYER) # 玩家被击中时的音效
68
+ livedealermusic = pygame.mixer.Sound(LIVEDEALER) # 恶魔被击中时的音效
69
+ blankmusic = pygame.mixer.Sound(BLANKMUSIC) # 空弹发射时的音效
70
+ shootlocation.center = (700,300) # 设置恶魔射击时的位置
71
+ text = pygame.font.Font(FONT,75) # 设定字体
72
+ nametext = text.render("Enter name:",False,WHITE) # 用字体生成文字
73
+ playerlose = text.render("dealer win!",False,WHITE) # 用字体生成文字
74
+ loseorwinlocation = playerlose.get_rect()
75
+ loseorwinlocation.center = (700,425)
76
+ nametextlocation = nametext.get_rect()
77
+ nametextlocation.center = (700,100)
78
+ shootdealer = Button(700,75,text.render("DEALER",False,WHITE),1)
79
+ dealerturntext = text.render("dealer's turn",False,WHITE)
80
+ buttons = []
81
+ name = ""
82
+ for i in range(26):buttons.append(Button(50*(i+1),700,pygame.image.load(f"assets/{LETTERS[i]}.png")))
83
+ delete = Button(350,760,pygame.image.load(DELETE))
84
+ enter = Button(800,760,pygame.image.load(ENTER))
85
+ # 以下是一些控制变量
86
+ naming = True # 正在命名
87
+ playerturn = False # 玩家回合
88
+ dealerturn = False # 恶魔回合
89
+ choosing = False
90
+ drawingbuckshots = False
91
+ wasd = int(0)
92
+ turn = [0,0]
93
+ dealer = Dealer(2)
94
+ player = Player(2,name)
95
+ # 以下是游戏主循环
96
+ pygame.mixer.music.play(-1)
97
+ while True:
98
+ for event in pygame.event.get():
99
+ if event.type == pygame.QUIT:
100
+ raise SystemExit
101
+ screen.blit(background,(0,0))
102
+ if not player.gethealth():
103
+ screen.blit(playerlose,loseorwinlocation)
104
+ pygame.display.update()
105
+ sleep(3)
106
+ raise SystemExit
107
+ if not dealer.gethealth():
108
+ turn[1] = 0
109
+ turn[0] += 1
110
+ del buckshot
111
+ screen.blit(playerwin,loseorwinlocation)
112
+ pygame.display.update()
113
+ sleep(3)
114
+ if turn[0] == 3:
115
+ raise SystemExit
116
+ else:
117
+ dealer = Dealer(health[turn[0]])
118
+ player = Player(health[turn[0]],name)
119
+ try:buckshot[0]
120
+ except:
121
+ if turn[0] < 3:
122
+ buckshot = buckshots[turn[0]][turn[1]]
123
+ turn[1] += 1
124
+ if not naming:
125
+ playerturn = dealerturn = False
126
+ drawingbuckshots = True
127
+ if naming:
128
+ screen.blit(nametext,nametextlocation)
129
+ for i in buttons:
130
+ if i.run(screen):
131
+ name += (LETTERS[buttons.index(i)])
132
+ if delete.run(screen):
133
+ name = name[:-1]
134
+ if enter.run(screen):
135
+ naming = False
136
+ drawingbuckshots = True
137
+ shootyou = Button(700,700,text.render(name,False,WHITE),1)
138
+ playerwin = text.render(f"{name} win!",False,WHITE)
139
+ player.setname(name)
140
+ tmpnametext = text.render(name,False,WHITE)
141
+ tmpnametextlocation = tmpnametext.get_rect()
142
+ tmpnametextlocation.center = (700,400)
143
+ screen.blit(tmpnametext,tmpnametextlocation)
144
+ elif playerturn:
145
+ for i in range(player.gethealth()):
146
+ chargelocation.bottomleft = (0,850-50*i)
147
+ screen.blit(charge,chargelocation)
148
+ for i in range(dealer.gethealth()):
149
+ chargelocation.topleft = (0,0+50*i)
150
+ screen.blit(charge,chargelocation)
151
+ if gun.run(screen):
152
+ playerturn = False
153
+ choosing = True
154
+ elif dealerturn:
155
+ screen.blit(dealerturntext,nametextlocation)
156
+ for i in range(player.gethealth()):
157
+ chargelocation.bottomleft = (0,850-50*i)
158
+ screen.blit(charge,chargelocation)
159
+ for i in range(dealer.gethealth()):
160
+ chargelocation.topleft = (0,0+50*i)
161
+ screen.blit(charge,chargelocation)
162
+ if dealer.shoot() == 0:
163
+ print("dealer shooting himself!")
164
+ screen.blit(dealershootself,shootlocation)
165
+ if buckshot[0]:
166
+ livedealermusic.play()
167
+ dealer.hurt()
168
+ dealerturn = False
169
+ playerturn = True
170
+ else:
171
+ blankmusic.play()
172
+ else:
173
+ print(f"dealer shooting {name}")
174
+ screen.blit(dealershootplayer,shootlocation)
175
+ if buckshot[0]:
176
+ liveplayermusic.play()
177
+ player.hurt()
178
+ else:
179
+ blankmusic.play()
180
+ dealerturn = False
181
+ playerturn = True
182
+ del buckshot[0]
183
+ pygame.display.update()
184
+ sleep(2)
185
+ elif choosing:
186
+ for i in range(player.gethealth()):
187
+ chargelocation.bottomleft = (0,850-50*i)
188
+ screen.blit(charge,chargelocation)
189
+ for i in range(dealer.gethealth()):
190
+ chargelocation.topleft = (0,0+50*i)
191
+ screen.blit(charge,chargelocation)
192
+ if shootdealer.run(screen):
193
+ print(f"{name} shooting dealer!")
194
+ choosing = False
195
+ dealerturn = True
196
+ if buckshot[0] == 0:
197
+ blankmusic.play()
198
+ else:
199
+ livedealermusic.play()
200
+ dealer.hurt()
201
+ del buckshot[0]
202
+ sleep(2)
203
+ elif shootyou.run(screen):
204
+ print(f"{name} shooting himself!")
205
+ choosing = False
206
+ if buckshot[0] == 0:
207
+ blankmusic.play()
208
+ playerturn = True
209
+ else:
210
+ liveplayermusic.play()
211
+ player.hurt()
212
+ dealerturn = True
213
+ del buckshot[0]
214
+ sleep(2)
215
+ elif drawingbuckshots:
216
+ for en,b in enumerate(buckshot):
217
+ buckshotlocation.topleft = (400+80 * en,400)
218
+ if b:
219
+ screen.blit(liveround,buckshotlocation)
220
+ else:
221
+ screen.blit(blank,buckshotlocation)
222
+ pygame.display.update()
223
+ sleep(2)
224
+ drawingbuckshots = False
225
+ playerturn = True
226
+ shuffle(buckshot)
227
+ else:
228
+ raise TypeError("Nothing is Running!!!")
229
+ pygame.display.update()
230
+ clock.tick(FPS)
231
+ else:
232
+ name = input("你的名字:") # 输入名字
233
+ for j in range(3): # 三个回合
234
+ dealer = Dealer(health[j]) # 恶魔初始化
235
+ player = Player(health[j],name) # 玩家初始化
236
+ for i in range(len(buckshots[j])): # 每一小轮
237
+ buckshot = buckshots[j][i] # 初始化本轮子弹
238
+ buckshotcount = [0,0] #子弹计数
239
+ for k in buckshot: # 实弹
240
+ if k:buckshotcount[0]+=1
241
+ for k in buckshot: # 空弹
242
+ if k == 0:buckshotcount[1]+=1
243
+ next = 0 # 下一轮
244
+ shuffle(buckshot) # 打乱子弹顺序
245
+ print(f"{buckshotcount[0]}发实弹,{buckshotcount[1]}发空弹") # 打印子弹提示
246
+ for i in range(len(buckshot)): #
247
+ print(f"恶魔血量:{dealer.gethealth()} {name}的血量:{player.gethealth()}")
248
+ if next == 0:
249
+ if player.shoot():
250
+ if buckshot[i]:
251
+ print("砰!!!")
252
+ dealer.hurt() # 受伤
253
+ else:
254
+ print("咔......")
255
+ next = 1
256
+ else:
257
+ if buckshot[i]:
258
+ print("砰!!!")
259
+ player.hurt()
260
+ next = 1
261
+ else:
262
+ print("咔......")
263
+ else:
264
+ if dealer.shoot():
265
+ print(f"恶魔选择向{name}开枪!!!")
266
+ if buckshot[i]:
267
+ print("砰!!!")
268
+ player.hurt()
269
+ else:
270
+ print("咔......")
271
+ next = 0
272
+ else:
273
+ print("恶魔选择向自己开枪......")
274
+ if buckshot[i]:
275
+ print("砰!!!")
276
+ dealer.hurt()
277
+ next = 0
278
+ else:
279
+ print("咔......")
280
+ if dealer.gethealth() == 0 or player.gethealth() == 0:exit()
281
+ sleep(1.5)
282
+ del dealer
283
+ del player
284
+ except KeyboardInterrupt:
285
+ print("\n检测到^C")
286
+ exit()
287
+ except SystemExit:pass
288
+ except:
289
+ print("抱歉,我们检测到了一个错误,这可能不是您造成的,但您无法继续进行游戏了")
290
+ print("错误信息:")
291
+ print_exc()
292
+ print("游戏结束!")
293
+ print("感谢您的游玩!")
294
+ print("名称:Buckshot Roulette(恶魔轮盘赌)")
295
+ print("版本:1.0")
296
+ print("LevoLet Inc.")
@@ -0,0 +1,29 @@
1
+ # 此文件用于定义各种常量(必须)各种改动可在这里进行(比如路径)
2
+
3
+ ASSESTS = "assets/" # 修改为存放图片背景音乐等素材的目录
4
+ DIR = "/home/gqx/codelab/Buckshot_Roulette/" #修改为此程序存放的路径
5
+ RED = (255, 0, 0)
6
+ WHITE = (255,255,255)
7
+ BACKGROUND = f"{ASSESTS}bg.png"
8
+ BGM = f"{ASSESTS}bgmsc.ogg"
9
+ FONT = f"{ASSESTS}Simhei.ttf"
10
+ LETTERS = ("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z")
11
+ DELETE = f"{ASSESTS}DELETE.png"
12
+ ENTER = f"{ASSESTS}ENTER.png"
13
+ CHARGE = f"{ASSESTS}charge.png"
14
+ GUN = f"{ASSESTS}gun.png"
15
+ BLANKMUSIC = f"{ASSESTS}blank.wav"
16
+ LIVEDEALER = f"{ASSESTS}livedealer.wav"
17
+ LIVEPLAYER = f"{ASSESTS}liveplayer.wav"
18
+ BLANK = f"{ASSESTS}blank.png"
19
+ LIVEROUND = f"{ASSESTS}liveround.png"
20
+ SHOOTSELF = f"{ASSESTS}dealershootself.png"
21
+ SHOOTPLAYER= f"{ASSESTS}dealershootplayer.png"
22
+ SMOKE = f"{ASSESTS}smoke.png"
23
+ HANDCUFF = f"{ASSESTS}handcuff.png"
24
+ MAGNIFIER = f"{ASSESTS}magnifier.png"
25
+ KNIFE = f"{ASSESTS}knife.png"
26
+ PROPBOX = f"{ASSESTS}propbox.png"
27
+ BEER = f"{ASSESTS}beer.png"
28
+ PILL = f"{ASSESTS}pill.png"
29
+ NONEPROP = f"{ASSESTS}noneprop.png"
@@ -0,0 +1,108 @@
1
+ # 此文件用于定义角色类(必须)
2
+ from random import random
3
+
4
+ class Dealer: # 恶魔
5
+ def __init__(self,health,prop = []) -> None: # 初始化
6
+ self.__tophealth = health
7
+ self.__health = health
8
+ self.__prop = prop
9
+
10
+ def gethealth(self) -> int:
11
+ return self.__health
12
+
13
+ def smoke(self) -> None:
14
+ if self.__health < self.__tophealth:
15
+ self.__health += 1
16
+
17
+ def setprop(self,prop) -> None: # 抽取道具
18
+ self.__prop.append(prop)
19
+
20
+ def getprop(self) -> list:
21
+ return self.__prop
22
+
23
+ def shoot(self) -> int: # 开枪
24
+ if random() >= 0.5:return 1 # 1:向玩家开枪,0:向自己开枪
25
+ else:return 0
26
+
27
+ def useprop(self) -> int: # 使用道具
28
+ '''
29
+ args:None
30
+ return:
31
+ (1:使用道具
32
+ (
33
+ 0:不用)
34
+ )
35
+ '''
36
+ while True:
37
+ rdm = random()
38
+ if rdm <= 0.19: # 啤酒
39
+ if 1 in self.__prop:
40
+ del self.__prop[self.__prop.index(1)]
41
+ return 1
42
+ elif rdm <= 0.38: # 烟
43
+ if 2 in self.__prop:
44
+ del self.__prop[self.__prop.index(2)]
45
+ return 2
46
+ elif rdm <= 0.57: # 手铐
47
+ if 3 in self.__prop:
48
+ del self.__prop[self.__prop.index(3)]
49
+ return 3
50
+ elif rdm <= 0.76: # 小刀
51
+ if 4 in self.__prop:
52
+ del self.__prop[self.__prop.index(4)]
53
+ return 4
54
+ elif rdm <= 0.95: # 放大镜
55
+ if 5 in self.__prop:
56
+ del self.__prop[self.__prop.index(5)]
57
+ return 5
58
+ else:return 0
59
+
60
+ def hurt(self):
61
+ self.__health -= 1
62
+ print("恶魔:啊!!!")
63
+ if self.__health == 0:
64
+ print("恶魔死了!!!")
65
+
66
+ class Player: # 人(玩家)
67
+ def __init__(self,health,name,prop = []) -> None: # 初始化(设置血量)
68
+ self.__tophealth = health
69
+ self.__health = health
70
+ self.__name = name
71
+ self.__prop = prop
72
+
73
+ def smoke(self) -> None:
74
+ if self.__health < self.__tophealth:
75
+ self.__health += 1
76
+
77
+ def shoot(self) -> int: # 打出
78
+ return int(input(f"{self.__name}想射:"))
79
+
80
+ def gethealth(self) -> int:
81
+ return self.__health
82
+
83
+ def getprop(self) -> list:
84
+ return self.__prop
85
+
86
+ def useprop(self): # 抽取道具
87
+ while True:
88
+ using = int(input(f"使用道具:"))
89
+ if using in self.__prop:
90
+ del self.__prop[self.__prop.index(using)]
91
+ return using
92
+ elif using == 0:
93
+ return 0
94
+ else:
95
+ print("没有此道具")
96
+
97
+ def setprop(self,prop) -> None: # 抽取道具
98
+ self.__prop.append(prop)
99
+
100
+ def hurt(self) -> int: # 受伤
101
+ self.__health -= 1
102
+ print(f"{self.__name}:啊!!!")
103
+ if self.__health == 0:
104
+ print(f"{self.__name}死了!!!")
105
+ raise SystemExit
106
+
107
+ def setname(self,name):
108
+ self.__name = name
@@ -0,0 +1,28 @@
1
+ # 此文件用于声明用于pygame的类(不必须,但使用窗口模式时需要)
2
+ import pygame
3
+ from data import *
4
+
5
+ class Button:
6
+ def __init__(self,x,y,image,mode = 0):
7
+ self.image = image
8
+ self.location = self.image.get_rect()
9
+ if mode == 0:
10
+ self.location.topleft = (x,y)
11
+ else:
12
+ self.location.center = (x,y)
13
+ x = self.location.topleft[0]
14
+ y = self.location.topleft[1]
15
+ self.framelocation = pygame.Rect(x-5, y-5, self.image.get_width()+10, self.image.get_height()+10)
16
+ self.clicked = False
17
+
18
+ def run(self,screen):
19
+ screen.blit(self.image,self.location)
20
+ mouselocation = pygame.mouse.get_pos()
21
+ if self.location.collidepoint(mouselocation):
22
+ pygame.draw.rect(screen,RED,self.framelocation,5)
23
+ if pygame.mouse.get_pressed()[0] == 1 and not self.clicked:
24
+ self.clicked = True
25
+ return 1
26
+ else:
27
+ self.clicked = False
28
+ return 0
@@ -0,0 +1,296 @@
1
+ # 主程序(没错,运行它!)
2
+ __version__ = "1.0" # 版本说明(没什么用)
3
+
4
+ # 外部导入
5
+ cannotuseGUI = False
6
+ from random import shuffle
7
+ from time import sleep
8
+ import pygame
9
+ from traceback import print_exc
10
+ from os import chdir
11
+ # 模块导入
12
+ from roles import *
13
+ from data import *
14
+ try:
15
+ from sprites import Button
16
+ except:
17
+ print("警告!无法导入sprites.py,无法使用窗口模式!")
18
+ cannotuseGUI = True
19
+ # 以下是主程序
20
+ chdir(DIR)
21
+ health = [2,4,6]
22
+ buckshots = [ # 子弹(1代表实,0代表空)
23
+ [
24
+ [1,0,0],
25
+ [1,1,0,0]
26
+ ],
27
+ [
28
+ [1,0],
29
+ [1,1,0,0,0],
30
+ [1,1,1,0,0,0],
31
+ [1,1,1,1,0,0,0,0]
32
+ ],
33
+ [
34
+ [1,1,1,1,1,0,0,0],
35
+ [1,1,1,1,0,0,0,0],
36
+ [1,1,1,0],
37
+ [1,1,1,1,0,0,0,0]
38
+ ]
39
+ ]
40
+ try:
41
+ if cannotuseGUI:
42
+ mode = 2
43
+ else:
44
+ mode = int(input("请选择模式(壳程序按0(更为稳定),窗口按1(游戏体验更好)):"))
45
+ if mode:
46
+ FPS = int(input("请设置帧率(如果设的太高您的计算机可能运行不了,区间:1~200):"))
47
+ assert FPS >= 1 and FPS <= 200,"FPS out of range"
48
+ pygame.init()
49
+ # 以下是一些关于pygame的一些常量声明
50
+ # 以下是初始化
51
+ clock = pygame.time.Clock() # 初始化时钟
52
+ screen = pygame.display.set_mode((1400,850)) # 屏幕(窗口)初始化
53
+ pygame.display.set_caption("Buckshot Roulette") # 设置标题
54
+ background = pygame.image.load(BACKGROUND) # 加载背景图
55
+ gunimage = pygame.image.load(GUN) # 加载霰弹枪图片
56
+ charge = pygame.image.load(CHARGE) # 加载血量图片
57
+ blank = pygame.image.load(BLANK) # 加载空弹图片
58
+ liveround = pygame.image.load(LIVEROUND) # 加载实弹图片
59
+ dealershootself = pygame.image.load(SHOOTSELF) # 加载恶魔射击自己时的图片
60
+ dealershootplayer = pygame.image.load(SHOOTPLAYER) # 加载恶魔射击玩家时的图片
61
+ buckshotlocation = blank.get_rect() # 获取子弹显示位置
62
+ shootlocation = dealershootself.get_rect() # 获取恶魔射击时的位置
63
+ chargelocation = charge.get_rect() # 获取血量显示位置
64
+ gunimage.set_alpha(0) # 完全透明(此图是为了绘制边框)
65
+ gun = Button(675,300,gunimage,1) # 加载按钮(Button类的定义在sprites.py)
66
+ pygame.mixer.music.load(BGM) # 加载背景音乐(BGM)
67
+ liveplayermusic = pygame.mixer.Sound(LIVEPLAYER) # 玩家被击中时的音效
68
+ livedealermusic = pygame.mixer.Sound(LIVEDEALER) # 恶魔被击中时的音效
69
+ blankmusic = pygame.mixer.Sound(BLANKMUSIC) # 空弹发射时的音效
70
+ shootlocation.center = (700,300) # 设置恶魔射击时的位置
71
+ text = pygame.font.Font(FONT,75) # 设定字体
72
+ nametext = text.render("Enter name:",False,WHITE) # 用字体生成文字
73
+ playerlose = text.render("dealer win!",False,WHITE) # 用字体生成文字
74
+ loseorwinlocation = playerlose.get_rect()
75
+ loseorwinlocation.center = (700,425)
76
+ nametextlocation = nametext.get_rect()
77
+ nametextlocation.center = (700,100)
78
+ shootdealer = Button(700,75,text.render("DEALER",False,WHITE),1)
79
+ dealerturntext = text.render("dealer's turn",False,WHITE)
80
+ buttons = []
81
+ name = ""
82
+ for i in range(26):buttons.append(Button(50*(i+1),700,pygame.image.load(f"assets/{LETTERS[i]}.png")))
83
+ delete = Button(350,760,pygame.image.load(DELETE))
84
+ enter = Button(800,760,pygame.image.load(ENTER))
85
+ # 以下是一些控制变量
86
+ naming = True # 正在命名
87
+ playerturn = False # 玩家回合
88
+ dealerturn = False # 恶魔回合
89
+ choosing = False
90
+ drawingbuckshots = False
91
+ wasd = int(0)
92
+ turn = [0,0]
93
+ dealer = Dealer(2)
94
+ player = Player(2,name)
95
+ # 以下是游戏主循环
96
+ pygame.mixer.music.play(-1)
97
+ while True:
98
+ for event in pygame.event.get():
99
+ if event.type == pygame.QUIT:
100
+ raise SystemExit
101
+ screen.blit(background,(0,0))
102
+ if not player.gethealth():
103
+ screen.blit(playerlose,loseorwinlocation)
104
+ pygame.display.update()
105
+ sleep(3)
106
+ raise SystemExit
107
+ if not dealer.gethealth():
108
+ turn[1] = 0
109
+ turn[0] += 1
110
+ del buckshot
111
+ screen.blit(playerwin,loseorwinlocation)
112
+ pygame.display.update()
113
+ sleep(3)
114
+ if turn[0] == 3:
115
+ raise SystemExit
116
+ else:
117
+ dealer = Dealer(health[turn[0]])
118
+ player = Player(health[turn[0]],name)
119
+ try:buckshot[0]
120
+ except:
121
+ if turn[0] < 3:
122
+ buckshot = buckshots[turn[0]][turn[1]]
123
+ turn[1] += 1
124
+ if not naming:
125
+ playerturn = dealerturn = False
126
+ drawingbuckshots = True
127
+ if naming:
128
+ screen.blit(nametext,nametextlocation)
129
+ for i in buttons:
130
+ if i.run(screen):
131
+ name += (LETTERS[buttons.index(i)])
132
+ if delete.run(screen):
133
+ name = name[:-1]
134
+ if enter.run(screen):
135
+ naming = False
136
+ drawingbuckshots = True
137
+ shootyou = Button(700,700,text.render(name,False,WHITE),1)
138
+ playerwin = text.render(f"{name} win!",False,WHITE)
139
+ player.setname(name)
140
+ tmpnametext = text.render(name,False,WHITE)
141
+ tmpnametextlocation = tmpnametext.get_rect()
142
+ tmpnametextlocation.center = (700,400)
143
+ screen.blit(tmpnametext,tmpnametextlocation)
144
+ elif playerturn:
145
+ for i in range(player.gethealth()):
146
+ chargelocation.bottomleft = (0,850-50*i)
147
+ screen.blit(charge,chargelocation)
148
+ for i in range(dealer.gethealth()):
149
+ chargelocation.topleft = (0,0+50*i)
150
+ screen.blit(charge,chargelocation)
151
+ if gun.run(screen):
152
+ playerturn = False
153
+ choosing = True
154
+ elif dealerturn:
155
+ screen.blit(dealerturntext,nametextlocation)
156
+ for i in range(player.gethealth()):
157
+ chargelocation.bottomleft = (0,850-50*i)
158
+ screen.blit(charge,chargelocation)
159
+ for i in range(dealer.gethealth()):
160
+ chargelocation.topleft = (0,0+50*i)
161
+ screen.blit(charge,chargelocation)
162
+ if dealer.shoot() == 0:
163
+ print("dealer shooting himself!")
164
+ screen.blit(dealershootself,shootlocation)
165
+ if buckshot[0]:
166
+ livedealermusic.play()
167
+ dealer.hurt()
168
+ dealerturn = False
169
+ playerturn = True
170
+ else:
171
+ blankmusic.play()
172
+ else:
173
+ print(f"dealer shooting {name}")
174
+ screen.blit(dealershootplayer,shootlocation)
175
+ if buckshot[0]:
176
+ liveplayermusic.play()
177
+ player.hurt()
178
+ else:
179
+ blankmusic.play()
180
+ dealerturn = False
181
+ playerturn = True
182
+ del buckshot[0]
183
+ pygame.display.update()
184
+ sleep(2)
185
+ elif choosing:
186
+ for i in range(player.gethealth()):
187
+ chargelocation.bottomleft = (0,850-50*i)
188
+ screen.blit(charge,chargelocation)
189
+ for i in range(dealer.gethealth()):
190
+ chargelocation.topleft = (0,0+50*i)
191
+ screen.blit(charge,chargelocation)
192
+ if shootdealer.run(screen):
193
+ print(f"{name} shooting dealer!")
194
+ choosing = False
195
+ dealerturn = True
196
+ if buckshot[0] == 0:
197
+ blankmusic.play()
198
+ else:
199
+ livedealermusic.play()
200
+ dealer.hurt()
201
+ del buckshot[0]
202
+ sleep(2)
203
+ elif shootyou.run(screen):
204
+ print(f"{name} shooting himself!")
205
+ choosing = False
206
+ if buckshot[0] == 0:
207
+ blankmusic.play()
208
+ playerturn = True
209
+ else:
210
+ liveplayermusic.play()
211
+ player.hurt()
212
+ dealerturn = True
213
+ del buckshot[0]
214
+ sleep(2)
215
+ elif drawingbuckshots:
216
+ for en,b in enumerate(buckshot):
217
+ buckshotlocation.topleft = (400+80 * en,400)
218
+ if b:
219
+ screen.blit(liveround,buckshotlocation)
220
+ else:
221
+ screen.blit(blank,buckshotlocation)
222
+ pygame.display.update()
223
+ sleep(2)
224
+ drawingbuckshots = False
225
+ playerturn = True
226
+ shuffle(buckshot)
227
+ else:
228
+ raise TypeError("Nothing is Running!!!")
229
+ pygame.display.update()
230
+ clock.tick(FPS)
231
+ else:
232
+ name = input("你的名字:") # 输入名字
233
+ for j in range(3): # 三个回合
234
+ dealer = Dealer(health[j]) # 恶魔初始化
235
+ player = Player(health[j],name) # 玩家初始化
236
+ for i in range(len(buckshots[j])): # 每一小轮
237
+ buckshot = buckshots[j][i] # 初始化本轮子弹
238
+ buckshotcount = [0,0] #子弹计数
239
+ for k in buckshot: # 实弹
240
+ if k:buckshotcount[0]+=1
241
+ for k in buckshot: # 空弹
242
+ if k == 0:buckshotcount[1]+=1
243
+ next = 0 # 下一轮
244
+ shuffle(buckshot) # 打乱子弹顺序
245
+ print(f"{buckshotcount[0]}发实弹,{buckshotcount[1]}发空弹") # 打印子弹提示
246
+ for i in range(len(buckshot)): #
247
+ print(f"恶魔血量:{dealer.gethealth()} {name}的血量:{player.gethealth()}")
248
+ if next == 0:
249
+ if player.shoot():
250
+ if buckshot[i]:
251
+ print("砰!!!")
252
+ dealer.hurt() # 受伤
253
+ else:
254
+ print("咔......")
255
+ next = 1
256
+ else:
257
+ if buckshot[i]:
258
+ print("砰!!!")
259
+ player.hurt()
260
+ next = 1
261
+ else:
262
+ print("咔......")
263
+ else:
264
+ if dealer.shoot():
265
+ print(f"恶魔选择向{name}开枪!!!")
266
+ if buckshot[i]:
267
+ print("砰!!!")
268
+ player.hurt()
269
+ else:
270
+ print("咔......")
271
+ next = 0
272
+ else:
273
+ print("恶魔选择向自己开枪......")
274
+ if buckshot[i]:
275
+ print("砰!!!")
276
+ dealer.hurt()
277
+ next = 0
278
+ else:
279
+ print("咔......")
280
+ if dealer.gethealth() == 0 or player.gethealth() == 0:exit()
281
+ sleep(1.5)
282
+ del dealer
283
+ del player
284
+ except KeyboardInterrupt:
285
+ print("\n检测到^C")
286
+ exit()
287
+ except SystemExit:pass
288
+ except:
289
+ print("抱歉,我们检测到了一个错误,这可能不是您造成的,但您无法继续进行游戏了")
290
+ print("错误信息:")
291
+ print_exc()
292
+ print("游戏结束!")
293
+ print("感谢您的游玩!")
294
+ print("名称:Buckshot Roulette(恶魔轮盘赌)")
295
+ print("版本:1.0")
296
+ print("LevoLet Inc.")
roulette-game/data.py ADDED
@@ -0,0 +1,29 @@
1
+ # 此文件用于定义各种常量(必须)各种改动可在这里进行(比如路径)
2
+
3
+ ASSESTS = "assets/" # 修改为存放图片背景音乐等素材的目录
4
+ DIR = "/home/gqx/codelab/Buckshot_Roulette/" #修改为此程序存放的路径
5
+ RED = (255, 0, 0)
6
+ WHITE = (255,255,255)
7
+ BACKGROUND = f"{ASSESTS}bg.png"
8
+ BGM = f"{ASSESTS}bgmsc.ogg"
9
+ FONT = f"{ASSESTS}Simhei.ttf"
10
+ LETTERS = ("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z")
11
+ DELETE = f"{ASSESTS}DELETE.png"
12
+ ENTER = f"{ASSESTS}ENTER.png"
13
+ CHARGE = f"{ASSESTS}charge.png"
14
+ GUN = f"{ASSESTS}gun.png"
15
+ BLANKMUSIC = f"{ASSESTS}blank.wav"
16
+ LIVEDEALER = f"{ASSESTS}livedealer.wav"
17
+ LIVEPLAYER = f"{ASSESTS}liveplayer.wav"
18
+ BLANK = f"{ASSESTS}blank.png"
19
+ LIVEROUND = f"{ASSESTS}liveround.png"
20
+ SHOOTSELF = f"{ASSESTS}dealershootself.png"
21
+ SHOOTPLAYER= f"{ASSESTS}dealershootplayer.png"
22
+ SMOKE = f"{ASSESTS}smoke.png"
23
+ HANDCUFF = f"{ASSESTS}handcuff.png"
24
+ MAGNIFIER = f"{ASSESTS}magnifier.png"
25
+ KNIFE = f"{ASSESTS}knife.png"
26
+ PROPBOX = f"{ASSESTS}propbox.png"
27
+ BEER = f"{ASSESTS}beer.png"
28
+ PILL = f"{ASSESTS}pill.png"
29
+ NONEPROP = f"{ASSESTS}noneprop.png"
roulette-game/roles.py ADDED
@@ -0,0 +1,108 @@
1
+ # 此文件用于定义角色类(必须)
2
+ from random import random
3
+
4
+ class Dealer: # 恶魔
5
+ def __init__(self,health,prop = []) -> None: # 初始化
6
+ self.__tophealth = health
7
+ self.__health = health
8
+ self.__prop = prop
9
+
10
+ def gethealth(self) -> int:
11
+ return self.__health
12
+
13
+ def smoke(self) -> None:
14
+ if self.__health < self.__tophealth:
15
+ self.__health += 1
16
+
17
+ def setprop(self,prop) -> None: # 抽取道具
18
+ self.__prop.append(prop)
19
+
20
+ def getprop(self) -> list:
21
+ return self.__prop
22
+
23
+ def shoot(self) -> int: # 开枪
24
+ if random() >= 0.5:return 1 # 1:向玩家开枪,0:向自己开枪
25
+ else:return 0
26
+
27
+ def useprop(self) -> int: # 使用道具
28
+ '''
29
+ args:None
30
+ return:
31
+ (1:使用道具
32
+ (
33
+ 0:不用)
34
+ )
35
+ '''
36
+ while True:
37
+ rdm = random()
38
+ if rdm <= 0.19: # 啤酒
39
+ if 1 in self.__prop:
40
+ del self.__prop[self.__prop.index(1)]
41
+ return 1
42
+ elif rdm <= 0.38: # 烟
43
+ if 2 in self.__prop:
44
+ del self.__prop[self.__prop.index(2)]
45
+ return 2
46
+ elif rdm <= 0.57: # 手铐
47
+ if 3 in self.__prop:
48
+ del self.__prop[self.__prop.index(3)]
49
+ return 3
50
+ elif rdm <= 0.76: # 小刀
51
+ if 4 in self.__prop:
52
+ del self.__prop[self.__prop.index(4)]
53
+ return 4
54
+ elif rdm <= 0.95: # 放大镜
55
+ if 5 in self.__prop:
56
+ del self.__prop[self.__prop.index(5)]
57
+ return 5
58
+ else:return 0
59
+
60
+ def hurt(self):
61
+ self.__health -= 1
62
+ print("恶魔:啊!!!")
63
+ if self.__health == 0:
64
+ print("恶魔死了!!!")
65
+
66
+ class Player: # 人(玩家)
67
+ def __init__(self,health,name,prop = []) -> None: # 初始化(设置血量)
68
+ self.__tophealth = health
69
+ self.__health = health
70
+ self.__name = name
71
+ self.__prop = prop
72
+
73
+ def smoke(self) -> None:
74
+ if self.__health < self.__tophealth:
75
+ self.__health += 1
76
+
77
+ def shoot(self) -> int: # 打出
78
+ return int(input(f"{self.__name}想射:"))
79
+
80
+ def gethealth(self) -> int:
81
+ return self.__health
82
+
83
+ def getprop(self) -> list:
84
+ return self.__prop
85
+
86
+ def useprop(self): # 抽取道具
87
+ while True:
88
+ using = int(input(f"使用道具:"))
89
+ if using in self.__prop:
90
+ del self.__prop[self.__prop.index(using)]
91
+ return using
92
+ elif using == 0:
93
+ return 0
94
+ else:
95
+ print("没有此道具")
96
+
97
+ def setprop(self,prop) -> None: # 抽取道具
98
+ self.__prop.append(prop)
99
+
100
+ def hurt(self) -> int: # 受伤
101
+ self.__health -= 1
102
+ print(f"{self.__name}:啊!!!")
103
+ if self.__health == 0:
104
+ print(f"{self.__name}死了!!!")
105
+ raise SystemExit
106
+
107
+ def setname(self,name):
108
+ self.__name = name
@@ -0,0 +1,28 @@
1
+ # 此文件用于声明用于pygame的类(不必须,但使用窗口模式时需要)
2
+ import pygame
3
+ from data import *
4
+
5
+ class Button:
6
+ def __init__(self,x,y,image,mode = 0):
7
+ self.image = image
8
+ self.location = self.image.get_rect()
9
+ if mode == 0:
10
+ self.location.topleft = (x,y)
11
+ else:
12
+ self.location.center = (x,y)
13
+ x = self.location.topleft[0]
14
+ y = self.location.topleft[1]
15
+ self.framelocation = pygame.Rect(x-5, y-5, self.image.get_width()+10, self.image.get_height()+10)
16
+ self.clicked = False
17
+
18
+ def run(self,screen):
19
+ screen.blit(self.image,self.location)
20
+ mouselocation = pygame.mouse.get_pos()
21
+ if self.location.collidepoint(mouselocation):
22
+ pygame.draw.rect(screen,RED,self.framelocation,5)
23
+ if pygame.mouse.get_pressed()[0] == 1 and not self.clicked:
24
+ self.clicked = True
25
+ return 1
26
+ else:
27
+ self.clicked = False
28
+ return 0
@@ -0,0 +1,16 @@
1
+ Copyright (c) 2018 The Python Packaging Authority
2
+ Permission is hereby granted, free of charge, to any person obtaining a copy
3
+ of this software and associated documentation files (the "Software"), to deal
4
+ in the Software without restriction, including without limitation the rights
5
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6
+ copies of the Software, and to permit persons to whom the Software is
7
+ furnished to do so, subject to the following conditions:
8
+ The above copyright notice and this permission notice shall be included in all
9
+ copies or substantial portions of the Software.
10
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
11
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
13
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
15
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16
+ SOFTWARE.
@@ -0,0 +1,49 @@
1
+ Metadata-Version: 2.1
2
+ Name: roulette-game
3
+ Version: 1.0
4
+ Summary: 模仿steam游戏“恶魔轮盘”,目前没有提供开发接口(只能单纯玩)
5
+ Home-page: https://github.com/BinaryGuo/Buckshot_Roulette
6
+ Author: GQX
7
+ Author-email: kill114514251@outlook.com
8
+ Classifier: Intended Audience :: End Users/Desktop
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Topic :: Software Development :: Libraries :: pygame
11
+ Classifier: Natural Language :: Chinese (Simplified)
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: POSIX :: Linux
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Requires-Python: >=3.8
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: pygame >=2.0.1
24
+
25
+ # Buckshot Roulette 恶魔轮盘赌
26
+ ## 版本
27
+ - 1.0
28
+ ## 开发环境
29
+ - linux ubuntu 22.04(主要开发环境,负责运行代码等等)
30
+ - apple mac 14.0(主要是使用mac上自带的“预览”来测量图片并使用PIL.Image进行切割、缩放等操作)
31
+ 其实ubuntu在网上也有测像素的工具,但我懒得找了......
32
+ 正好家里有台mac,就选择用mac完成。
33
+ ## 改动说明
34
+ ## 0.1(上个版本)
35
+ - 使用类初步实现了游戏
36
+ - 可玩性不高
37
+ ### 1.0
38
+ - 增加道具
39
+ - 增加两个回合
40
+ - 增加图形界面(pygame)
41
+ ## 程序说明
42
+ - 你可以看到在每个.py文件开头简短的说明
43
+ ### asset
44
+ - 你可能注意到gun.png是一张空白图片,因为它只用于绘制边框(届时ALPHA值将设为255(完全透明))
45
+ ## 道歉
46
+ - 不好意思,此版本没有提供开发接口,README也写的不多,请见凉!!!
47
+ # Levolet Inc.
48
+ ### CC-BY-SA 3.0 protocol
49
+ ### Python3.10.12
@@ -0,0 +1,13 @@
1
+ Buckshot-Roulette/__init__.py,sha256=GEjta067orPv2hzwj2TKVbhEdEvQH9_p3EA1IKlJLxY,12703
2
+ Buckshot-Roulette/data.py,sha256=fno7guy_DqFVfYu6TR5tXno0KxRdAHA4DXFy21OI-rk,1241
3
+ Buckshot-Roulette/roles.py,sha256=Qrx2RYuE5iVi5rF2imd89n1ZaRHLzGB1-7rPv1umD20,3199
4
+ Buckshot-Roulette/sprites.py,sha256=a4TMCswAbRqrpULxf32h9vdLTUHnlnUtT879bdmH0YE,1042
5
+ roulette-game/__init__.py,sha256=GEjta067orPv2hzwj2TKVbhEdEvQH9_p3EA1IKlJLxY,12703
6
+ roulette-game/data.py,sha256=fno7guy_DqFVfYu6TR5tXno0KxRdAHA4DXFy21OI-rk,1241
7
+ roulette-game/roles.py,sha256=Qrx2RYuE5iVi5rF2imd89n1ZaRHLzGB1-7rPv1umD20,3199
8
+ roulette-game/sprites.py,sha256=a4TMCswAbRqrpULxf32h9vdLTUHnlnUtT879bdmH0YE,1042
9
+ roulette_game-1.0.dist-info/LICENSE,sha256=wuJc6SkaE_G-4alxueHO8BhgWRmEJAlJaPkoFuI9kqk,1070
10
+ roulette_game-1.0.dist-info/METADATA,sha256=glc6x4RF_VnOn21ZCDBAt8_nB--AFprzbklLv0adyRE,1942
11
+ roulette_game-1.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
12
+ roulette_game-1.0.dist-info/top_level.txt,sha256=LOX-0jfUuXp4D42mfguerOiMi0OkZ99kLtX1LPCBHFY,14
13
+ roulette_game-1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.43.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ roulette-game