服务器之家

服务器之家 > 正文

python版大富翁源代码分享

时间:2021-04-21 00:11     来源/作者:Khalil_XUT

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

?
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
# -*- coding: utf-8 -*-
 
 
# code by: 物网141 王璞劼khalil
# name:   理工大富翁beta2.0
# describe: 基于python的一个2d大富翁游戏
'''
1.游戏地图为自己使用各种网络素材制作;
 各种按钮和选项,小图标等也是使用ps制作。
2.声音效果主要为背景音乐和几种游戏中音效;
3.游戏设定了两个类:玩家和建筑
 玩家的参数和方法都在代码中给出;
 具体有:移动方法、位置判断方法、
  购买房屋方法、添加小房子方法、
 事件判断方法。
4.玩家在大富翁的主要操作是投掷骰子,由随机函数
 进行判定然后进行移动,进行位置判断,然后开始
 进行相关的判定。
5.游戏中的按键有:是、否、和结束回合;
 每个按键由没按下与按下两种状态的图片组成,
 这个设计花费了一定时间。
 还有 开始游戏 和 扔骰子 的两个明暗按钮,
 由pygame优化后的一个函数实现。
6.玩家的位置与电脑重叠时会将双方的位置进行一定
 偏移,防止进行覆盖,分不清自己的位置。
7.游戏基础功能有移动,购买房子,在已经购买的房子下
 搭建新的小房子增加过路费,被收费,判断胜负的基础
 功能,此外还加入了幸运事件:
  财神 - 免收费一次
  衰神 - 双倍被收费一次
  破坏神 - 直接破坏一个建筑 无论敌我
  土地神 - 强占对面建筑
 这四项功能在位置处于左上角和右下角的时候会被触发,
 添加了很多游戏乐趣哦~~~ ^_^
8.游戏基于python的一个模块pygame实现,给我提供了很
 多快乐的时光,谢谢老师的阅览与郭宁同学的协助答辩
 :)
'''
 
#####################准备工作##################
 
# 初始化各种模块
import pygame
import random
import sys
 
# 定义类
class player():
  def __init__(self, image ,name , isplayer):
    self.name = name
    self.money = 10000
    self.isgoingtomove = false
    self.movable = true
    self.image = image
    self.position = 0
    self.temp_position = false
    self.dice_value = 0
    self.locatedbuilding = 0
    self.showtext = []
    self.isplayer = isplayer
    self.ownedbuildings = []
    self.isshowtext = false
    self.soundplaylist = 0
    self.caishen = 0
    self.shuaishen = 0
    self.tudishen = 0
    self.pohuaishen = 0
    
  
  def judgeposition(self,buildings): # 位置判断 返回值是所在位置的建筑
    for each in buildings:
      for every in each.location:
        if self.position == every:
          return each
          
      
      # 当使用元组时 当元组中只有一个元素时 发现该元素不可迭代
      # 出现错误 换成列表后解决
      '''
      try:
        for every in each.location:
          if self.position == every:
            print(each.name)
      except:
        if self.position == every:
          print(each.name)
      '''
      
  def buyabuilding(self,ispressyes):  # 购买方法
    if ispressyes and self.locatedbuilding.owner != self.name:
      self.locatedbuilding.owner = self.name
      self.locatedbuilding.wasbought = true
      self.ownedbuildings.append(self.locatedbuilding)
      self.money -= self.locatedbuilding.price
      self.showtext = [self.name + '购买了' + self.locatedbuilding.name + '!']
      self.soundplaylist = 1
      return true
    else:
      return false
    
     
      
  def addahouse(self,ispressyes): # 在建筑物上添加一个房子
    try:
      if ispressyes and self.locatedbuilding.owner == self.name:
        self.locatedbuilding.builtroom += 1
        self.money -= self.locatedbuilding.payment
        self.showtext = [self.name + '在' + self.locatedbuilding.name + '上!','盖了一座房子!',\
                '有%d' % self.locatedbuilding.builtroom + '个房子了!',\
                "它的过路费是%d" % (self.locatedbuilding.payment * \
                        (self.locatedbuilding.builtroom + 1)) ]
        self.soundplaylist = 2
        return true
      else:
        return false
    except:
      pass
  
  def move(self,buildings,allplayers):  # 移动方法 返回值是所在的建筑位置
    self.dice_value = random.randint(1,6)
    self.position += self.dice_value
    if self.position >= 16:
      self.position -= 16
    self.locatedbuilding = self.judgeposition(buildings)
    self.isshowtext = true
    return self.eventinposition(allplayers)
  
  
  def eventinposition(self,allplayers):    # 判断在建筑位置应该发生的事件   
    building = self.locatedbuilding
    if building.name != '空地':
      if self.locatedbuilding.wasbought == false: # 未购买的时候显示建筑的数据!
        if self.isplayer == true:
          textline0 = self.name +'扔出了' + '%d'% self.dice_value + '点!'
          textline1 = self.name +'来到了' + building.name + '!'
          textline2 = '购买价格:%d' % building.price
          textline3 = '过路收费:%d' % building.payment
          textline4 = '是否购买?'
          self.showtext = [textline0,textline1,textline2,textline3,textline4]
          return true
        else :
          self.addahouse(not self.buyabuilding(true))
          
        # ----- 动画 -------
        # ----- 是否购买 ------
      elif building.owner == self.name: # 路过自己的房子开始加盖建筑!
        if self.pohuaishen == 1:
          textline0 = self.name + '破坏神附体!'
          textline1 = '摧毁了自己的房子!'
          building.owner = 'no'
          building.wasbought = false
          self.showtext = [textline0,textline1]
          self.pohuaishen = 0
        else:
          if self.isplayer == true:
            textline0 = self.name + '扔出了' + '%d'% self.dice_value + '点!'
            textline1 = '来到了ta的'+ self.locatedbuilding.name +'!'
            textline2 = '可以加盖小房子!'
            textline3 = '加盖收费:%d' % building.payment
            textline4 = '是否加盖?'
            self.showtext = [textline0,textline1,textline2,textline3,textline4]
            return true
          # ----- 动画-------
          else:
            self.addahouse(true)
      else:
        for each in allplayers: # 被收费!
          if self.locatedbuilding.owner == each.name and each.name != self.name:
            if self.caishen == 1:
              textline0 = self.name + '财神附体!'
              textline1 = '免除过路费%d!' % (building.payment * (building.builtroom + 1))
              self.showtext = [textline0,textline1]
              self.caishen = 0
            else:
              if self.tudishen == 1:
                textline0 = self.name + '土地神附体!'
                textline1 = '强占土地!'
                textline2 = building.name + '现在属于'+ self.name
                self.locatedbuilding.owner = self.name
                self.showtext = [textline0,textline1,textline2]
                self.tudishen = 0
              else:
                if self.pohuaishen == 1:
                  textline0 = self.name + '破坏神附体!'
                  textline1 = '摧毁了对手的房子!'
                  building.owner = 'no'
                  building.wasbought = false
                  self.showtext = [textline0,textline1]
                  self.pohuaishen = 0
                else:
                  textline0 = self.name + '扔出了' + '%d'% self.dice_value + '点!'
                  textline1 = self.name+ '来到了'+ each.name+'的:'
                  textline2 = building.name + ',被收费!'
                  if self.shuaishen == 1:
                    textline3 = '过路收费:%d*2!' % (building.payment * (building.builtroom + 1)*2)
                    self.shuaishen = 0
                  else:
                    textline3 = '过路收费:%d' % (building.payment * (building.builtroom + 1))
                  textline4 = '哦!'+ self.name +'好倒霉!'
                  self.showtext = [textline0,textline1,textline2,textline3,textline4]
                  # 收费!
                  self.money -= building.payment * (building.builtroom + 1)
                  each.money += building.payment * (building.builtroom + 1)
                  self.soundplaylist = 3
                  # ----- 动画-------
            
    else:
      # 发现不能处理在空地上的情况 于是使用 try & except 来解决!然后加入了幸运事件功能!
      # 后来发现 try except 弊端太大 找不到错误的根源 换为if else嵌套。。
      whichone = self.dice_value % 4
      if whichone == 0:
        self.caishen = 1
        textline2 = '遇到了财神!'
        textline3 = '免一次过路费!'
      if whichone == 1:
        self.shuaishen = 1
        textline2 = '遇到了衰神!'
        textline3 = '过路费加倍一次!'
      if whichone == 2:
        self.tudishen = 1
        textline2 = '遇到了土地神!'
        textline3 = '强占一次房子!'
      if whichone == 3:
        self.pohuaishen = 1
        textline3 = '摧毁路过的房子!'
        textline2 = '遇到了破坏神!'
      textline0 = self.name +'扔出了' +'%d'% self.dice_value + '点!'
      textline1 = '来到了运气地点!'
      self.showtext = [textline0,textline1,textline2,textline3]
 
  
  
  
