简体   繁体   中英

minesweeper setting values problem in python

I have to make minesweeper in python.. i have problem with the search inside the cellgame..the random mines are working but the number per

My Code

    #i search every shell for "nuke". When it finds it the perimeter became " 1 "
    def bottom(x,y):
        if table[x][y]=="nuke":
            table[x-1][y]=" 1  "
    def right(x,y):
        if table[x][y]=="nuke":
            table[x][y-1]=" 1  "
    def up(x,y):
        if table[x][y]=="nuke":
            table[x+1][y]=" 1  "
    def left(x,y):
        if table[x][y]=="nuke":
            table[x][y+1]=" 1  "






    #here I do the search
    for x in range(10):
        for y in range(10):
            if table[x][y]!="nuke":
                    if x==0:
                      #here is the up left corner
                        if y==0:
                            right(x,y+1)
                            bottom(x+1,y)
                      #here is the up right corner
                        if y==10 :
                            bottom(x+1,y)
                            left(x,y-1)
                        else:
                      #the rest up
                            right(x,y+1)
                            bottom(x+1,y)
                            left(x,y-1)
                    elif x==10:
                      #here is the bottom left corner
                        if y==0:
                            up(x-1,y)
                            right(x,y+1)
                      #here is the bottom right corner
                        elif y==10:
                            left(x,y-1)
                            up(x-1,y)
                        else:
                      #the rest bottom
                            right(x,y+1)
                            left(x,y-1)
                            up(x-1,y)
                      #the rest
                    else:
                        right(x,y+1)
                        bottom(x+1,y)
                        left(x,y-1)
                        up(x-1,y)

for i in table: print i

what my problem is: It's not working the part of searching and the count..do you have any idea about that?

#i change somethin to the end
#i search every shell for "nuke". When it finds it the perimeter became " 1 "
def bottom(x,y):
    if table[x][y]=="nuke":
        table[x-1][y]=" 1  "
def right(x,y):
    if table[x][y]=="nuke":
        table[x][y-1]=" 1  "
def up(x,y):
    if table[x][y]=="nuke":
        table[x+1][y]=" 1  "
def left(x,y):
    if table[x][y]=="nuke":
        table[x][y+1]=" 1  "






#here I do the search

for x in range(10): for y in range(10): if table[x][y]!="nuke": if x==0: #here is the up left corner if y==0: right(x,y-1) bottom(x+1,y) #here is the up right corner if y==10 : bottom(x+1,y) left(x,y-1) else: #the rest up right(x,y-1) bottom(x+1,y) left(x,y-1) elif x==10: #here is the bottom left corner if y==0: up(x-1,y) right(x,y+1) #here is the bottom right corner elif y==10: left(x,y-1) up(x-1,y) else: #the rest bottom right(x,y+1) left(x,y-1) up(x-1,y) #the rest else: right(x,y-1) bottom(x-1,y) left(x,y-1) up(x-1,y)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM