找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 979|回复: 1

[求助] 求大神帮忙看看为什么没有出现字

抢楼 抢楼 本帖为抢楼帖,欢迎抢楼! 

2

主题

17

帖子

17

积分

贫民

积分
17
QQ
lufu329 发表于 2021-9-20 12:07:17 | 显示全部楼层 |阅读模式
3威望
  1. import sys, random, time, pygame
  2. from pygame.locals import *

  3. def print_text(font, x, y, text, color=(255,255,255)):
  4.     imgText = fon.render(text, True, color)
  5.     screen.blit(imgText, (x,y))

  6. pygame.init()
  7. screen = pygame.display.set_mode((600,500))
  8. pygame.display.set_caption("测试你的打字速度")
  9. font1 = pygame.font.Font(None, 24)
  10. font2 = pygame.font.Font(None, 200)
  11. white = 255,255,255
  12. yellow = 255,255,0

  13. key_flag = False
  14. correct_answer = 97
  15. seconds = 11
  16. score = 0
  17. clock_start = 0
  18. game_over = True

  19. while True:
  20.     for event in pygame.event.get():
  21.         if event.type == QUIT:
  22.             sys.exit()
  23.         elif event.type == KEYDOWN:
  24.             key_flag = True
  25.         elif event.type == KEYUP:
  26.             key_flag = False

  27.         keys = pygame.key.get_pressed()
  28.         if keys[K_ESCAPE]:
  29.             sys.exit()
  30.             
  31.         if keys[K_RETURN]:
  32.             if game_over:
  33.                 game_over = False
  34.                 score = 0
  35.                 seconds = 11
  36. clock_start = time.clock()
  37. current = time.clock() - clock_start
  38. speed = score * 6
  39. if seconds-current < 0:
  40.     game_over = True
  41. elif current <= 10:
  42.     if keys[correct_answer]:
  43.         correct_answer = random.randint(97,122)
  44.         score += 1

  45. screen.fill((0,100,0))

  46. print_text(font1, 0, 0, "让我们看看你打字有多快!")
  47. print_text(font1, 0, 20, "尽量保持10秒钟……")

  48. if key_flag:
  49.     print_text(font1, 500, 0, "<用计算机键盘输入>")

  50. if not game_over:
  51.     print_text(font1, 0, 80, "时间: " + str(int(seconds-current)))

  52. print_text(font1, 0, 100, "速度: " + str(speed) + "字母/分钟")

  53. if game_over:
  54.     print_text(font1, 0, 160, "按回车键开始……")

  55. print_text(font2, 0, 240, chr(correct_answer-32), yellow)

  56. pygame.display.update()

复制代码


测试你的手速.py

1.79 KB, 阅读权限: 1, 下载次数: 2

源文件

回复

使用道具 举报

2

主题

17

帖子

17

积分

贫民

积分
17
QQ
lufu329  楼主| 发表于 2021-9-25 15:06:33 | 显示全部楼层
没有人吗
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表