猫史档案馆


[开源]橙软扫雷项目进度报告(α0.4)

用户:CoderorangesoftCoderorangesoft查看:1 回复:1 评论:1 创建时间:2022-05-22T11:01:46


若想下载相关的图片,请前往coderorangesoft.github.io/Orangesoft.github.io/(橙软官网),单击'开源项目'-‘扫雷’以下载。

import time
import random
import pgzrun
import os
'''
1.时间库
2.随机数库
3.pygame库
4.系统库
'''
# 导入库

print('______________________________________________________')
print('扫雷 版本α0.4 橙软制作')
print('______________________________________________________')
# 初始界面

print('''<公告>扫雷α 0.4 更新日志:
1.修复‘超出索引范围’
2.重写图标代码
''')
print('<程序>启动中,请稍候...')
blocks = [[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, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]
for i in range(9):
    defaultSweep = random.randint(0, 8)
    blocks[i][defaultSweep] = 9
while True:
    sweep = random.randint(0, 8)
    sweepI = random.randint(0, 8)
    if blocks[sweepI][sweep] == 9:
        continue
    else:
        blocks[sweepI][sweep] = 9
        break

print('<程序>启动完成!')
# 初始化雷区

HEIGHT = 450
WIDTH = 450
# 窗口绘制

back = Actor('back')
block = Actor('b0')
'''↓block的全部形态'''
b0 = Actor('b0')
b1 = Actor('b1')
b2 = Actor('b2')
b3 = Actor('b3')
b4 = Actor('b4')
sweep = Actor('boom')
# 绘制角色

def draw():
    screen.blit('back', [0, 0])
    for blocksPainter in range(9):
        for blocksPainter1 in range(9):
            if blocks[blocksPainter][blocksPainter1] == 9:
                block.y = blocksPainter * 50 + 25
                block.x = blocksPainter1 * 50 + 25
                block.image = 'boom'
                block.draw()
                #↑如果是雷
            else:
                aroundSweep = blocks#←周围雷数
                #↓渲染中间的方块
                if blocksPainter > 0 and blocksPainter < 8 and blocksPainter1 > 0 and blocksPainter1 < 8:
                    if blocks[blocksPainter][blocksPainter1] == 0:
                        if blocks[blocksPainter][blocksPainter1 - 1]== 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        if blocks[blocksPainter][blocksPainter1 + 1]== 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        if blocks[blocksPainter - 1][blocksPainter1 - 1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        if blocks[blocksPainter - 1][blocksPainter1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        if blocks[blocksPainter - 1][blocksPainter1 + 1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        if blocks[blocksPainter + 1][blocksPainter1 - 1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        if blocks[blocksPainter + 1][blocksPainter1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        if blocks[blocksPainter + 1][blocksPainter1 + 1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        block.y = blocksPainter * 50 + 25
                        block.x = blocksPainter1 * 50 + 25
                        block.image = 'b' + str(blocks[blocksPainter][blocksPainter1])
                        block.draw()
                #↓顶层方块渲染
                if blocksPainter == 0:
                    if blocksPainter1 == 0:
                        if blocks[blocksPainter][blocksPainter1 + 1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        if blocks[blocksPainter + 1][blocksPainter1 + 1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        if blocks[blocksPainter + 1][blocksPainter1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        block.y = blocksPainter * 50 + 25
                        block.x = blocksPainter1 * 50 + 25
                        block.image = 'b' + str(blocks[blocksPainter][blocksPainter1])
                        block.draw()
                    if blocksPainter1 > 0 and blocksPainter1 < 8:
                        if blocks[blocksPainter][blocksPainter1 + 1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        if blocks[blocksPainter + 1][blocksPainter1 + 1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        if blocks[blocksPainter + 1][blocksPainter1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        if blocks[blocksPainter][blocksPainter1 - 1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        block.y = blocksPainter * 50 + 25
                        block.x = blocksPainter1 * 50 + 25
                        block.image = 'b' + \
                            str(blocks[blocksPainter][blocksPainter1])
                        block.draw()
                    if blocksPainter1 == 8:
                        if blocks[blocksPainter][blocksPainter1 - 1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        if blocks[blocksPainter + 1][blocksPainter1 - 1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        if blocks[blocksPainter - 1][blocksPainter1] == 9:
                              aroundSweep[blocksPainter][blocksPainter1] += 1
                        block.y = blocksPainter * 50 + 25
                        block.x = blocksPainter1 * 50 + 25
                        block.image = 'b' + \
                            str(blocks[blocksPainter][blocksPainter1])
                        block.draw()
                #↓底层方块渲染
                if blocksPainter == 8:
                    if blocksPainter1 == 0:
                        if blocks[blocksPainter][blocksPainter1 + 1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        if blocks[blocksPainter - 1][blocksPainter1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        if blocks[blocksPainter - 1][blocksPainter1 + 1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        block.y = blocksPainter * 50 + 25
                        block.x = blocksPainter1 * 50 + 25
                        block.image = 'b' + \
                            str(blocks[blocksPainter][blocksPainter1])
                        block.draw()
                    if blocksPainter1 > 0 and blocksPainter1 < 8:
                        if blocks[blocksPainter][blocksPainter1 - 1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        if blocks[blocksPainter - 1][blocksPainter1 - 1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        if blocks[blocksPainter - 1][blocksPainter1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        if blocks[blocksPainter][blocksPainter1 + 1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        block.y = blocksPainter * 50 + 25
                        block.x = blocksPainter1 * 50 + 25
                        block.image = 'b' + \
                            str(blocks[blocksPainter][blocksPainter1])
                        block.draw()
                    if blocksPainter1 == 8:
                        if blocks[blocksPainter][blocksPainter1 - 1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        if blocks[blocksPainter - 1][blocksPainter1 - 1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        if blocks[blocksPainter - 1][blocksPainter1] == 9:
                            aroundSweep[blocksPainter][blocksPainter1] += 1
                        block.y = blocksPainter * 50 + 25
                        block.x = blocksPainter1 * 50 + 25
                        block.image = 'b' + \
                            str(blocks[blocksPainter][blocksPainter1])
                        block.draw()
                    #↑如果不是雷

#调试驱动
def debug1():
    Debug_sweepCount = 0
    for Debug1_blocksMiner in blocks:
        for Debug1_blocksMiner1 in Debug1_blocksMiner:
            if Debug1_blocksMiner1 == 9:
                Debug_sweepCount += 1
    print('<调试>:blocks:')
    print('<调试>:',blocks)
    print('<调试>:blocks共有',len(blocks),'个数据包(81项),其中有',Debug_sweepCount,'项的值是‘9’')

# 调试
# 选择你想调试的内容,然后删去‘#’,即可启用该内容。
'''↓调试功能1:查看雷分布的位置(blocks列表)'''
debug1()

pgzrun.go()


回复

上一页1 页 / 共 1下一页
上知天文上知天文

wc!

点赞0


评论