Example #1
0
    /// <summary>
    /// Creates a new Occupied array based on if a mino is dropped
    /// All params are optional, if any aren't used then the current mino/occupied is used
    /// </summary>
    /// <param name="position">Position to drop from, if null use current mino position</param>
    /// <param name="rotation">Rotation to drop from, if null use current mino rotation</param>
    /// <param name="type">Block to drop, if null use current mino block</param>
    /// <param name="occupied">Result from previous call, if null use board array</param>
    /// <returns></returns>
    public bool[,] TestDrop(Point position = null, Tetris.Rotation? rotation = null, MinoType type = null, bool[,] occupied = null)
    {
        if (position == null)
        {
            position = game.CurrentBlock.Position;
        }
        if (rotation == null)
        {
            rotation = game.CurrentBlock.Rotation;
        }
        if (type == null)
        {
            type = game.CurrentBlock.BlockType;
        }
        if (occupied == null)
        {
            occupied = Board.Occupied;
        }

        occupied = (bool[, ])occupied.Clone();

        while (IsValidPlacement(occupied, Mino.GetBlockLocations(type, position, (int)rotation)))
        {
            position.y++;
        }
        position.y--;
        if (IsValidPlacement(occupied, Mino.GetBlockLocations(type, position, (int)rotation)))
        {
            foreach (Point p in Mino.GetBlockLocations(type, position, (int)rotation))
            {
                if (p.y >= 0)
                {
                    occupied[p.y, p.x] = true;
                }
            }
        }
        return(occupied);
    }