class building():              # 好像所有功能都在player类里实现了=_=
  def __init__(self,name,price,payment,location):
    self.name = name
    self.price = price
    self.payment = payment
    self.location = location
    self.wasbought = false        # 是否被购买
    self.builtroom = 0          # 小房子建造的数目
    self.owner = 'no'
 
# 带透明度的绘图方法 by turtle 2333
def blit_alpha(target,source,location,opacity):
  x = location[0]
  y = location[1]
  temp = pygame.surface((source.get_width(),source.get_height())).convert()
  temp.blit(target , (-x , -y))
  temp.blit(source,(0,0))
  temp.set_alpha(opacity)
  target.blit(temp,location)
 
########################主函数######################### 
 
 
def main():
  pygame.init()
  clock = pygame.time.clock()
  
  # 初始化屏幕
  size = (1270,768)
  screen = pygame.display.set_mode(size)
  pygame.display.set_caption("理工大大富翁 - made by 王璞劼")
  
  # 读取字体以及有关数据
  textcolorinmessagebox = (141,146,152)
  white = (255,255,255)
  black = (0,0,0)
  red = (255,0,0)
  font = pygame.font.font('resource\\font\\myfont.ttf',30)
  
  
  # 读取资源
  backgroud = pygame.image.load("resource\\pic\\gamemap.png")
  chess = pygame.image.load("resource\\pic\\chess.png")
  chess_com = pygame.image.load("resource\\pic\\chess1.png")
  bigdice_image = pygame.image.load("resource\\pic\\dice.png").convert_alpha()
  dice_1 = pygame.image.load("resource\\pic\\dice_1.png")
  dice_2 = pygame.image.load("resource\\pic\\dice_2.png")
  dice_3 = pygame.image.load("resource\\pic\\dice_3.png")
  dice_4 = pygame.image.load("resource\\pic\\dice_4.png")
  dice_5 = pygame.image.load("resource\\pic\\dice_5.png")
  dice_6 = pygame.image.load("resource\\pic\\dice_6.png")
  dices = [dice_1,dice_2,dice_3,dice_4,dice_5,dice_6]
  yes = pygame.image.load("resource\\pic\\yes.png")
  yes2 = pygame.image.load("resource\\pic\\yes2.png")
  no = pygame.image.load("resource\\pic\\no.png")
  no2 = pygame.image.load("resource\\pic\\no2.png")
  gamestart = pygame.image.load("resource\\pic\\gamestart.png")
  startgamebutton = pygame.image.load("resource\\pic\\startgamebutton.png").convert_alpha()
  turnover = pygame.image.load("resource\\pic\\turnover.png")
  turnover2 = pygame.image.load("resource\\pic\\turnover2.png")
  shuaishen = pygame.image.load("resource\\pic\\shuaishen.png").convert_alpha()
  tudishen = pygame.image.load("resource\\pic\\tudishen.png").convert_alpha()
  caishen = pygame.image.load("resource\\pic\\caishen.png").convert_alpha()
  pohuaishen = pygame.image.load("resource\\pic\\pohuaishen.png").convert_alpha()
  
  rolldicesound = pygame.mixer.sound("resource\\sound\\rolldicesound.wav")
  bgm = pygame.mixer.music.load("resource\\sound\\bgm.ogg")
  throwcoin = pygame.mixer.sound("resource\\sound\\throwcoin.wav")
  moneysound = pygame.mixer.sound("resource\\sound\\moneysound.wav")
  aiyo = pygame.mixer.sound("resource\\sound\\aiyo.wav")
  didong = pygame.mixer.sound("resource\\sound\\didong.wav")
  
  # playlist 在对象中设置应该播放的声音
  playlist = [moneysound ,throwcoin ,aiyo]
  
  # 各种surface的rect
  bigdice_rect = bigdice_image.get_rect()
  bigdice_rect.left , bigdice_rect.top = 50 , 600
  yes_rect = yes.get_rect()
  yes_rect.left , yes_rect.top = 500,438
  no_rect = no.get_rect()
  no_rect.left , no_rect.top = 630,438
  button_rect = startgamebutton.get_rect()
  button_rect.left , button_rect.top = 1003,30
  turnover_rect = turnover.get_rect()
  turnover_rect.left , turnover_rect.top = 1035,613
  
  # 实例化对象
  players = []
  computers = []
  allplayers = []
  player_1 = player(chess , '玩家' , true )
  player_com1 = player(chess_com , '电脑' , false )
  players.append(player_1)
  computers.append(player_com1)
  allplayers.append(player_1)
  allplayers.append(player_com1)
  
  presentplayer = player_com1
  
  # 初始化建筑物数据
  gate = building('大门',1000,200,[1,2])
  fountain = building('喷泉',2000,400,[3,4])
  path = building('小道',800,160,[5])
  library = building('图书馆',2000,400,[6,7])
  kongdi1 = building('空地',0,0,[8])
  classroomten = building('教十',1200,240,[9,10])
  classroomnine = building('教九',1200,240,[11,12])
  resone = building('三餐厅',800,160,[13])
  restwo = building('二餐厅',800,160,[14])
  resthree = building('一餐厅',800,160,[15])
  kongdi2 = building('空地',0,0,[0])
  
  buildings = [gate,fountain,path,library,classroomnine,\
         classroomten,resone,resthree,restwo,kongdi1,kongdi2]
  
  
  
  # 坐标数据 同时处理坐标数据 使之合适
  mapxyvalue = [(435.5,231.5),(509.5,231.5),(588.5,231.5),(675.5,231.5),(758.5,231.5),\
         (758.5,317.0),(758.5,405.5),(758.5,484.5),(758.5,558.5),(679.5,558.5),\
         (601.5,558.5),(518.5,556.5),(435.5,556.5),(435.5,479.5),(435.5,399.0),\
         (435.5,315.5)
         ]
  
  mapchessposition_player = []
  mapchessposition_com = []
  mapchessposition_original = []
  mapchessposition_payment = []
  
  mapmessageboxposition = (474.1 , 276.9)
  yesnomessageboxposition = [(500,438) , (630,438)]
  startgamebuttonposition = (1003,30)
  turnovwrbuttonposition = (1035,613)
  
  
        # 调整位置
  for i in range(0,16):
    mapchessposition_original.append((mapxyvalue[i][0]-50,mapxyvalue[i][1]-80))
    mapchessposition_player.append((mapxyvalue[i][0]-70,mapxyvalue[i][1]-60))
    mapchessposition_com.append((mapxyvalue[i][0]-30,mapxyvalue[i][1]-100))
    mapchessposition_payment.append((mapxyvalue[i][0]-30,mapxyvalue[i][1]-15))
    
  # 循环时所用的一些变量  
  running = true
  image_alpha = 255
  button_alpha = 255
  half_alpha = 30
  showdice = true
  showyes2 = false
  showno2 = false
  showyes_no = false
  pressyes = false
  whetheryes_nojudge = false
  gamestarted = false
  showbutton2 = false
  
  # 播放背景音乐
  pygame.mixer.music.play(100)
  
