Exemple #1
0
    //更新牆壁狀態
    public void UpdateNeighbours()
    {
        int x, y;

        //遍歷各牆壁
        for (int i = 1; i < 5; i++)
        {
            switch (i)
            {
            case 1:
                x = m_x;
                y = m_y + 1;
                break;

            case 2:
                x = m_x;
                y = m_y - 1;
                break;

            case 3:
                x = m_x - 1;
                y = m_y;
                break;

            case 4:
                x = m_x + 1;
                y = m_y;
                break;

            default:
                x = m_x;
                y = m_y;
                break;
            }

            //若牆壁位置在外圍則繼續下一牆壁位置
            if (x < 0 || x == m_maze.m_width ||
                y < 0 || y == m_maze.m_height)
            {
                continue;
            }

            //如果牆壁位置有物件則將狀態設為 1 = 未確定
            if (m_maze.HasCell(x, y))
            {
                m_neighbours[i] = 1;
            }
        }
    }
Exemple #2
0
    private void UpdateNeighbours()
    {
        for (int cnt = 1; cnt < Enum.GetNames(typeof(Direction)).Length; cnt++)
        {
            Vector2 direction = m_center + MazeUtils.DirectionToVector2((Direction)cnt);
            if (direction.x < 0 || direction.x == m_maze.Width ||
                direction.y < 0 || direction.y == m_maze.Height)
            {
                continue;
            }

            if (m_maze.HasCell((int)direction.x, (int)direction.y))
            {
                m_neighbours[(Direction)cnt] = NeighbourType.Visited;
            }
        }
    }