-2
在嵌套的數組中,將用作網格有一個easir 檢查天氣的方法上下的地方都是空的或者是唯一的方法if,elsif聲明嵌套數組中的索引Ruby
即
if maze[i][j-1].to_i == index
maze[i][j-1] = ">"
#down
elsif maze[i+1][j].to_i == index
maze[i+1][j] = ">"
# UP
elsif maze[i-1][j].to_i == index
maze[i-1][j] = ">"
#right
elsif maze[i][j+1].to_i == index
maze[i][j+1] = ">"
end
發佈的代碼不完整。您還必須小心不要傳遞數組邊界。如果'j == 0','j-1'在數組外。 – axiac