|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
源码如下:
- import pygame, sys, random, time
- from pygame import *
- def print_text(font, x, y, text, color=(255, 255, 255)):
- imgText = font.render(text, True, colour)
- dvreen.bilit(imgText, (x, y))
- pygame.init()
- screen = pygame.display.set_mode((600, 500))
- pygame.display.set_caption("Keyboard Demo")
- font1 = pygame.font.Font("zh.ttf", 25)
- font2 = pygame.font.Font("zh.ttf", 200)
- white = 255, 255, 255
- yellow = 255, 255, 0
- correct_answer = 97
- seconds = 11
- score = 0
- clock_start = 0
- game_over = True
- while True:
- for event in pygame.event.get():
- if event.type == QUIT:
- sys.exit()
- elif event.type == KEYDOWN:
- key_flag = True
- elif event.type == KEYUP:
- key_flag = False
- keys = pygame.key.get_pressed()
- if keys[K_ESCAPE]:
- pygame.quit()
- sys.exit()
- if keys[K_RETURN]:
- if game_over:
- game_over = False
- score = 0
- second = 11
- clock_start = time.clock()
- current = time.clock() - clock_start
- speed = score * 6
- if seconds-current < 0:
- game_over = True
- elif current <= 10:
- if keys[corrent_answer]:
- corrent_answer = random.randint(97, 122)
- score += 1
- screen.fill((0, 100, 0))
- print_text(font1, 0, 0, "让我们看看你打字有多快!")
- print_text(font1, 0, 20, "加油奋战10秒钟...")
- if key_flag:
- print_text(font1, 500, 0, "key")
- if not game_over:
- print_text(font1, 0, 80, f"时间{int(seconds-current)}")
- print_text(font2, 0, 100, f"速度{speed}个/秒")
- if game_over:
- print_text(font1, 0, 160, "请按下Enter键重新开始...")
- print_text(font2, 0, 240, chr(correct_answer-32), yellow)
- pygame.display.update()
复制代码
javascript:;
运行后不报错,但什么也不显示
- import time as t
- import pygame, sys, random
- from pygame import *
- def print_text(font, x, y, text, color=(255, 255, 255)):
- imgText = font.render(text, True, color)
- screen.blit(imgText, (x, y))
- pygame.init()
- screen = pygame.display.set_mode((600, 500))
- pygame.display.set_caption("Keyboard Demo")
- font1 = pygame.font.Font("zh.ttf", 25)
- font2 = pygame.font.Font("zh.ttf", 200)
- white = 255, 255, 255
- yellow = 255, 255, 0
- correct_answer = 97
- seconds = 11
- score = 0
- clock_start = 0
- game_over = True
- while True:
- for event in pygame.event.get():
- if event.type == QUIT:
- sys.exit()
- elif event.type == KEYDOWN:
- key_flag = True
- elif event.type == KEYUP:
- key_flag = False
- keys = pygame.key.get_pressed()
- if keys[K_ESCAPE]:
- pygame.quit()
- sys.exit()
- if keys[K_RETURN]:
- if game_over:
- game_over = False
- score = 0
- second = 11
- clock_start = t.time()
- current = t.time() - clock_start
- speed = score * 6
- if seconds-current < 0:
- game_over = True
- elif current <= 10:
- if keys[correct_answer]:
- corrent_answer = random.randint(97, 122)
- score += 1
- screen.fill((0, 100, 0))
- print_text(font1, 0, 0, "让我们看看你打字有多快!")
- print_text(font1, 0, 20, "加油奋战10秒钟...")
-
- if key_flag:
- print_text(font1, 500, 0, "key")
- if not game_over:
- print_text(font1, 0, 80, f"时间{int(seconds-current)}")
- print_text(font2, 0, 100, f"速度{speed}个/秒")
- if game_over:
- print_text(font1, 0, 160, "请按下Enter键重新开始...")
- print_text(font2, 0, 240, chr(correct_answer-32), yellow)
- pygame.display.update()
复制代码
尽力改正了一些低级错误,但是仍然没改完
|
-
|