Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Python的Minewsweeper中的每行之间添加行_Python_Game Development - Fatal编程技术网

如何在Python的Minewsweeper中的每行之间添加行

如何在Python的Minewsweeper中的每行之间添加行,python,game-development,Python,Game Development,我是一名在澳大利亚学习数字电子学的学生,我不知道如何在每行之间画线。(我可以使用列,但不能使用行) 我还发现了其他几个问题,例如 1.玩家可以欺骗倒计时, 通过反复输入相同的安全坐标。 2.如果玩家输入的数字超出游戏范围,游戏将崩溃 板范围 3.还有一个小问题,我不能标记任何 炸弹,因为这样做所需的功能是 我无法理解,尽管我确信 我可以用更多的时间(即几个月)完成, 代码不允许这样做,我只好到此为止 4.还有一个你不知道的小问题 在Windows上玩扫雷游戏 事实是你在第一次转弯时就死了。它是

我是一名在澳大利亚学习数字电子学的学生,我不知道如何在每行之间画线。(我可以使用列,但不能使用行)

我还发现了其他几个问题,例如 1.玩家可以欺骗倒计时, 通过反复输入相同的安全坐标。 2.如果玩家输入的数字超出游戏范围,游戏将崩溃 板范围 3.还有一个小问题,我不能标记任何 炸弹,因为这样做所需的功能是 我无法理解,尽管我确信 我可以用更多的时间(即几个月)完成, 代码不允许这样做,我只好到此为止 4.还有一个你不知道的小问题 在Windows上玩扫雷游戏 事实是你在第一次转弯时就死了。它是 常规比赛不可能做到这一点

提前谢谢

是否有任何方法可以添加标记功能,或者有什么方法可以显示丢失的棋盘?

# Matthew
# Simple Minesweeper - but not so simple anymore
# Version 3.0
# 20/9/17 - 25/10/17

from random import randint      # so there is a random mine placement
import time     # so I can delay the game
import sys      # so I can quit the game at any time`enter code here`

# Starts the loop for the game
play = True
while play == True:

    ##############################
    #### Functions Start Here ####
    ##############################

    # opens the board for use
    board = [] 

    # opens the mines list, currently empty so it can be altered later. 
    mines = []

    # determines the rows on the board
    board_row = 0

    # determines the adjacent mines
    adj = 0

    # sets a variable to be used later in the check_ans() function
    wrong = 0

    #determines the amount of rows on the board
    while True:
        board_row = int(input("For a square board, how many rows and columns? (5 min, 10 max):"))
        if board_row > 10:
            print("That is too high. Please enter another!")
        elif board_row < 5:
            print("That is too small. Please enter another!")
        else:
            break

    # adds mines for a larger board
    if board_row >= 8:
        for i in range(15):
            mines.append([randint(0,board_row-1), randint(0, board_row-1)])

    # adds smaller mines for a smaller board
    elif board_row >= 5:
        for i in range(10):
            mines.append([randint(0,board_row-1), randint(0, board_row-1)])

    # creates rows
    for i in range(board_row):
        board.append(["x"] * board_row)

    # creates the rows
    def draw_board(board):
        for i in board:
            print("|".join(i))

    # check the answers
    def check_ans():
        if row >= board_row or col >= board_row:
            print("That number is too high. The order goes 0 to ", board_row)
            wrong = 1
        else:
            wrong = 0      

    # defines the adjacent mines, by checking each of the surrounding squares, one
    # by one
    def adj_mines(r, c, adj):
        adj = 0
        if [r+1, c] in mines:
            adj += 1
        if [r+1, c+1] in mines:
            adj += 1
        if [r+1, c-1] in mines:
            adj += 1
        if [r, c+1] in mines:
            adj += 1
        if [r, c-1] in mines:
            adj += 1
        if [r-1, c+1] in mines:
            adj += 1
        if [r-1, c] in mines:
            adj += 1
        if [r-1, c-1] in mines:
            adj += 1
        return adj

    def Intro_to_game():
        print('Hello. This is a game of Minesweeper - with a twist!')
        print('You cannot flag any bombs, because I can\'t figure out how to do that...')
        print('On each turn, select the row or column that you wish to ')
        print('disarm, and this program will do it. To let you know how')
        print('many tiles you have left to disarm, there will be a ')
        print('countdown before each turn. Enjoy, and good luck!')

    # defines number of moves required to beat the game, as
    # there is no flagging function. 
    moves = (((board_row) * (board_row) - int(len(mines))))


    ##################################
    #### Main Program Starts Here ####
    ##################################

    draw_board(board)

    # This uses a function to determine how many cells are left to
    # clear the board, as there is no way to flag. This makes the
    # game significantly harder, as you have to keep track in your
    # head of where the bombs are. 
    Intro_to_game()
    while True:
        print('===================================')
        print("Cells to clear: " + str(moves))

        # This part enters in the rows and columns. However, although
        # the lists typically start at 0, the program has to subtract
        # one from the different imputs to put them in the right place

        row = (int(input("Row: ")) - 1)

        # This part doesn't allow the player to enter
        # a number that is higher than the board range
        while row >= board_row + 1:
            print('That is not in the board range')
            row = (int(input("Row: ")) -1) 

        col = (int(input("Col: ")) - 1)

        # This part doesn't allow the player to enter
        # a number that is higher than the board range

        while col >= board_row + 1:
            print('That is not in the board range')
            col = (int(input("Col: ")) -1)              

        # checks to see if there is a bomb in the called field, if not,
        # then it repeats. If there is a bomb, it shows, "Sorry, but you
        # have blown up." Then it asks if they player would like to play
        # again. 
        check_ans()

        if wrong != 1:
            if [row, col] in mines:
                break

            else:
                board[row][col] = str(adj_mines(row,col,0))
                moves = moves - 1
        draw_board(board)
        if moves == 0:
            print("You have won!")
            time.sleep(2)
            sys.exit

    print("Sorry, but you have blown up :(")

    # draws the board again each time. 
    draw_board(board)

    # Although unconventional, this little bit processes the
    # request to play again. If yes, it breaks the loop, and
    # goes back to the start. If no, sys.exit quits the game

    print("Would you like to play again? (Yes or No)(Needs Capitals)")
    play_again = input()
    if play_again == 'Yes':
        continue
    if play_again == 'Y':
        continue
    if play_again == 'yes':
        continue
    if play_again == 'y':
        continue
    else:
        sys.exit()
