Pygame开发一个打字游戏

背景:

You are the chairperson of the computer club, and you are tasked withdeveloping a program for your schoolmates to practice English typing. Theprogram should have the following features:
“Typing a given passage.
Calculating accuracy and typing speed.
Viewing a list of previous results.

You have the option to implement additional features as well. To prepare forthis project, your teacher will guide you through the following tasks:
a. Design and create a flowchart for the main program.
b. Complete the main program.
c. Develop the sub-programs

你是计算机俱乐部的主席,你的任务是为你的同学开发一个练习英语打字的程序。该程序应具有以下特点:

输入一段给定的文字。

计算精度和打字速度。

查看先前结果的列表。

您还可以选择实现其他功能。为了准备这个项目,你的老师将指导你完成以下任务:

a.设计并创建主程序流程图。

b.完成主程序。

c.开发子程序

代码运行效果:

使用python的Pygame库实现,如下列图。

1-其中英文句子内容来源于python爬虫每日爬取的英文句子。

2-用户进入打字游戏页面时会有游戏背景音乐,输入错误时会有错误音效。

3-成就页面有成就规则来约定画出的星星。

菜单页面:

Pygame开发一个打字游戏_第1张图片

进行打字游戏界面

Pygame开发一个打字游戏_第2张图片

分数界面:

Pygame开发一个打字游戏_第3张图片

成就页面:

Pygame开发一个打字游戏_第4张图片

Pygame开发一个打字游戏_第5张图片

Pygame开发一个打字游戏_第6张图片

演示视频:

pygame开发打字小游戏演示视频

主要代码:

//联系请加V:zew1040994588

while running:
    screen.fill(BG_COLOR)
    for event in pygame.event.get():
        print("event.type值为%s"%(event.type))
        if event.type == pygame.QUIT:
            running = False
            # 恩-23-9-28-停止程序
            exit()
        elif event.type == pygame.KEYDOWN:
            if game_state == State.MENU:
                if event.key == pygame.K_p:
                    game_state = State.GAME
                    # 从可迭代对象里面挑一个,这里业务逻辑为从句子列表中任意挑一个
                    sentence = random.choice(sentences)
                    print("sentence内容为%s"%(sentence))
                    start_time = time.time()
                    user_input = ""
                elif event.key == pygame.K_s:
                    game_state = State.SCORES
                # 成就页面监测按键A
                elif event.key == pygame.K_a:
                    game_state = State.ACIEVEMENT
                elif event.key == pygame.K_q:
                    running = False
            elif game_state == State.GAME:
                print("pygame.K_BACKSPACE值为%s"%(pygame.K_BACKSPACE))
                print("event.key值为%s"%(event.key))
                if event.key == pygame.K_RETURN:
                    wpm = len(sentence) / 5 / (time.time() - start_time) * 60
                    accuracy = check_input(
                        user_input, sentence) / len(sentence) * 100
                    score = wpm * accuracy / 100
                    insert_score(wpm, accuracy, score)
                    # Update the latest score
                    latest_score = (wpm, accuracy, score)
                    game_state = State.SCORES
//联系请加V:zew1040994588

"""
23-9-26爬取的内容为:
'5th International Daoism Forum opens in Jiangsu',
 "China's tourism market speeds up recovery",
  'US factor emerges in India-Canada row', 
  'China gets to grips with cricket', 
  "China's tourism market speeds up recovery",
 'US factor emerges in India-Canada row', 
 'Thailand rolls out carpet to woo travelers',
  'Trump takes opposite view of McCarthy on shutdown']
"""

"""
23-9-27爬取的内容为:
['Economic uptick anticipated', 
"Tech hegemony name of NSA's game", 
'Anesthesia drug put on control list to halt abuse', 
'Legend wows Hangzhou Asiad at 48', "Tech hegemony name of NSA's game", 
'Anesthesia drug put on control list to halt abuse', 
"Chinese official slams Japan's nuke wastewater dumping", 
'Macron unveils new green plan for France']
"""

# 提取内容并输出
   for b_tag in b_tags:
       content = b_tag.text
       print(content)
       print(len(content))
       if len(content) > 45:
           # 句子太长 界面无法显示
           continue
       # print(content)
       list_senetcens.append(content)
   return list_senetcens

print("爬取的英文网页标题句子为%s"%(sentences))

你可能感兴趣的:(Python课程设计,游戏,python,Pygame,打字小游戏,大学生课设)