import pygame
import random
import sys
class BoTTon:
def __init__(self):
self.start=pygame.image.load("start_1.JPG")
self.stop=pygame.image.load("stop_1.JPG")
self.end=pygame.image.load("exit_1.JPG")
self.startRect=self.start.get_rect().move(0,0)
self.stopRect=self.stop.get_rect().move(200,8)
self.endRect=self.end.get_rect().move(400,0)
class Dice:
def __init__(self):
self.dice = pygame.image.load("assets:3.JPG")
self.diceRect = self.dice.get_rect().move(225, 225)
self.diceSpin=[pygame.image.load("assets:3.jpg"),
pygame.image.load("assets:2.jpg"),
pygame.image.load("assets:1.jpg")]
self.diceStop=[pygame.image.load("dice_1.jpg"),
pygame.image.load("dice_2.jpg"),
pygame.image.load("dice_3.jpg"),
pygame.image.load("dice_4.jpg"),
pygame.image.load("dice_5.jpg"),
pygame.image.load("dice_6.jpg")]
self.StopStatus=random.randint(0,5)
self.SpinStatus=0
def move(self):
self.SpinStatus+=1
if self.SpinStatus==3:
self.SpinStatus=0
def creatmap1():
screen.fill((0, 0, 0))
screen.blit(background, (0, 0))
screen.blit(BoTTon.start, BoTTon.startRect)
screen.blit(BoTTon.stop, BoTTon.stopRect)
screen.blit(BoTTon.end, BoTTon.endRect)
if not stop and not start:
pygame.display.update()
def creatmap2():
screen.fill((0,0,0))
screen.blit(background,(0,0))
screen.blit(BoTTon.start, BoTTon.startRect)
screen.blit(BoTTon.stop, BoTTon.stopRect)
screen.blit(BoTTon.end, BoTTon.endRect)
screen.blit(Dice.diceSpin[Dice.SpinStatus],Dice.diceRect)
Dice.move()
if not stop and start:
pygame.display.update()
def creatmap3():
screen.fill((0,0,0))
screen.blit(background,(0,0))
screen.blit(BoTTon.start, BoTTon.startRect)
screen.blit(BoTTon.stop, BoTTon.stopRect)
screen.blit(BoTTon.end, BoTTon.endRect)
screen.blit(Dice.diceStop[Dice.StopStatus],Dice.diceRect)
if stop and not start:
pygame.display.update()
if __name__=='__main__':
pygame.init()
size=width,height=600,600
screen = pygame.display.set_mode(size)
clock = pygame.time.Clock()
BoTTon=BoTTon()
Dice=Dice()
background = pygame.image.load("background.jpg")
stop=False
start=False
empirnum=[0,0,0,0,0,0]
n=0
while True:
clock.tick(20)
for event in pygame.event.get():
if event.type==pygame.QUIT \
or (event.type == pygame.MOUSEBUTTONDOWN \
and 0 <= event.pos[1] <= 113 \
and 400 <= event.pos[0] <= 600):
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN and 0 <= event.pos[0] <= 200 and 0 <= event.pos[1] <= 113:
start=True
stop=False
if event.type == pygame.MOUSEBUTTONDOWN and 200 <= event.pos[0] <= 400 and 8 <= event.pos[1] <= 121:
stop = True
start=False
n+=1
Dice.StopStatus=random.randint(0,5)
for j in range(1, 7):
if j == Dice.StopStatus:
empirnum[j - 1] += 1
break
if not start and not stop:
creatmap1()
if start and not stop:
creatmap2()
if not start and stop:
creatmap3()
pygame.quit()
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
骰子.zip (15个子文件)
骰子
start_1.JPG 7KB
.DS_Store 6KB
dice_1.jpg 6KB
stop_1.JPG 7KB
骰子.py 3KB
dice_2.jpg 6KB
assets:1.jpg 4KB
assets:2.jpg 6KB
exit_1.JPG 7KB
dice_3.jpg 6KB
background.jpg 21KB
dice_6.jpg 6KB
dice_4.jpg 6KB
assets:3.jpg 4KB
dice_5.jpg 6KB
共 15 条
- 1
Focus�
- 粉丝: 14
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页