#Matthew
#简单的扫雷艇——但不再那么简单了
#版本3.0
# 20/9/17 - 25/10/17
从random import randint#中,有一个随机地雷放置
输入时间,这样我可以推迟比赛
导入系统#以便我可以随时退出游戏`在此处输入代码`
#开始游戏的循环
播放=正确
当播放=真时:
##############################
####功能从这里开始####
##############################
#打开电路板以供使用
董事会=[]
#打开当前为空的地雷列表,以便以后可以对其进行更改。
地雷=[]
#确定板上的行
线路板排=0
#确定相邻矿山
adj=0
#设置稍后在check_ans()函数中使用的变量
错误=0
#确定板上的行数
尽管如此:
board_row=int(输入(“对于方形板,有多少行和多少列?(5分钟,10分钟):”)
如果线路板排>10:
打印(“太高了。请输入另一个!”)
elif board_row<5:
打印(“太小了。请输入另一个!”)
其他:
打破
#为更大的板添加地雷
如果board_row>=8:
对于范围(15)内的i:
矿山。追加([randint(0,董事会第1行),randint(0,董事会第1行)])
#为较小的板添加较小的地雷
elif board_row>=5:
对于范围(10)内的i:
矿山。追加([randint(0,董事会第1行),randint(0,董事会第1行)])
#创建行
对于范围内的i(板排):
board.append([“x”]*board_行)
#创建行
def牵引板(板):
我在董事会:
打印(“|”。连接(i))
#核对答案
def check_ans():
如果行>=线路板行或列>=线路板行:
打印(“该数字太高。订单为0至”,board_行)
错误=1
其他:
错误=0
#通过检查周围的每个正方形,定义相邻的矿山,一个
#一个
定义调整(r、c、调整):
adj=0
如果[r+1,c]在矿井中:
adj+=1
如果[r+1,c+1]在矿井中:
adj+=1
如果[r+1,c-1]在矿井中:
adj+=1
如果[r,c+1]在矿井中:
adj+=1
如果[r,c-1]在矿井中:
adj+=1
如果[r-1,c+1]在矿井中:
adj+=1
如果[r-1,c]在矿井中:
adj+=1
如果[r-1,c-1]在矿井中:
adj+=1
返回
def游戏介绍():
print('你好,这是一个扫雷游戏-有一个转折点!')
打印('你不能标记任何炸弹,因为我不知道怎么做…')
打印('在每个回合中,选择要打印的行或列')
打印('解除武装,此程序将执行此操作。让您知道如何解除武装')
打印('您要解除防护的瓷砖数量较多,将出现')
打印('每回合前倒计时。祝您好运,祝您愉快!')
#定义击败游戏所需的移动次数,如下所示
#没有标记功能。
移动=((板排)*(板排)-int(列(地雷)))
##################################
####主程序从这里开始####
##################################
绘图板(板)
#它使用一个函数来确定剩余的单元格数量
#清除棋盘,因为无法标记。这使得
#游戏要难得多,因为你必须在游戏中保持跟踪
#炸弹在哪里的头。
游戏介绍()
尽管如此:
打印('=======================================================')
打印(“要清除的单元格:+str(移动))
#此部分在行和列中输入。然而,尽管
#列表通常从0开始,程序必须减去
#从不同的输入中选择一个,将它们放在正确的位置
行=(int(输入(“行:”)-1)
#此部件不允许玩家进入
#高于电路板范围的数字
当行>=线路板行+1时:
打印('不在线路板范围内')
行=(int(输入(“行:”)-1)
列=(int(输入(“列:”)-1)
#此部件不允许玩家进入
#高于电路板范围的数字
当列>=线路板行+1时:
打印('不在线路板范围内')
列=(int(输入(“列:”)-1)
#检查呼叫区域是否有炸弹,如果没有,
#然后它重复。如果有炸弹,它会显示“对不起,但是你
#然后它问玩家是否愿意玩
#再说一遍。
核对
如果错了!=1:
如果[行,列]在矿井中:
打破
其他:
板[行][col]=str(调整矿山(行,列,0))
移动=移动-1
绘图板(板)
如果移动=0:
打印(“你
2|x|x|x|x
x|x|x|x|x
x|x|x|x|x
x|x|x|x|x
x|x|x|x|x
print("|".join(i))
print("-" * (board_row*2-1)) # add this line
x|x|x|x|x
---------
x|x|x|x|x
---------
x|x|x|x|x
---------
x|x|x|x|x
---------
x|x|x|x|x
---------