猫史档案馆


【Python作品分享】简单的喵抽奖器

用户:舍簪笏于百年舍簪笏于百年查看:0 回复:0 评论:0 创建时间:2021-12-05T20:14:28


center_imagecenter_imagecenter_imagecenter_image

import pygame
import sys
import random
import 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', 66)

#抽奖逻辑函数


def choujiang(x):
    for __count in range(x):
        x = random.randint(0, 100)
        if (x >= 20):
            y = random.randint(0, 8)
            screen.blit(bluepic, (0, 0))
            mytext = font.render(sanxing[y], True, color[3])
            screen.blit(mytext, [280, 280])
            pygame.display.update()
            time.sleep(1)
        elif 2 < x < 20:
            y = random.randint(0, 15)
            screen.blit(purplepic, (0, 0))
            mytext = font.render(sixing[y], True, color[0])
            screen.blit(mytext, [280, 280])
            pygame.display.update()
            time.sleep(1.5)
        elif x <= 2:
            y = random.randint(0, 9)
            screen.blit(yellowpic, (0, 0))
            mytext = font.render(wuxing[y], True, color[2])
            screen.blit(mytext, [280, 280])
            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下一页