利用python的GUI界面简单实现扫雷游戏
# -*- coding: utf-8 -*-
import random
import sys
from Tkinter import *
'''
GUI界面的简单应用
'''
class Model:
"""
核心数据类,维护一个矩阵
"""
def __init__(self,row,col):
self.width=col
self.height=row
self.items=[[0 for c in range(col)] for r in range(row)]
def setItemValue(self,r,c,value):
"""
设置某个位置的值为value
"""
self.items[r][c]=value;
def checkValue(self,r,c,value):
"""
检测某个位置的值是否为value
"""
if self.items[r][c]!=-1 and self.items[r][c]==value:
self.items[r][c]=-1 #已经检测过
return True
else:
return False
def countValue(self,r,c,value):
"""
统计某个位置周围8个位置中,值为value的个数
"""
count=0
if r-1>=0 and c-1>=0:
if self.items[r-1][c-1]==1:count+=1
if r-1>=0 and c>=0:
if self.items[r-1][c]==1:count