资讯专栏INFORMATION COLUMN

python学习教程,python版大富翁游戏开发源代码分享

davidac / 3955人阅读

摘要:物网王璞劼理工大富翁基于的一个大富翁游戏游戏地图为自己使用各种网络素材制作各种按钮和选项,小图标等也是使用制作。玩家在大富翁的主要操作是投掷骰子,由随机函数进行判定然后进行移动,进行位置判断,然后开始进行相关的判定。

本文实例为大家分享了python版大富翁游戏的具体代码,供大家参考,具体内容如下

</>复制代码

  1. # -*- coding: utf-8 -*-
  2. """
  3. 在学习过程中有什么不懂得可以加我的python学习交流扣扣qun,934109170,群里有不错的学习教程、开发工具与电子书籍。
  4. 与你分享python企业当下人才需求及怎么从零基础学习好python,和学习什么内容。
  5. """
  6. # code by: 物网141 王璞劼Khalil
  7. # name: 理工大富翁beta2.0
  8. # describe: 基于python的一个2D大富翁游戏
  9. """
  10. 1.游戏地图为自己使用各种网络素材制作;
  11. 各种按钮和选项,小图标等也是使用PS制作。
  12. 2.声音效果主要为背景音乐和几种游戏中音效;
  13. 3.游戏设定了两个类:玩家和建筑
  14. 玩家的参数和方法都在代码中给出;
  15. 具体有:移动方法、位置判断方法、
  16. 购买房屋方法、添加小房子方法、
  17. 事件判断方法。
  18. 4.玩家在大富翁的主要操作是投掷骰子,由随机函数
  19. 进行判定然后进行移动,进行位置判断,然后开始
  20. 进行相关的判定。
  21. 5.游戏中的按键有:是、否、和结束回合;
  22. 每个按键由没按下与按下两种状态的图片组成,
  23. 这个设计花费了一定时间。
  24. 还有 开始游戏 和 扔骰子 的两个明暗按钮,
  25. 由pygame优化后的一个函数实现。
  26. 6.玩家的位置与电脑重叠时会将双方的位置进行一定
  27. 偏移,防止进行覆盖,分不清自己的位置。
  28. 7.游戏基础功能有移动,购买房子,在已经购买的房子下
  29. 搭建新的小房子增加过路费,被收费,判断胜负的基础
  30. 功能,此外还加入了幸运事件:
  31. 财神 - 免收费一次
  32. 衰神 - 双倍被收费一次
  33. 破坏神 - 直接破坏一个建筑 无论敌我
  34. 土地神 - 强占对面建筑
  35. 这四项功能在位置处于左上角和右下角的时候会被触发,
  36. 添加了很多游戏乐趣哦~~~ ^_^
  37. 8.游戏基于python的一个模块pygame实现,给我提供了很
  38. 多快乐的时光,谢谢老师的阅览与郭宁同学的协助答辩
  39. :)
  40. """
  41. #####################准备工作##################
  42. # 初始化各种模块
  43. import pygame
  44. import random
  45. import sys
  46. # 定义类
  47. class Player():
  48. def __init__(self, image ,name , isPlayer):
  49. self.name = name
  50. self.money = 10000
  51. self.isGoingToMove = False
  52. self.movable = True
  53. self.image = image
  54. self.position = 0
  55. self.temp_position = False
  56. self.dice_value = 0
  57. self.locatedBuilding = 0
  58. self.showText = []
  59. self.isPlayer = isPlayer
  60. self.ownedBuildings = []
  61. self.isShowText = False
  62. self.soundPlayList = 0
  63. self.caishen = 0
  64. self.shuaishen = 0
  65. self.tudishen = 0
  66. self.pohuaishen = 0
  67. def judgePosition(self,buildings): # 位置判断 返回值是所在位置的建筑
  68. for each in buildings:
  69. for every in each.location:
  70. if self.position == every:
  71. return each
  72. # 当使用元组时 当元组中只有一个元素时 发现该元素不可迭代
  73. # 出现错误 换成列表后解决
  74. """
  75. try:
  76. for every in each.location:
  77. if self.position == every:
  78. print(each.name)
  79. except:
  80. if self.position == every:
  81. print(each.name)
  82. """
  83. def buyaBuilding(self,isPressYes): # 购买方法
  84. if isPressYes and self.locatedBuilding.owner != self.name:
  85. self.locatedBuilding.owner = self.name
  86. self.locatedBuilding.wasBought = True
  87. self.ownedBuildings.append(self.locatedBuilding)
  88. self.money -= self.locatedBuilding.price
  89. self.showText = [self.name + "购买了" + self.locatedBuilding.name + "!"]
  90. self.soundPlayList = 1
  91. return True
  92. else:
  93. return False
  94. def addaHouse(self,isPressYes): # 在建筑物上添加一个房子
  95. try:
  96. if isPressYes and self.locatedBuilding.owner == self.name:
  97. self.locatedBuilding.builtRoom += 1
  98. self.money -= self.locatedBuilding.payment
  99. self.showText = [self.name + "在" + self.locatedBuilding.name + "上!","盖了一座房子!",
  100. "有%d" % self.locatedBuilding.builtRoom + "个房子了!",
  101. "它的过路费是%d" % (self.locatedBuilding.payment *
  102. (self.locatedBuilding.builtRoom + 1)) ]
  103. self.soundPlayList = 2
  104. return True
  105. else:
  106. return False
  107. except:
  108. pass
  109. def move(self,buildings,allplayers): # 移动方法 返回值是所在的建筑位置
  110. self.dice_value = random.randint(1,6)
  111. self.position += self.dice_value
  112. if self.position >= 16:
  113. self.position -= 16
  114. self.locatedBuilding = self.judgePosition(buildings)
  115. self.isShowText = True
  116. return self.eventInPosition(allplayers)
  117. def eventInPosition(self,allplayers): # 判断在建筑位置应该发生的事件
  118. building = self.locatedBuilding
  119. if building.name != "空地":
  120. if self.locatedBuilding.wasBought == False: # 未购买的时候显示建筑的数据!
  121. if self.isPlayer == True:
  122. textLine0 = self.name +"扔出了" + "%d"% self.dice_value + "点!"
  123. textLine1 = self.name +"来到了" + building.name + "!"
  124. textLine2 = "购买价格:%d" % building.price
  125. textLine3 = "过路收费:%d" % building.payment
  126. textLine4 = "是否购买?"
  127. self.showText = [textLine0,textLine1,textLine2,textLine3,textLine4]
  128. return True
  129. else :
  130. self.addaHouse(not self.buyaBuilding(True))
  131. # ----- 动画 -------
  132. # ----- 是否购买 ------
  133. elif building.owner == self.name: # 路过自己的房子开始加盖建筑!
  134. if self.pohuaishen == 1:
  135. textLine0 = self.name + "破坏神附体!"
  136. textLine1 = "摧毁了自己的房子!"
  137. building.owner = "no"
  138. building.wasBought = False
  139. self.showText = [textLine0,textLine1]
  140. self.pohuaishen = 0
  141. else:
  142. if self.isPlayer == True:
  143. textLine0 = self.name + "扔出了" + "%d"% self.dice_value + "点!"
  144. textLine1 = "来到了ta的"+ self.locatedBuilding.name +"!"
  145. textLine2 = "可以加盖小房子!"
  146. textLine3 = "加盖收费:%d" % building.payment
  147. textLine4 = "是否加盖?"
  148. self.showText = [textLine0,textLine1,textLine2,textLine3,textLine4]
  149. return True
  150. # ----- 动画-------
  151. else:
  152. self.addaHouse(True)
  153. else:
  154. for each in allplayers: # 被收费!
  155. if self.locatedBuilding.owner == each.name and each.name != self.name:
  156. if self.caishen == 1:
  157. textLine0 = self.name + "财神附体!"
  158. textLine1 = "免除过路费%d!" % (building.payment * (building.builtRoom + 1))
  159. self.showText = [textLine0,textLine1]
  160. self.caishen = 0
  161. else:
  162. if self.tudishen == 1:
  163. textLine0 = self.name + "土地神附体!"
  164. textLine1 = "强占土地!"
  165. textLine2 = building.name + "现在属于"+ self.name
  166. self.locatedBuilding.owner = self.name
  167. self.showText = [textLine0,textLine1,textLine2]
  168. self.tudishen = 0
  169. else:
  170. if self.pohuaishen == 1:
  171. textLine0 = self.name + "破坏神附体!"
  172. textLine1 = "摧毁了对手的房子!"
  173. building.owner = "no"
  174. building.wasBought = False
  175. self.showText = [textLine0,textLine1]
  176. self.pohuaishen = 0
  177. else:
  178. textLine0 = self.name + "扔出了" + "%d"% self.dice_value + "点!"
  179. textLine1 = self.name+ "来到了"+ each.name+"的:"
  180. textLine2 = building.name + ",被收费!"
  181. if self.shuaishen == 1:
  182. textLine3 = "过路收费:%d*2!" % (building.payment * (building.builtRoom + 1)*2)
  183. self.shuaishen = 0
  184. else:
  185. textLine3 = "过路收费:%d" % (building.payment * (building.builtRoom + 1))
  186. textLine4 = "哦!"+ self.name +"好倒霉!"
  187. self.showText = [textLine0,textLine1,textLine2,textLine3,textLine4]
  188. # 收费!
  189. self.money -= building.payment * (building.builtRoom + 1)
  190. each.money += building.payment * (building.builtRoom + 1)
  191. self.soundPlayList = 3
  192. # ----- 动画-------
  193. else:
  194. # 发现不能处理在空地上的情况 于是使用 try & except 来解决!然后加入了幸运事件功能!
  195. # 后来发现 try except 弊端太大 找不到错误的根源 换为if else嵌套。。
  196. whichone = self.dice_value % 4
  197. if whichone == 0:
  198. self.caishen = 1
  199. textLine2 = "遇到了财神!"
  200. textLine3 = "免一次过路费!"
  201. if whichone == 1:
  202. self.shuaishen = 1
  203. textLine2 = "遇到了衰神!"
  204. textLine3 = "过路费加倍一次!"
  205. if whichone == 2:
  206. self.tudishen = 1
  207. textLine2 = "遇到了土地神!"
  208. textLine3 = "强占一次房子!"
  209. if whichone == 3:
  210. self.pohuaishen = 1
  211. textLine3 = "摧毁路过的房子!"
  212. textLine2 = "遇到了破坏神!"
  213. textLine0 = self.name +"扔出了" +"%d"% self.dice_value + "点!"
  214. textLine1 = "来到了运气地点!"
  215. self.showText = [textLine0,textLine1,textLine2,textLine3]
  216. class Building(): # 好像所有功能都在Player类里实现了=_=
  217. def __init__(self,name,price,payment,location):
  218. self.name = name
  219. self.price = price
  220. self.payment = payment
  221. self.location = location
  222. self.wasBought = False # 是否被购买
  223. self.builtRoom = 0 # 小房子建造的数目
  224. self.owner = "no"
  225. # 带透明度的绘图方法 by turtle 2333
  226. def blit_alpha(target,source,location,opacity):
  227. x = location[0]
  228. y = location[1]
  229. temp = pygame.Surface((source.get_width(),source.get_height())).convert()
  230. temp.blit(target , (-x , -y))
  231. temp.blit(source,(0,0))
  232. temp.set_alpha(opacity)
  233. target.blit(temp,location)
  234. ########################主函数#########################
  235. def main():
  236. pygame.init()
  237. clock = pygame.time.Clock()
  238. # 初始化屏幕
  239. size = (1270,768)
  240. screen = pygame.display.set_mode(size)
  241. pygame.display.set_caption("理工大大富翁 - made by 王璞劼")
  242. # 读取字体以及有关数据
  243. textColorInMessageBox = (141,146,152)
  244. white = (255,255,255)
  245. black = (0,0,0)
  246. red = (255,0,0)
  247. font = pygame.font.Font("resourcefontmyfont.ttf",30)
  248. # 读取资源
  249. backgroud = pygame.image.load("resourcepicGameMap.png")
  250. chess = pygame.image.load("resourcepicchess.png")
  251. chess_com = pygame.image.load("resourcepicchess1.png")
  252. bigdice_image = pygame.image.load("resourcepicdice.png").convert_alpha()
  253. dice_1 = pygame.image.load("resourcepicdice_1.png")
  254. dice_2 = pygame.image.load("resourcepicdice_2.png")
  255. dice_3 = pygame.image.load("resourcepicdice_3.png")
  256. dice_4 = pygame.image.load("resourcepicdice_4.png")
  257. dice_5 = pygame.image.load("resourcepicdice_5.png")
  258. dice_6 = pygame.image.load("resourcepicdice_6.png")
  259. dices = [dice_1,dice_2,dice_3,dice_4,dice_5,dice_6]
  260. yes = pygame.image.load("resourcepicyes.png")
  261. yes2 = pygame.image.load("resourcepicyes2.png")
  262. no = pygame.image.load("resourcepic
  263. o.png")
  264. no2 = pygame.image.load("resourcepic
  265. o2.png")
  266. GameStart = pygame.image.load("resourcepicGameStart.png")
  267. StartGameButton = pygame.image.load("resourcepicStartGameButton.png").convert_alpha()
  268. turnover = pygame.image.load("resourcepic
  269. urnover.png")
  270. turnover2 = pygame.image.load("resourcepic
  271. urnover2.png")
  272. shuaishen = pygame.image.load("resourcepicshuaishen.png").convert_alpha()
  273. tudishen = pygame.image.load("resourcepic
  274. udishen.png").convert_alpha()
  275. caishen = pygame.image.load("resourcepiccaishen.png").convert_alpha()
  276. pohuaishen = pygame.image.load("resourcepicpohuaishen.png").convert_alpha()
  277. rollDiceSound = pygame.mixer.Sound("resourcesound
  278. olldicesound.wav")
  279. bgm = pygame.mixer.music.load("resourcesoundgm.ogg")
  280. throwcoin = pygame.mixer.Sound("resourcesound
  281. hrowcoin.wav")
  282. moneysound = pygame.mixer.Sound("resourcesoundmoneysound.wav")
  283. aiyo = pygame.mixer.Sound("resourcesoundaiyo.wav")
  284. didong = pygame.mixer.Sound("resourcesounddidong.wav")
  285. # PlayList 在对象中设置应该播放的声音
  286. playList = [moneysound ,throwcoin ,aiyo]
  287. # 各种Surface的rect
  288. bigdice_rect = bigdice_image.get_rect()
  289. bigdice_rect.left , bigdice_rect.top = 50 , 600
  290. yes_rect = yes.get_rect()
  291. yes_rect.left , yes_rect.top = 500,438
  292. no_rect = no.get_rect()
  293. no_rect.left , no_rect.top = 630,438
  294. button_rect = StartGameButton.get_rect()
  295. button_rect.left , button_rect.top = 1003,30
  296. turnover_rect = turnover.get_rect()
  297. turnover_rect.left , turnover_rect.top = 1035,613
  298. # 实例化对象
  299. players = []
  300. computers = []
  301. allplayers = []
  302. player_1 = Player(chess , "玩家" , True )
  303. player_com1 = Player(chess_com , "电脑" , False )
  304. players.append(player_1)
  305. computers.append(player_com1)
  306. allplayers.append(player_1)
  307. allplayers.append(player_com1)
  308. presentPlayer = player_com1
  309. # 初始化建筑物数据
  310. gate = Building("大门",1000,200,[1,2])
  311. fountain = Building("喷泉",2000,400,[3,4])
  312. path = Building("小道",800,160,[5])
  313. library = Building("图书馆",2000,400,[6,7])
  314. kongdi1 = Building("空地",0,0,[8])
  315. classroomTen = Building("教十",1200,240,[9,10])
  316. classroomNine = Building("教九",1200,240,[11,12])
  317. resOne = Building("三餐厅",800,160,[13])
  318. resTwo = Building("二餐厅",800,160,[14])
  319. resThree = Building("一餐厅",800,160,[15])
  320. kongdi2 = Building("空地",0,0,[0])
  321. buildings = [gate,fountain,path,library,classroomNine,
  322. classroomTen,resOne,resThree,resTwo,kongdi1,kongdi2]
  323. # 坐标数据 同时处理坐标数据 使之合适
  324. MapXYvalue = [(435.5,231.5),(509.5,231.5),(588.5,231.5),(675.5,231.5),(758.5,231.5),
  325. (758.5,317.0),(758.5,405.5),(758.5,484.5),(758.5,558.5),(679.5,558.5),
  326. (601.5,558.5),(518.5,556.5),(435.5,556.5),(435.5,479.5),(435.5,399.0),
  327. (435.5,315.5)
  328. ]
  329. MapChessPosition_Player = []
  330. MapChessPosition_Com = []
  331. MapChessPosition_Original = []
  332. MapChessPosition_Payment = []
  333. MapMessageBoxPosition = (474.1 , 276.9)
  334. YesNoMessageBoxPosition = [(500,438) , (630,438)]
  335. StartGameButtonPosition = (1003,30)
  336. TurnOvwrButtonPosition = (1035,613)
  337. # 调整位置
  338. for i in range(0,16):
  339. MapChessPosition_Original.append((MapXYvalue[i][0]-50,MapXYvalue[i][1]-80))
  340. MapChessPosition_Player.append((MapXYvalue[i][0]-70,MapXYvalue[i][1]-60))
  341. MapChessPosition_Com.append((MapXYvalue[i][0]-30,MapXYvalue[i][1]-100))
  342. MapChessPosition_Payment.append((MapXYvalue[i][0]-30,MapXYvalue[i][1]-15))
  343. # 循环时所用的一些变量
  344. running = True
  345. image_alpha = 255
  346. button_alpha = 255
  347. half_alpha = 30
  348. showdice = True
  349. showYes2 = False
  350. showNo2 = False
  351. showYes_No = False
  352. pressYes = False
  353. whetherYes_NoJudge = False
  354. gameStarted = False
  355. showButton2 = False
  356. # 播放背景音乐
  357. pygame.mixer.music.play(100)
  358. #################进入游戏循环!########################
  359. # 循环开始!
  360. while running:
  361. if not gameStarted:
  362. for event in pygame.event.get():
  363. if event.type == pygame.QUIT:
  364. sys.exit()
  365. # 明暗触发 鼠标位置判断
  366. if event.type == pygame.MOUSEMOTION:
  367. if button_rect.collidepoint(event.pos):
  368. button_alpha = 255
  369. else:
  370. button_alpha = 120
  371. if event.type == pygame.MOUSEBUTTONDOWN:
  372. if button_rect.collidepoint(event.pos): # 按下按钮
  373. didong.play()
  374. gameStarted = True
  375. screen.blit(GameStart , (0,0))
  376. blit_alpha(screen, StartGameButton, StartGameButtonPosition, button_alpha)
  377. if gameStarted:
  378. for event in pygame.event.get():
  379. if event.type == pygame.QUIT:
  380. sys.exit()
  381. # 明暗触发 鼠标位置判断
  382. if event.type == pygame.MOUSEMOTION:
  383. if bigdice_rect.collidepoint(event.pos):
  384. image_alpha = 255
  385. else:
  386. image_alpha = 190
  387. if event.type == pygame.MOUSEBUTTONDOWN:
  388. if bigdice_rect.collidepoint(event.pos): # 按骰子
  389. if presentPlayer != player_1:
  390. rollDiceSound.play(1, 2000)
  391. pygame.time.delay(2000)
  392. showYes_No = player_1.move(buildings,allplayers)
  393. whetherYes_NoJudge = showYes_No
  394. presentPlayer = player_1
  395. else:
  396. presentPlayer.showText = ["还没到你的回合!"]
  397. if turnover_rect.collidepoint(event.pos): # 按回合结束
  398. showButton2 = True
  399. if presentPlayer != player_com1:
  400. showYes_No = player_com1.move(buildings,allplayers)
  401. presentPlayer = player_com1
  402. else:
  403. presentPlayer.showText = ["还没到你的回合!"]
  404. else:
  405. showButton2 = False
  406. # 不显示Yes_No的时候不能点击它们!
  407. if whetherYes_NoJudge == True:
  408. if yes_rect.collidepoint(event.pos): # 按是否
  409. showYes2 = True
  410. if no_rect.collidepoint(event.pos): # 按是否
  411. showNo2 = True
  412. if event.type == pygame.MOUSEBUTTONUP:
  413. if turnover_rect.collidepoint(event.pos): # 按回合结束
  414. showButton2 = False
  415. if yes_rect.collidepoint(event.pos): # 按是否
  416. showYes2 = False
  417. showYes_No = False
  418. # 只有在可以判定的时候才能算按下了是 同时将判断条件置为空
  419. if whetherYes_NoJudge == True:
  420. pressYes = True
  421. whetherYes_NoJudge = False
  422. if no_rect.collidepoint(event.pos): # 按是否
  423. showNo2 = False
  424. pressYes = False
  425. showYes_No = False
  426. whetherYes_NoJudge = False
  427. # 测试事件选项
  428. if event.type == pygame.KEYDOWN:
  429. if event.key == pygame.K_w:
  430. showYes_No = player_1.move(buildings,allplayers)
  431. whetherYes_NoJudge = showYes_No
  432. presentPlayer = player_1
  433. if event.key == pygame.K_q:
  434. showYes_No = player_com1.move(buildings,allplayers)
  435. presentPlayer = player_com1
  436. """for each in allplayers:
  437. if each.isGoingToMove == True and each.movable == True :
  438. showYes_No = each.move(buildings,allplayers)
  439. each.movable = False
  440. each.isGoingToMove = False"""
  441. """
  442. allisready = True
  443. for each in allplayers:
  444. if each.movable == True:
  445. allisready = False
  446. if allisready:
  447. for each in allplayers:
  448. each.movable = True
  449. """
  450. # 购买房屋!!!!!!!!
  451. if presentPlayer.buyaBuilding(pressYes) == True:
  452. pressYes = False
  453. if presentPlayer.addaHouse(pressYes) == True:
  454. pressYes = False
  455. #########################################################################
  456. screen.blit( backgroud , (0,0) )
  457. blit_alpha(screen, bigdice_image, (50, 600), image_alpha)
  458. textPosition = [MapMessageBoxPosition[0],MapMessageBoxPosition[1]]
  459. # 打印信息
  460. for each in presentPlayer.showText:
  461. text = font.render(each, True, white, textColorInMessageBox)
  462. screen.blit(text,textPosition)
  463. textPosition[1] += 30
  464. # 播放行动声音
  465. if presentPlayer.soundPlayList != 0:
  466. playList[presentPlayer.soundPlayList - 1].play()
  467. presentPlayer.soundPlayList = 0
  468. # 在位置上显示过路费
  469. for i in range(1,8):
  470. for each in buildings:
  471. for every in each.location:
  472. if i == every:
  473. if each.owner == presentPlayer.name:
  474. text = font.render("%d" % (each.payment * (each.builtRoom + 1))
  475. , True, red)
  476. elif each.owner == "no":
  477. text = font.render("%d" % (each.payment * (each.builtRoom + 1))
  478. , True, white)
  479. elif each.owner != presentPlayer.name and each.owner != "no":
  480. text = font.render("%d" % (each.payment * (each.builtRoom + 1))
  481. , True, black)
  482. screen.blit(text,MapChessPosition_Payment[i])
  483. for i in range(9,16):
  484. for each in buildings:
  485. for every in each.location:
  486. if i == every:
  487. if each.owner == presentPlayer.name:
  488. text = font.render("%d" % (each.payment * (each.builtRoom + 1))
  489. , True, red)
  490. elif each.owner == "no":
  491. text = font.render("%d" % (each.payment * (each.builtRoom + 1))
  492. , True, white)
  493. elif each.owner != presentPlayer.name and each.owner != "no":
  494. text = font.render("%d" % (each.payment * (each.builtRoom + 1))
  495. , True, black)
  496. screen.blit(text,MapChessPosition_Payment[i])
  497. # 打印金钱数和幸运状态
  498. money_1 = font.render(player_1.name +"金钱:%d" % player_1.money, True, black, white)
  499. screen.blit(money_1,(0,0))
  500. if player_1.pohuaishen == True:
  501. screen.blit(pohuaishen,(0,30))
  502. else:
  503. blit_alpha(screen, pohuaishen, (0, 30), half_alpha)
  504. if player_1.caishen == True:
  505. screen.blit(caishen,(55,30))
  506. else:
  507. blit_alpha(screen, caishen, (55, 30), half_alpha)
  508. if player_1.shuaishen == True:
  509. screen.blit(shuaishen,(110,30))
  510. else:
  511. blit_alpha(screen, shuaishen, (110, 30), half_alpha)
  512. if player_1.tudishen == True:
  513. screen.blit(tudishen,(165,30))
  514. else:
  515. blit_alpha(screen, tudishen, (165, 30), half_alpha)
  516. money_2 = font.render(player_com1.name +"金钱:%d" % player_com1.money, True, black, white)
  517. screen.blit(money_2,(1000,0))
  518. if player_com1.pohuaishen == True:
  519. screen.blit(pohuaishen,(1000,30))
  520. else:
  521. blit_alpha(screen, pohuaishen, (1000, 30), half_alpha)
  522. if player_com1.caishen == True:
  523. screen.blit(caishen,(1055,30))
  524. else:
  525. blit_alpha(screen, caishen, (1055, 30), half_alpha)
  526. if player_com1.shuaishen == True:
  527. screen.blit(shuaishen,(1110,30))
  528. else:
  529. blit_alpha(screen, shuaishen, (1110, 30), half_alpha)
  530. if player_com1.tudishen == True:
  531. screen.blit(tudishen,(1165,30))
  532. else:
  533. blit_alpha(screen, tudishen, (1165, 30), half_alpha)
  534. # 放置扔出来的骰子
  535. if player_1.dice_value != 0 and showdice:
  536. screen.blit(dices[player_1.dice_value - 1],(70,450))
  537. # 放置回合结束按钮
  538. if showButton2:
  539. screen.blit(turnover2,TurnOvwrButtonPosition)
  540. else:
  541. screen.blit(turnover,TurnOvwrButtonPosition)
  542. # 放置是否按钮
  543. if showYes_No == True:
  544. screen.blit(yes , YesNoMessageBoxPosition[0])
  545. screen.blit(no , YesNoMessageBoxPosition[1])
  546. if showYes2 == True:
  547. screen.blit(yes2 , YesNoMessageBoxPosition[0])
  548. if showNo2 == True:
  549. screen.blit(no2 , YesNoMessageBoxPosition[1])
  550. # 放置玩家与电脑的位置 如果重合则挪位
  551. for each in players:
  552. for every in computers:
  553. if each.position == every.position:
  554. screen.blit(each.image,MapChessPosition_Player[each.position])
  555. screen.blit(every.image,MapChessPosition_Com[every.position])
  556. each.temp_position = True
  557. every.temp_position = True
  558. for each in players:
  559. if each.temp_position == False:
  560. screen.blit(each.image,MapChessPosition_Original[each.position])
  561. each.temp_position = True
  562. each.temp_position = not each.temp_position
  563. for every in computers:
  564. if every.temp_position == False:
  565. screen.blit(every.image,MapChessPosition_Original[every.position])
  566. every.temp_position = True
  567. every.temp_position = not every.temp_position
  568. # 输赢判断
  569. for each in allplayers:
  570. if each.money <= 0:
  571. font = pygame.font.Font("resourcefontmyfont.ttf",200)
  572. loseText = font.render(each.name +"输了!", True, red)
  573. screen.fill(black)
  574. screen.blit(loseText,(100,100))
  575. font = pygame.font.Font("resourcefontmyfont.ttf",30)
  576. pygame.time.delay(3000)
  577. # 画面运行
  578. pygame.display.flip()
  579. clock.tick(60) # 刷新率
  580. # 双击打开运行
  581. if __name__ == "__main__":
  582. main()

因为目前python非常火,应用非常的广泛,是目前最火的行业之一,竞争很大,工资很高,未来发展也极好。加油加油!

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/44147.html

相关文章

  • 游戏开发上手体验 - Cocos Creator

    摘要:但开发的游戏是无法通过网页发给别人在线玩的,更不能做成微信小游戏。它使用作为开发语言,开发出的游戏可以直接生成微信小游戏网页安卓等平台上的版本。 微信群里最大的骚扰源有两种: 一是转发#吱口令#~!@#¥%……&*,长按复制此消息领红包之类的 另一种就是各种小程序和小游戏的分享 前天有同学无意间把一个小游戏分享到了答疑群中,我看了一下,其实游戏的代码逻辑并不复杂(简化版的跳一跳,套上个...

    zhiwei 评论0 收藏0
  • 编程书单:十本Python编程语言的入门书籍

    摘要:本文与大家分享一些编程语言的入门书籍,其中不乏经典。全书贯穿的主体是如何思考设计开发的方法,而具体的编程语言,只是提供一个具体场景方便介绍的媒介。入门入门容易理解而且读起来幽默风趣,对于编程初学者和语言新手而言是理想的书籍。 本文与大家分享一些Python编程语言的入门书籍,其中不乏经典。我在这里分享的,大部分是这些书的英文版,如果有中文版的我也加上了。有关书籍的介绍,大部分截取自是官...

    desdik 评论0 收藏0
  • SegmentFault 技术周刊 Vol.40 - 2018,来学习一门新的编程语言吧!

    摘要:入门,第一个这是一门很新的语言,年前后正式公布,算起来是比较年轻的编程语言了,更重要的是它是面向程序员的函数式编程语言,它的代码运行在之上。它通过编辑类工具,带来了先进的编辑体验,增强了语言服务。 showImg(https://segmentfault.com/img/bV1xdq?w=900&h=385); 新的一年不知不觉已经到来了,总结过去的 2017,相信小伙们一定有很多收获...

    caspar 评论0 收藏0
  • SegmentFault 技术周刊 Vol.40 - 2018,来学习一门新的编程语言吧!

    摘要:入门,第一个这是一门很新的语言,年前后正式公布,算起来是比较年轻的编程语言了,更重要的是它是面向程序员的函数式编程语言,它的代码运行在之上。它通过编辑类工具,带来了先进的编辑体验,增强了语言服务。 showImg(https://segmentfault.com/img/bV1xdq?w=900&h=385); 新的一年不知不觉已经到来了,总结过去的 2017,相信小伙们一定有很多收获...

    nihao 评论0 收藏0
  • SegmentFault 技术周刊 Vol.40 - 2018,来学习一门新的编程语言吧!

    摘要:入门,第一个这是一门很新的语言,年前后正式公布,算起来是比较年轻的编程语言了,更重要的是它是面向程序员的函数式编程语言,它的代码运行在之上。它通过编辑类工具,带来了先进的编辑体验,增强了语言服务。 showImg(https://segmentfault.com/img/bV1xdq?w=900&h=385); 新的一年不知不觉已经到来了,总结过去的 2017,相信小伙们一定有很多收获...

    Drummor 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<