猫史档案馆


wodezuoping

用户:舍簪笏于百年舍簪笏于百年查看:0 回复:0 评论:0 创建时间:2022-01-05T12:37:48


center_imagecenter_imagecenter_imagecenter_image

import pygame
import sys
import random,time
from pygame.locals import*
from pygame.color import THECOLORS
#文件数据
bluepic = pygame.image.load('./蓝色的.png')
purplepic = pygame.image.load('./紫色的.png')
yellowpic = pygame.image.load('./黄色的.png')
bg = pygame.image.load('./bg.png')
#列表数据
sanxing = ['两个红果', '荷蛋', '一碗饭', '喵莓冰激凌', '两个果', '冰激凌','一个蛋','棒棒糖']
sixing = ['奶昔', '喵莓奶昔', '奇怪的果汁', '黑色的果汁', '可乐']
wuxing = ['火鸡', '感恩节火鸡', '美味的火鸡',]
#常用颜色
purple = [120, 60, 240]
red = [255, 48, 48]
yellow = THECOLORS['yellow']
blue = [0, 150, 255]
brown = THECOLORS['brown']
pink = THECOLORS['pink']
white = THECOLORS['white']
color = [purple, red, yellow, blue, brown, pink, white]

colck = pygame.time.Clock()
pygame.init()
screen = pygame.display.set_mode((800,600), 0)
pygame.display.set_caption('抽奖器')
screen.fill([191,239, 255])
screen.blit(bg,[0,0])
pygame.display.flip()
font = pygame.font.SysFont('SimHei', 40)
ziti_x = 330
ziti_y = 300

#抽奖逻辑函数
def choujiang(x):
    for __count in range(x):
        x = random.randint(0, 100)
        if (x >= 20):
            y = random.randint(0, 7)
            screen.blit(bluepic, (0, 0))
            mytext = font.render(sanxing[y],True,color[3])
            screen.blit(mytext,[ziti_x,ziti_y])
            pygame.display.update()
            time.sleep(1)
        elif 2 < x < 20:
            y = random.randint(0, 4)
            screen.blit(purplepic, (0, 0))
            mytext = font.render(sixing[y], True, color[0])
            screen.blit(mytext, [ziti_x, ziti_y])
            pygame.display.update()
            time.sleep(1.5)
        elif x <= 2:
            y = random.randint(0, 2)
            screen.blit(yellowpic, (0, 0))
            mytext = font.render(wuxing[y], True, color[2])
            screen.blit(mytext, [ziti_x, ziti_y])
            pygame.display.update()
            time.sleep(1.8)

#Game的主循环
while True:
    pos_x,pos_y = pygame.mouse.get_pos()
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        if event.type == pygame.KEYDOWN:
            if event.key == K_UP:
                pygame.quit()
                sys.exit()
        elif event.type == pygame.MOUSEBUTTONDOWN:
            if pos_x >400 and pos_y >500:
                x = 10
                choujiang(x)
                time.sleep(1)
                screen.blit(bg, [0, 0])
            elif pos_x < 400 and pos_y > 500:
                x = 1
                choujiang(x)
                time.sleep(1)
                screen.blit(bg,[0,0])
            else:
                m =random.randint(0,6)
                txt = font.render('QwQ',True,color[m])
                screen.blit(txt,(pos_x,pos_y))
    colck.tick(60)
    pygame.display.update()
    


回复

上一页1 页 / 共 0下一页