python打字测速_【pygame游戏编程】第四篇-----打字测速游戏

importpygameclassDisplayboard():‘‘‘展示程序中的文本‘‘‘

def __init__(self, my_settings, screen):

self.screen=screen

self.my_settings=my_settings

self.screen_rect=screen.get_rect()#获取字体对象

self.s_font = pygame.font.Font(r‘fonts\freesansbold.ttf‘,

my_settings.s_font_size)

self.m_font= pygame.font.Font(r‘fonts\freesansbold.ttf‘,

my_settings.m_font_size)

self.l_font= pygame.font.Font(r‘fonts\freesansbold.ttf‘,

my_settings.l_font_size)#获取文本图片

self.top_text_image =self.s_font.render(my_settings.top_text, True,

my_settings.YELLOW)

self.typing_flag_image= self.s_font.render("typing!", True,

my_settings.DARKGRAY)

self.start_text_image=self.m_font.render(my_settings.start_text, True,

my_settings.GREEN, my_settings.OLIVE)#获取surface的rect

self.start_image_rect =self.start_text_image.get_rect()

self.start_image_rect.center=self.screen_rect.center

self.typing_image_rect=self.typing_flag_image.get_rect()

self.typing_image_rect.right= self.screen_rect.right - 20self.typing_image_rect.top= 20

#显示各个文本的函数

defdisplay_top_text(self):

self.screen.blit(self.top_text_image,

self.my_settings.top_text_position)defdisplay_typing_text(self):

self.screen.blit(self.typing_flag_image, self.typing_image_rect)defdisplay_start_text(self):

self.screen.blit(self.start_text_image, self.start_image_rect)defdisplay_speed_text(self, speed):

speed_text_image= self.s_font.render("Current Speed:" + str(speed) + "letters/min",

True, self.my_settings.YELLOW)

speed_text_rect=speed_text_image.get_rect()

speed_text_rect.centery= self.screen_rect.centery / 2speed_text_rect.right= self.screen_rect.right - 20self.screen.blit(speed_text_image, speed_text_rect)defdisplay_letter_text(self, letter):

letter_text_image=self.l_font.render(letter, True,

self.my_settings.RED)

letter_rect=letter_text_image.get_rect()

letter_rect.centerx=self.screen_rect.centerx

letter_rect.centery= self.screen_rect.bottom * 2 / 3self.screen.blit(letter_text_image, letter_rect)defdisplay_remaining_time_text(self, remaining_time):

remaining_time_image= self.s_font.render("Remaining Time:" +str(remaining_time),

True, self.my_settings.OLIVE)

remaining_time_rect=remaining_time_image.get_rect()

remaining_time_rect.top= self.screen_rect.top + 20remaining_time_rect.centerx=self.screen_rect.centerx

self.screen.blit(remaining_time_image, remaining_time_rect)defdisplay_fastest_text(self, fastest_speed):

fastest_speed_image= self.s_font.render("Fastest Speed:" +str(fastest_speed),

True, self.my_settings.YELLOW)

fastest_speed_rect=fastest_speed_image.get_rect()

fastest_speed_rect.centery= self.screen_rect.centery / 2fastest_speed_rect.left= 20self.screen.blit(fastest_speed_image, fastest_speed_rect)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值