Eric_zhao 发表于 2021-10-27 18:52

python开发一款练习打字游戏_仅供学习

名称:练习打字
主要功能:
1.分段获取英文短句,将英文短句分单词检测。索引到单词再拆分为字母用以检测正确性
2.输入框设计,提示符点击输入
3.显示正确与错误,正确则显示单词 错误则提示错误
4.打字速度检测,实现背景颜色实时变化
5.单词正确数量统计
6.倒计时统计
7.英文短句切换


部分代码: ‘
import pygame
from pygame.locals import *
import sys
from datetime import datetime
from logic import Lo_gic
from dis_play import Dis_play
from Ascii_key import asc_key,bgcolors
pygame.init()
t = pygame.time.Clock()
screen = pygame.display.set_mode((800,600))
pygame.display.set_caption("typing games")
text1 = 'Click-input:'
count = 0
A = ord('A')
Z = ord('Z')
a = ord('a')
z = ord('z')
key_letter = 0
input_lst = []
input_lst2 = []
flag = False
right_count = 0
count_down = False
game_start = False

eng_text = ''
clock_time = 0
while True:
    t.tick(20)
    wang = Lo_gic()
    dis_sc = Dis_play()
    current = wang.Count_down(count_down, clock_time, game_start)
    screen.fill(bgcolors())
    if not flag:
      screen.fill((0,0,0))
    # eng_text = wang.open_english()
    # print(ord(eng_text))
      
    screen.blit(dis_sc.font_text(40, ''.join(eng_text), (255, 255, 255)), (10, 100))
    pygame.draw.rect(screen,(200,200,0),dis_sc.draw_rect(200,300,400,50),5)
    screen.blit(dis_sc.font_text(50,text1,(255,0,0)), (210,310))
    screen.blit(dis_sc.font_text(40, ''.join(input_lst), (0, 255, 255)), (10, 100))
    screen.blit(dis_sc.font_text(50, ''.join(input_lst2), (255, 0, 255)), (210, 310))
    screen.blit(dis_sc.font_text(40,'words_number:'+str(right_count),(255,255,0)), (550,20))
    screen.blit(dis_sc.font_text(20, 'Welcome to the typing game', (0, 255, 255)), (0, 580))
    screen.blit(dis_sc.font_text(50, 'countdown: ' + str(current), (255, 0, 0)), (20, 20))
    input_lst2,input_lst,eng_text,right_count,flag,text1,aa= \
      asc_key(screen,input_lst2,input_lst,text1)
    # print(click_ing)
    if aa:
      clock_time = datetime.now()
      count_down = True
      game_start = True

    if current == True:
      screen.blit(dis_sc.font_text(80, 'GAMEOVER', (255, 255, 0)), (210, 250))
      pygame.display.update()
      pygame.time.delay(2000)
      break
    else:
      screen.blit(dis_sc.font_text(50, 'countdown: ' + str(current), (255, 0, 0)), (20, 20))
    for event in pygame.event.get():
      if event.type == QUIT:
            pygame.quit()
            sys.exit()   
    pygame.display.update()








完整项目:链接:https://pan.baidu.com/s/1xtPwGdDdbcxqIrmaqCLoZQ
提取码:vax7

紫气 发表于 2021-10-27 19:00

学习一下,感谢楼主分享

deyen 发表于 2021-10-27 19:08

pygame,可以媲美金山了

YUCHEN1213 发表于 2021-10-27 19:10

学习大佬

king100 发表于 2021-10-27 19:11

感谢分享,感恩楼主

迦南圣经 发表于 2021-10-27 19:13

突然想到金山打字的那个飞机陨石游戏

denislov 发表于 2021-10-27 19:15

pygame的打字小游戏{:1_893:}

Heilexplode 发表于 2021-10-27 19:18

哈哈,再设计设计ui就完美了

414504394 发表于 2021-10-27 19:19

不错666,比金山打字好

阿笙小祖宗 发表于 2021-10-27 19:36

感谢分享
页: [1] 2 3
查看完整版本: python开发一款练习打字游戏_仅供学习