|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 shigure_takimi 于 2017-4-13 08:18 编辑
- import pygame, random
- from pygame.locals import *
- pygame.init()
- screen = pygame.display.set_mode((800,600))
- pygame.display.set_caption("Jan-Ken-Pon")
- jan = pygame.image.load("1.jpg").convert()
- ken = pygame.image.load("2.jpg").convert()
- pon = pygame.image.load("3.jpg").convert()
- jan1 = pygame.transform.smoothscale(jan,(jan.get_width()//2, jan.get_height()//2))
- jan2 = pygame.transform.scale2x(jan)
- jan2_com = pygame.transform.flip(jan2, True, False)
- ken1 = pygame.transform.smoothscale(ken,(ken.get_width()//2, ken.get_height()//2))
- ken2 = pygame.transform.scale2x(ken)
- ken2_com = pygame.transform.flip(ken2, True, False)
- pon1 = pygame.transform.smoothscale(pon,(pon.get_width()//2, pon.get_height()//2))
- pon2 = pygame.transform.scale2x(pon)
- pon2_com = pygame.transform.flip(pon2, True, False)
- font1 = pygame.font.SysFont(None, 80,bold = True)
- font2 = pygame.font.SysFont(None, 40,bold = True)
- font3 = pygame.font.SysFont(None, 25,bold = True)
- text1 = font1.render("JAN-KEN-PON",True,(255,255,0))
- text2 = font2.render("Click to Select",True,(255,255,0))
- text3 = font2.render("VS",True,(255,255,0))
- text4 = font2.render("Enter to Reset",True,(255,255,0))
- text_per = font3.render("PERSON",True,(255,255,0))
- text_com = font3.render("COMPUTER",True,(255,255,0))
- com_selected = [jan2_com,ken2_com,pon2_com]
- selected = [jan2,ken2,pon2]
- clicked = False
- # 勝負の条件
- win = [(jan2,ken2_com),(ken2,pon2_com),(pon2,jan2_com)]
- lost = [(ken2,jan2_com),(pon2,ken2_com),(jan2,pon2_com)]
- draw = [(jan2,jan2_com),(ken2,ken2_com),(pon2,pon2_com)]
- per = None
- com = None
- result = 'RESULT'
- clock = pygame.time.Clock()
- done = False
- while not done:
- pos = pygame.mouse.get_pos()
- for event in pygame.event.get():
- if event.type == QUIT:
- done = True
- if not clicked and event.type == MOUSEBUTTONDOWN and 520 < pos[1] < 585:
- if 250 < pos[0] < 315:
- per = selected[0]
- clicked = True
- elif 367 < pos[0] < 432:
- per = selected[1]
- clicked = True
- elif 485 < pos[0] < 550:
- per = selected[2]
- clicked = True
- pressed_keys = pygame.key.get_pressed()
- if clicked and pressed_keys[K_RETURN]:
- clicked = False
- result = 'RESULT'
-
- screen.fill((0,120,255))
- screen.blit(text1,(400 - text1.get_width()//2,30))
- screen.blit(text2,(400 - text2.get_width()//2,460))
- screen.blit(text3,(400 - text3.get_width()//2,300))
- screen.blit(text4,(400 - text4.get_width()//2,485))
- screen.blit(text_com,(230 - text_com.get_width()//2,140))
- screen.blit(text_per,(570 - text_per.get_width()//2,140))
- result_img = font2.render(result,True,(255,0,0))
- screen.blit(result_img,(400 - result_img.get_width()//2,100))
- screen.blit(jan1,(250,520))
- screen.blit(ken1,(367,520))
- screen.blit(pon1,(485,520))
- # ジャンケンポン
- if not clicked:
- com = random.choice(com_selected)
- screen.blit(random.choice(com_selected),(100,170))
- screen.blit(random.choice(selected),(440,170))
- else:
- screen.blit(com,(100,170))
- screen.blit(per,(440,170))
- # 勝負を判断
- if clicked:
- if (per,com) in win:
- result = 'You Win!!'
- if (per,com) in lost:
- result = 'You Lost!!'
- if (per,com) in draw:
- result = 'Draw Game!!'
- clock.tick(60)
- pygame.display.flip()
- pygame.quit()
复制代码 |
|