韩小小鱼 2022-12-01 21:31 采纳率: 100%
浏览 14
已结题

pygame图案问题

下面这个是我要做的内容,我刚开始学,不是很懂,我把上个问题回答给的代码放进来,但是第二个画面是绿色的,是什么原因

import pygame
import sys


def Morse_code(x):
    '''
    function:返回对应的摩斯码
    '''
    dic = {'A': '._', 'B': '_...', 'C': '_._.', 'D': '_..', 'E': '.', 'F': '.._.',
           'G': '__.', 'H': '....', 'I': '..', 'J': '.___', 'K': '_._', 'L': '._..',
           'M': '__', 'N': '_.', 'O': '___', 'P': '.__.', 'Q': '__._', 'R': '._.',
           'S': '...', 'T': '_', 'U': '.._', 'V': '..._', 'W': '.__', 'X': '_.._',
           'Y': '_.__', 'Z': '__..',
           '1': '.____', '2': '..___', '3': '...__', '4': '...._', '5': '.....',
           '6': '_....', '7': '__...', '8': '___..', '9': '____.', '0': '_____',
           ' ': ' '}
    if x in dic:
        return dic[x]


def Turn_Morse_code(s):
    '''
    function:将字符串转为摩斯密码串
    '''
    s = s.upper()  # 将小写字母转换为大写字母
    num = len(s)
    Morsecode = ''
    i = 0
    for i in range(num):
        Morsecode += str(Morse_code(s[i]))
    return Morsecode
s:str = "ILOVEYOU"
Morse = Turn_Morse_code(s)


pygame.init()
pygame.mixer.init()
ck = pygame.display.set_mode((800,500))   #  游戏窗口
pygame.display.set_caption("发报机")    #  给窗口取个名
clock = pygame.time.Clock()                         #  游戏刷新速度
start_ck = pygame.Surface(ck.get_size())    #   充当开始界面的画布
start_ck2 = pygame.Surface(ck.get_size())  #  充当第一关的画布界面暂时占位
start_ck3 = pygame.Surface(ck.get_size())
start_ck = start_ck.convert()
start_ck2 = start_ck2.convert()
start_ck.fill((255,255,255))  # 白色画布1(开始界面用的)
start_ck2.fill((0,255,0))
start_ck3.fill((255,255,255))
# 加载各个素材 并且赋予变量名
track = pygame.mixer.music.load("./sound/sound.mp3")
i1 = pygame.image.load("./s1.png")
i1.convert()
i11 = pygame.image.load("./s2.png")
i11.convert()

i2 = pygame.image.load("./n2.png")
i2.convert()
i21 = pygame.image.load("./n1.png")
i21.convert()


bg = pygame.image.load('./bi.jpg')
bg.convert()
f = pygame.font.Font('./WETPET.TTF',50)

pygame.mixer.music.play()
#  以下为选择开始界面鼠标检测结构。
n1 = True
while n1:
    clock.tick(30)
    buttons = pygame.mouse.get_pressed()
    x1, y1 = pygame.mouse.get_pos()
    if x1 >= 227 and x1 <= 555 and y1 >= 141 and y1 <=207:
        start_ck.blit(i11, (200, 120))
        if buttons[0]:
            n1 = False

    elif x1 >= 227 and x1 <= 555 and y1 >= 271 and y1 <=337:
        start_ck.blit(i21, (200, 230))
        if buttons[0]:
            pygame.quit()
            exit()

    else:
        start_ck.blit(i1, (200, 120))
        start_ck.blit(i2, (200, 230))


    ck.blit(start_ck,(0,0))
    pygame.display.update()


    # 下面是监听退出动作

    # 监听事件
    for event in pygame.event.get():

        # 判断事件类型是否是退出事件
        if event.type == pygame.QUIT:
            print("游戏退出...")

            # quit 卸载所有的模块
            pygame.quit()

            # exit() 直接终止当前正在执行的程序
            sys.exit()
ck.blit(start_ck2,(0,0))
pygame.display.update()

deviation = 0
pos = 100


while True:
    for i in Morse:
        if (i == '.'):
            pygame.draw.line(start_ck2, (225, 0, 0), (pos - deviation, 30), (pos + 5 - deviation, 30), 5)
            pos += 10
        if (i == '-'):
            pygame.draw.line(start_ck2, (225, 0, 0), (pos - deviation, 30), (pos + 20 - deviation, 30), 5)
            pos += 25
    pos = 100
    deviation += 0.05

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
    pygame.display.flip()


  • 写回答

1条回答 默认 最新

  • orbitgw C++领域新星创作者 2022-12-01 21:41
    关注

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 12月10日
  • 已采纳回答 12月2日
  • 创建了问题 12月1日

悬赏问题

  • ¥200 csgo2的viewmatrix值是否还有别的获取方式
  • ¥15 Stable Diffusion,用Ebsynth utility在视频选帧图重绘,第一步报错,蒙版和帧图没法生成,怎么处理啊
  • ¥15 请把下列每一行代码完整地读懂并注释出来
  • ¥15 pycharm运行main文件,显示没有conda环境
  • ¥15 易优eyoucms关于二级栏目调用的问题
  • ¥15 寻找公式识别开发,自动识别整页文档、图像公式的软件
  • ¥15 为什么eclipse不能再下载了?
  • ¥15 编辑cmake lists 明明写了project项目名,但是还是报错怎么回事
  • ¥15 关于#计算机视觉#的问题:求一份高质量桥梁多病害数据集
  • ¥15 特定网页无法访问,已排除网页问题