Django-Vi中的递归

2024-09-20 23:02:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个扫雷游戏,我想用一个递归函数,当我点击一个空白的方块时,我会显示出许多方块。在

到目前为止我的视图.py公司名称:

def reveal(board_id, x, y):
        tile = Tile.objects.filter(board=board_id, x=x, y=y)
    if tile[0].revealed == False:
        tile.update(revealed=True)
        if tile[0].mine == False and tile[0].value == 0:
            if x != 0:
                tempx = x-1
                reveal(board_id, tempx, y)
            if x != 9:
                tempx = x+1
                reveal(board_id, tempx, y)
            if y != 0:
                tempy = y-1
                reveal(board_id, x, tempy)
            if y != 9:
                tempy = y+1
                reveal(board_id, x, tempy)

它给我一个服务器错误。在


Tags: pyboard视图idfalse游戏if空白
2条回答

x和y值是作为unicode字符传递的,所以当我试图添加或减去这些值时,它引发了一个异常。在

基本上

x = int(x)
y = int(y)

帮我解决了。在

我猜reveal()会一直走在已经显示的瓷砖上。在

if not tile[0].revealed and tile[0].mine == False and tile[0].value == 0:
    ....

相关问题 更多 >

    热门问题