Exemplo n.º 1
0
    // Add a new row to the map. If n is positive, then we add to the bottom, otherwise to the top;
    private void AddMapRow(int n)
    {
        CellComponent[,] tempMap = new CellComponent[this.row + Mathf.Abs(n), col];
        int tempRow = tempMap.GetUpperBound(0) + 1;
        int tempCol = tempMap.GetUpperBound(1) + 1;

        if (n < 0)
        {
            for (int i = 0; i < tempRow; i++)
            {
                for (int j = 0; j < tempCol; j++)
                {
                    if (i < -n)
                    {
                        tempMap[i, j] = new CellComponent();
                    }
                    else
                    {
                        tempMap[i, j] = this.elementMap[i + n, j];
                    }
                }
            }

            // update the player's coordinate
            this.playerRow -= n;
        }
        else
        {
            for (int i = 0; i < tempRow; i++)
            {
                for (int j = 0; j < tempCol; j++)
                {
                    if (i < this.row)
                    {
                        tempMap[i, j] = this.elementMap[i, j];
                    }
                    else
                    {
                        tempMap[i, j] = new CellComponent();
                    }
                }
            }
        }

        this.elementMap = tempMap;
        this.row       += Mathf.Abs(n);
    }
Exemplo n.º 2
0
    // Add a new column to the map. If n is positive, then we add to the right, otherwise to the left;
    private void AddMapColunm(int n)
    {
        CellComponent[,] tempMap = new CellComponent[this.row, this.col + Mathf.Abs(n)];
        int tempRow = tempMap.GetUpperBound(0) + 1;
        int tempCol = tempMap.GetUpperBound(1) + 1;

        if (n < 0)
        {
            for (int i = 0; i < tempRow; i++)
            {
                for (int j = 0; j < tempCol; j++)
                {
                    if (j < -n)
                    {
                        tempMap[i, j] = new CellComponent();
                    }
                    else
                    {
                        tempMap[i, j] = this.elementMap[i, j + n];
                    }
                }
            }
            // update the player's coordinate
            this.playerCol -= n;
        }
        else
        {
            for (int i = 0; i < tempRow; i++)
            {
                for (int j = 0; j < tempCol; j++)
                {
                    if (j >= this.col)
                    {
                        tempMap[i, j] = new CellComponent();
                    }
                    else
                    {
                        tempMap[i, j] = this.elementMap[i, j];
                    }
                }
            }
        }

        this.elementMap = tempMap;
        this.col       += Mathf.Abs(n);
    }