在网上找了一个小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):

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

被折叠的 条评论
为什么被折叠?



