![](https://csdnimg.cn/release/download_crawler_static/89359244/bg1.jpg)
介绍:
一个扫雷游戏,但是不如原版;
借助 Excel 实现:
所依赖文件特别多:
最重要的原理图
![](https://csdnimg.cn/release/download_crawler_static/89359244/bg2.jpg)
对 Python 的要求:
运行效果
![](https://csdnimg.cn/release/download_crawler_static/89359244/bg3.jpg)
代码
import itertools
import time
import pygame
import sys
import random
import numpy as np
import pandas as pd
import tkinter.messagebox
# import os
tkinter.messagebox.showinfo(title='祝您游戏愉快!', message='是否要开始
游戏?\n\n\n\n 单击\"确定\"或\"X\"以继续')
![](https://csdnimg.cn/release/download_crawler_static/89359244/bg4.jpg)
# def load_file():
# # 获取当前文件路径
# current_path = os.path.abspath(__file__)
# # 获取当前文件的父目录
# father_path = os.path.abspath(os.path.dirname(current_path) +
os.path.sep + ".")
# # config.ini 文件路径,获取当前目录的父目录的父目录与 congig.ini 拼接
# config_file_path =
os.path.join(os.path.abspath(os.path.dirname(current_path) + os.path.sep
+ ".."), 'config.ini')
# return father_path
#
#
# f_path = load_file()
# 有 print 的地方或为检查点,不必在意。当然,您也可以打开这些检查点检
查检查
study_place = 'https://geek-docs.com/pygame/pygame-
questions/478_pygame_getting_monitor_size_in_python.html'
# 获取数据
target_excel = pd.read_excel('.\\game_setting.xlsx', index_col=None,
header=None)
the_excel = target_excel.to_numpy()
# print(the_excel[0, 0], type(the_excel[0, 0]))
global standard_positions, lists_random, x_num, y_num, dang_num
# standard_positions = [0, 1, 2, 3, 4] # 存放标准位置
# used_positions = [0, 1, 2, 3, 4] # 存放使用过的位置
# lists_random = [a, b]
![](https://csdnimg.cn/release/download_crawler_static/89359244/bg5.jpg)
# x_num, y_num, dang_num = 0, 0, 0
if np.isnan(the_excel[0, 0]): #判断第一个格子是否为空
x_num = the_excel[1, 7]
y_num = the_excel[2, 7]
dang_num = the_excel[3, 7]
elif the_excel[0, 0] == 1:
x_num, y_num, dang_num = 9, 9, 10
elif the_excel[0, 0] == 2:
x_num, y_num, dang_num = 16, 16, 40
elif the_excel[0, 0] == 3:
x_num, y_num, dang_num = 30, 16, 100
elif the_excel[0, 0] == 4:
x_num, y_num, dang_num = 39, 21, 120
# 验证数据
# print(x_num, y_num, dang_num)
if np.isnan(x_num) or np.isnan(y_num) or np.isnan(dang_num): #是否为空
tkinter.messagebox.showerror(title='Error!', message='您可能未输入数据
于表格中!\n 或者 您未将数据输入正确位置!')
sys.exit()
# 生成基本位置
def standard_position(a, b):
c = []
for i in range(a):
c.append([])