#################进入游戏循环!######################## 
 
 
  # 循环开始!
  while running:
    if not gamestarted:
      for event in pygame.event.get():
        if event.type == pygame.quit:
          sys.exit()
        
        # 明暗触发 鼠标位置判断
        if event.type == pygame.mousemotion:
          if button_rect.collidepoint(event.pos):
            button_alpha = 255
          else:
            button_alpha = 120
            
        if event.type == pygame.mousebuttondown:
           
          if button_rect.collidepoint(event.pos): # 按下按钮
            didong.play()          
            gamestarted = true
      
      screen.blit(gamestart , (0,0))   
      blit_alpha(screen, startgamebutton, startgamebuttonposition, button_alpha)
    
    
    
    if gamestarted:
    
      for event in pygame.event.get():
        if event.type == pygame.quit:
          sys.exit()
        
        # 明暗触发 鼠标位置判断
        if event.type == pygame.mousemotion:
          if bigdice_rect.collidepoint(event.pos):
            image_alpha = 255
          else:
            image_alpha = 190
            
        
        if event.type == pygame.mousebuttondown:
          
          if bigdice_rect.collidepoint(event.pos): # 按骰子
            if presentplayer != player_1:
              rolldicesound.play(1, 2000)
              pygame.time.delay(2000)
              showyes_no = player_1.move(buildings,allplayers)
              whetheryes_nojudge = showyes_no
              presentplayer = player_1
            else:
              presentplayer.showtext = ['还没到你的回合!']
            
          if turnover_rect.collidepoint(event.pos): # 按回合结束
            showbutton2 = true
            if presentplayer != player_com1:
              showyes_no = player_com1.move(buildings,allplayers)
              presentplayer = player_com1
            else:
              presentplayer.showtext = ['还没到你的回合!']             
          else:
            showbutton2 = false
          
            # 不显示yes_no的时候不能点击它们!
          if whetheryes_nojudge == true:
            if yes_rect.collidepoint(event.pos): # 按是否
              showyes2 = true
              
            if no_rect.collidepoint(event.pos): # 按是否
              showno2 = true
           
        if event.type == pygame.mousebuttonup:
          
          if turnover_rect.collidepoint(event.pos): # 按回合结束
            showbutton2 = false
          
          if yes_rect.collidepoint(event.pos): # 按是否
            showyes2 = false
            showyes_no = false
            # 只有在可以判定的时候才能算按下了是 同时将判断条件置为空
            if whetheryes_nojudge == true:
              pressyes = true
              whetheryes_nojudge = false
              
              
          if no_rect.collidepoint(event.pos): # 按是否
            showno2 = false
            pressyes = false
            showyes_no = false      
            whetheryes_nojudge = false   
      
        # 测试事件选项   
        if event.type == pygame.keydown:
          if event.key == pygame.k_w:
            showyes_no = player_1.move(buildings,allplayers)
            whetheryes_nojudge = showyes_no
            presentplayer = player_1
          if event.key == pygame.k_q:
            showyes_no = player_com1.move(buildings,allplayers)
            presentplayer = player_com1
      
      
      '''for each in allplayers:
        if each.isgoingtomove == true and each.movable == true :
          showyes_no = each.move(buildings,allplayers)
          each.movable = false
          each.isgoingtomove = false'''
      '''
      allisready = true
      
      for each in allplayers:
        if each.movable == true:
          allisready = false
      
      if allisready:
        for each in allplayers:
          each.movable = true
      '''      
       
      # 购买房屋!!!!!!!!
      
      if presentplayer.buyabuilding(pressyes) == true:
        pressyes = false
        
      if presentplayer.addahouse(pressyes) == true:
        pressyes = false   
        
      #########################################################################     
      screen.blit( backgroud , (0,0) )
      blit_alpha(screen, bigdice_image, (50, 600), image_alpha)
      
      
      textposition = [mapmessageboxposition[0],mapmessageboxposition[1]]
      
      # 打印信息
      for each in presentplayer.showtext:
        text = font.render(each, true, white, textcolorinmessagebox)
        screen.blit(text,textposition)
        textposition[1] += 30
      
      # 播放行动声音
      if presentplayer.soundplaylist != 0:
        playlist[presentplayer.soundplaylist - 1].play()
        presentplayer.soundplaylist = 0
        
      # 在位置上显示过路费
      
      for i in range(1,8):
        for each in buildings:
          for every in each.location:
            if i == every:
              if each.owner == presentplayer.name:
                text = font.render('%d' % (each.payment * (each.builtroom + 1))\
                          , true, red)
              elif each.owner == 'no':
                text = font.render('%d' % (each.payment * (each.builtroom + 1))\
                          , true, white)
              elif each.owner != presentplayer.name and each.owner != 'no':
                text = font.render('%d' % (each.payment * (each.builtroom + 1))\
                          , true, black)
              screen.blit(text,mapchessposition_payment[i])
      
      for i in range(9,16):
        for each in buildings:
          for every in each.location:
            if i == every:
              if each.owner == presentplayer.name:
                text = font.render('%d' % (each.payment * (each.builtroom + 1))\
                          , true, red)
              elif each.owner == 'no':
                text = font.render('%d' % (each.payment * (each.builtroom + 1))\
                          , true, white)
              elif each.owner != presentplayer.name and each.owner != 'no':
                text = font.render('%d' % (each.payment * (each.builtroom + 1))\
                          , true, black)
              screen.blit(text,mapchessposition_payment[i])       
      
          
      # 打印金钱数和幸运状态
      
      money_1 = font.render(player_1.name +'金钱:%d' % player_1.money, true, black, white)
      screen.blit(money_1,(0,0))
      
      if player_1.pohuaishen == true:
        screen.blit(pohuaishen,(0,30))
      else:
        blit_alpha(screen, pohuaishen, (0, 30), half_alpha)
        
      if player_1.caishen == true:
        screen.blit(caishen,(55,30))
      else:
        blit_alpha(screen, caishen, (55, 30), half_alpha)
      
      if player_1.shuaishen == true:
        screen.blit(shuaishen,(110,30))
      else:
        blit_alpha(screen, shuaishen, (110, 30), half_alpha)
      
      if player_1.tudishen == true:
        screen.blit(tudishen,(165,30))
      else:
        blit_alpha(screen, tudishen, (165, 30), half_alpha)
      
    
      money_2 = font.render(player_com1.name +'金钱:%d' % player_com1.money, true, black, white)
      screen.blit(money_2,(1000,0))   
      if player_com1.pohuaishen == true:
        screen.blit(pohuaishen,(1000,30))
      else:
        blit_alpha(screen, pohuaishen, (1000, 30), half_alpha)
    
      if player_com1.caishen == true:
        screen.blit(caishen,(1055,30))
      else:
        blit_alpha(screen, caishen, (1055, 30), half_alpha)
      
      if player_com1.shuaishen == true:
        screen.blit(shuaishen,(1110,30))
      else:
        blit_alpha(screen, shuaishen, (1110, 30), half_alpha)
        
      if player_com1.tudishen == true:
        screen.blit(tudishen,(1165,30))
      else:
        blit_alpha(screen, tudishen, (1165, 30), half_alpha)
        
        
      # 放置扔出来的骰子
      if player_1.dice_value != 0 and showdice:
        screen.blit(dices[player_1.dice_value - 1],(70,450))   
      
      # 放置回合结束按钮
      if showbutton2:
        screen.blit(turnover2,turnovwrbuttonposition)
      else:
        screen.blit(turnover,turnovwrbuttonposition)
      
      # 放置是否按钮
      if showyes_no == true:
        screen.blit(yes , yesnomessageboxposition[0])
        screen.blit(no , yesnomessageboxposition[1])
        
        if showyes2 == true:
          screen.blit(yes2 , yesnomessageboxposition[0])
          
        if showno2 == true:
          screen.blit(no2 , yesnomessageboxposition[1]) 
               
          
      # 放置玩家与电脑的位置 如果重合则挪位
      for each in players:
        for every in computers:
          if each.position == every.position:
            screen.blit(each.image,mapchessposition_player[each.position])
            screen.blit(every.image,mapchessposition_com[every.position])
            each.temp_position = true
            every.temp_position = true
            
      for each in players:
        if each.temp_position == false:
          screen.blit(each.image,mapchessposition_original[each.position])
          each.temp_position = true
        each.temp_position = not each.temp_position
        
         
      for every in computers:
        if every.temp_position == false:
          screen.blit(every.image,mapchessposition_original[every.position])
          every.temp_position = true
        every.temp_position = not every.temp_position
            
      
      # 输赢判断
      for each in allplayers:
        if each.money <= 0:
          font = pygame.font.font('resource\\font\\myfont.ttf',200)
          losetext = font.render(each.name +'输了!', true, red)
          screen.fill(black)
          screen.blit(losetext,(100,100))
          font = pygame.font.font('resource\\font\\myfont.ttf',30)     
          pygame.time.delay(3000)
            
    # 画面运行
    
    pygame.display.flip()
    clock.tick(60)       # 刷新率
        
 
# 双击打开运行     
if __name__ == "__main__":
  main()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/hsgwpj/article/details/49000369

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
返回顶部