扫雷小游戏-python

本文分享了如何基于Python3.2实现扫雷小游戏。通过修改网上找到的demo,使用C++调用来运行,详细展示了相关代码实现过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在网上找了一个小demo,然后进行了修改,用C++调用来运行。直接贴代码(python3.2)。

注:

PyObject* PyObject_Call(PyObject *callable_object, PyObject *args, PyObject *kw) 
Return value: New reference.

Call a callable Python object callable_object, with arguments given by the tuple args, and named arguments given by the dictionary kw. If no named arguments are needed, kw may be NULL. args must not be NULL, use an empty tuple if no arguments are needed. Returns the result of the call on success, or NULL on failure. This is the equivalent of the Python expression callable_object(*args, **kw).

# -*- coding: utf-8 -*-
'''@author: Yeah_Man
   @version: 1.0
   @note: 实现扫雷游戏(2012-9-18)
          测试环境:python3.2.2
'''
import sys
import random
import string

class MineSweeping():
    '''扫雷主程序
    '''

    def __init__(self):
        '''初始化函式
        '''
        
        self.ROW = 8
        self.LINE = 8
        self.SCORE = 0 #扫雷得分
        self.MineNum = 15 #地雷总数
        self.xy_list= [[0,0,0,0,0,0,0,0],
                         [0,0,0,0,0,0,0,0],
                         [0,0,0,0,0,0,0,0],
                         [0,0,0,0,0,0,0,0],
                         [0,0,0,0,0,0,0,0],
                         [0,0,0,0,0,0,0,0],
                         [0,0,0,0,0,0,0,0],
                         [0,0,0,0,0,0,0,0]]
        
        
    def iniData(self):
        '''x,y坐标初始状态值函数
           0-没有地雷;1-有地雷
        '''
        
        #游戏开始前所有数值归零
        for l in range(self.LINE):
            for r in range(self.ROW):
                self.xy_list[l][r]= 0
        
        Max = self.MineNum
        fo
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值