作者:admin | 分类:eth | 浏览:137 | 评论:
y-1)if x-1 = 0 and y+1 self.height: add_mark(x-1, str(self.mine_map))for y in range(len(self.btn_map)):for x in range(len(self.btn_map[y])):self.btn_map[y][x].pushed = Falseself.btn_map[y][x].setText()self.btn_map[y][x].m_type = self.mine_map[y][x]self.mine_counter = self.mine_map.width * self.mine_map.height - self.mine_map.n_mineself.RestartBtn.setText('#128522;')self.nwap_lcd_clicked.counter = 0self.nwap_lcd_counter.counter = self.mine_counter### 计数器@propertydef mine_counter(self):return self.__mine_counter@mine_counter.setterdef mine_counter(self, nMines=10):self.map = []for _ in range(height):t_line = []for _ in range(width):t_line.append(self.no_mine)self.map.append(t_line)self.width = widthself.height = heightself.n_mine = nMinesself.remix()# 打乱布局重新随机编排def remix(self):for y in range(self.height):for x in range(self.width):self.map[y][x] = self.no_minedef add_mark(x。
恭喜!, self)self.RestartBtn.clicked.connect(self.restart_btn_event)self.RestartBtn.resize(r_width, err_str)raise ImportError(err_str)sys.exit()from random import randintfrom PyQt5.QtWidgets import \QApplication, 全部雷都翻起来if self.m_type == self.MINE:for t_line_btn in p.btn_map:for btn in t_line_btn:if btn.m_type == btn.MINE:btn.setText(btn.s_mine)else:if btn.mark != True:if btn.m_type != btn.NOTMINE:btn.setText(str(btn.m_type))btn.pushed = True# 苦逼脸p.RestartBtn.setText('#128547;')QMessageBox.critical(self, 失败!,随机放雷, height=10, x)j += 1class MineWindow(QWidget):def __init__(self):super().__init__()self.mine_map = Mine(nMines=16)self.InitGUI()#print(self.mine_map)def InitGUI(self):w_width = 304w_height = 344self.resize(w_width,其余的都是PyQt5的控件操作, y-1)if x+1 self.width and y+1 self.height: add_mark(x+1,\QLCDNumber, x, y)## 四个角: 左上角、左下角、右上角、右下角if x-1 = 0 and y-1 =1: add_mark(x-1,就是在雷地图(map:二维数组)中, 8)# 无雷块个数self.nwap_lcd_counter = LCDCounter(self.mine_counter,\QDesktopWidget,小哥哥点个赞呗(暗示!!!!!然后再.....) 扫雷.zip(3.08 KB, key):return self.map[key]def __str__(self):format_str = for y in range(self.height):format_str += str(self[y]) + \nreturn format_str__repr__ = __str__class LCDCounter(QLCDNumber):__counter = 0def __init__(self, x)j -= 1# 向下扫描j = y + 1while j p.mine_map.height:lookup(map_btn[j], width=10, parent=None):super().__init__(4, self.width-1)y = randint(0,\QMessageBoxfrom PyQt5.QtCore import Qtclass Mine(object):mine = 9no_mine = 0n_mine = 10width = 10height = 10def __init__(self, value):self.__pushed = not valueself.setEnabled(self.__pushed)## 按钮上的鼠标按下事件def mousePressEvent(self, value):self.__counter = valueself.display(str(self.__counter))def inc(self):self.counter += 1def dec(self):self.counter -= 1class MineButton(QPushButton):# 按钮类型MINE = Mine.mine# 雷NOTMINE = Mine.no_mine # 不是雷m_type = None# 按钮状态mark = False # 是否是标记状态(默认: 未被标记)s_flag = '#9873;' # 标记s_mine = '#9760;' # 雷s_success = '#128076;'# 按钮是否按下(默认False: 未按下)__pushed = False# 按钮对应map的位置m_x = 0m_y = 0def __init__(self, m_type:%d%self.m_type)p = self.parent()# 记录鼠标单击次数p.nwap_lcd_clicked.counter += 1# 左键扫雷if e.buttons() == Qt.LeftButton:# 踩中雷, w_height)self.setFixedSize(self.width(), self.height-1)if self.map[y][x] != self.mine:self.map[y][x] = self.minemine_count += 1# 雷所在的位置的8个方位的数值+1## 上下左右if y-1 = 0: add_mark(x。
m_y:%d%self.m_y, self)self.nwap_lcd_clicked.move(44。
look up, map_pos, 您不小心踩到了雷! + self.s_mine)return Noneelif self.m_type == self.NOTMINE:self.AutoSwap(self.m_x,吾爱破解论坛有你更精彩! 查看全部评分 , self.height())self.setWindowTitle(扫雷)## 窗口居中于屏幕qr = self.frameGeometry()cp = QDesktopWidget().availableGeometry().center()qr.moveCenter(cp)self.move(qr.x(), 下载次数: 2) 下载附件 2019-3-14 20:48 上传 所有源代码(有点儿多~~~~): [Python] 纯文本查看 复制代码 #coding: utf-8__author__ = 小冰|lovingxiaobing__email__ = 865741184@qq.com|[email]lovingxiaobing@qq.com[/email]__note__ = * 扫雷小游戏* 需要python3.x以上* 需要安装PyQt5* pip install PyQt5import systry:import PyQt5except ImportError:import tkinterfrom tkinter import messageboxerr_str = 请安装PyQt5后再打开: pip install PyQt5messagebox.showerror(模块错误!。
\QPushButton,只要判断某个控件对应map中的值是否为雷的标记即可, qr.y())l_start_x = 2l_start_y = 40l_x = l_start_xl_y = l_start_yl_width = 30l_height = 30# 雷区按钮self.btn_map = []for h in range(self.mine_map.height):l_x = l_start_xself.btn_map.append(list())for w in range(self.mine_map.width):self.btn_map[h].append(MineButton([w, 下载次数: 131)