• 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. 联系请加V:zew1040994588
    2. 源码获取、定制咨询、非开源
    3. while running:
    4. screen.fill(BG_COLOR)
    5. for event in pygame.event.get():
    6. print("event.type值为%s"%(event.type))
    7. if event.type == pygame.QUIT:
    8. running = False
    9. # 恩-23-9-28-停止程序
    10. exit()
    11. elif event.type == pygame.KEYDOWN:
    12. if game_state == State.MENU:
    13. if event.key == pygame.K_p:
    14. game_state = State.GAME
    15. # 从可迭代对象里面挑一个,这里业务逻辑为从句子列表中任意挑一个
    16. sentence = random.choice(sentences)
    17. print("sentence内容为%s"%(sentence))
    18. start_time = time.time()
    19. user_input = ""
    20. elif event.key == pygame.K_s:
    21. game_state = State.SCORES
    22. # 成就页面监测按键A
    23. elif event.key == pygame.K_a:
    24. game_state = State.ACIEVEMENT
    25. elif event.key == pygame.K_q:
    26. running = False
    27. elif game_state == State.GAME:
    28. print("pygame.K_BACKSPACE值为%s"%(pygame.K_BACKSPACE))
    29. print("event.key值为%s"%(event.key))
    30. if event.key == pygame.K_RETURN:
    31. wpm = len(sentence) / 5 / (time.time() - start_time) * 60
    32. accuracy = check_input(
    33. user_input, sentence) / len(sentence) * 100
    34. score = wpm * accuracy / 100
    35. insert_score(wpm, accuracy, score)
    36. # Update the latest score
    37. latest_score = (wpm, accuracy, score)
    38. game_state = State.SCORES
    1. 联系请加V:zew1040994588
    2. 源码获取、定制咨询、非开源
    3. """
    4. 23-9-26爬取的内容为:
    5. '5th International Daoism Forum opens in Jiangsu',
    6. "China's tourism market speeds up recovery",
    7. 'US factor emerges in India-Canada row',
    8. 'China gets to grips with cricket',
    9. "China's tourism market speeds up recovery",
    10. 'US factor emerges in India-Canada row',
    11. 'Thailand rolls out carpet to woo travelers',
    12. 'Trump takes opposite view of McCarthy on shutdown']
    13. """
    14. """
    15. 23-9-27爬取的内容为:
    16. ['Economic uptick anticipated',
    17. "Tech hegemony name of NSA's game",
    18. 'Anesthesia drug put on control list to halt abuse',
    19. 'Legend wows Hangzhou Asiad at 48', "Tech hegemony name of NSA's game",
    20. 'Anesthesia drug put on control list to halt abuse',
    21. "Chinese official slams Japan's nuke wastewater dumping",
    22. 'Macron unveils new green plan for France']
    23. """
    24. # 提取内容并输出
    25. for b_tag in b_tags:
    26. content = b_tag.text
    27. print(content)
    28. print(len(content))
    29. if len(content) > 45:
    30. # 句子太长 界面无法显示
    31. continue
    32. # print(content)
    33. list_senetcens.append(content)
    34. return list_senetcens
    35. print("爬取的英文网页标题句子为%s"%(sentences))

    源码获取

    欢迎大家点赞、收藏、关注、评论、批评啦 、查看👇🏻👇🏻获取联系方式👇🏻👇🏻

  • 相关阅读:
    基于Win11、CentOS7、VMWare15pro搭建Hadoop2.7.7
    wordpress 安装主题显示要配置FTP的解决办法
    Java集合框架最全详解(看这篇就够了)
    【Java 基础篇】Java 自动装箱与拆箱:优雅处理基本数据类型与包装类的转换
    网络连接错误错误代码103怎么解决
    工具推荐-使用RedisInsight工具对Redis集群CURD操作及数据可视化和性能监控
    (二)kafka从入门到精通之kafka的优势
    运筹帷幄决胜千里,Python3.10原生协程asyncio工业级真实协程异步消费任务调度实践
    c++1237. 找出给定方程的正整数解,四种解法(二分+有限状态机)
    如何确保面试流程标准化操作,避免人为因素影响**
  • 原文地址:https://blog.csdn.net/Elephantpretty/article/details/133741237