• 【Python游戏】用Python实现一个测试你智商的小游戏——24点,过不了三关的都是细狗 | 附带源码


    前言

    好咯,包子们下午好
    今天小编主要是过来测试一下大家的智商,没别的意思,不是看不起大家,我感觉今天实现的小游戏,可能大家真的过不了三关!
    哈哈哈,废话不多说吧
    直接开始我们的游戏实现功能

    相关文件

    关注小编,私信小编领取哟!
    当然别忘了一件三连哟~~
    Python日志

    开发工具

    Python版本:3.7.8
    相关模块:
    pygame模块;
    random模块;
    pyttsx3模块;
    以及一些python自带的模块。

    环境搭建

    安装Python并添加到环境变量,pip安装需要的相关模块即可。

    效果展示

    在这里插入图片描述
    在这里插入图片描述

    代码实现

    导入模块

    import os
    import sys
    import pygame
    from cfg import *
    from modules import *
    from fractions import Fraction
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    检查控件是否被点击

    def checkClicked(group, mouse_pos, group_type='NUMBER'):
        selected = []
        # 数字卡片/运算符卡片
        if group_type == GROUPTYPES[0] or group_type == GROUPTYPES[1]:
            max_selected = 2 if group_type == GROUPTYPES[0] else 1
            num_selected = 0
            for each in group:
                num_selected += int(each.is_selected)
            for each in group:
                if each.rect.collidepoint(mouse_pos):
                    if each.is_selected:
                        each.is_selected = not each.is_selected
                        num_selected -= 1
                        each.select_order = None
                    else:
                        if num_selected < max_selected:
                            each.is_selected = not each.is_selected
                            num_selected += 1
                            each.select_order = str(num_selected)
                if each.is_selected:
                    selected.append(each.attribute)
        # 按钮卡片
        elif group_type == GROUPTYPES[2]:
            for each in group:
                if each.rect.collidepoint(mouse_pos):
                    each.is_selected = True
                    selected.append(each.attribute)
        # 抛出异常
        else:
            raise ValueError('checkClicked.group_type unsupport %s, expect %s, %s or %s...' % (group_type, *GROUPTYPES))
        
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
  • 相关阅读:
    OSEP 考试总结
    周亚军 红宝书 案例 3 SSH远程管理协议
    JavaScript --Set对象及常用方法总结
    网络安全笔记 -- 文件操作(文件下载读取)
    2.2并发三大特性可见性、原子性、有序性
    容器的通俗讲解
    《会计信息系统》课程期末复习题与参考答案
    LeetCode热题100——图论
    消除过期的对象引用
    海象赋值表达式减少重复变量
  • 原文地址:https://blog.csdn.net/Gtieguo/article/details/128148253