Beispiel #1
0
 internal bool Drop(IBlockArea blockArea)
 {
     var newPos = new Point(Position.X, Position.Y + 1);
     if (!IsValidDropPoint(newPos, blockArea))
         return false;
     Position = new Point(newPos.X, newPos.Y);
     return true;
 }
Beispiel #2
0
        internal bool Move(Direction direction, IBlockArea blockArea)
        {
            if (direction != Direction.Right && direction != Direction.Left)
                throw new ArgumentException("Only left and right directions are supported", "direction");

            int shift = direction == Direction.Right ? 1 : -1;
            var newPos = new Point(Position.X + shift, Position.Y);
            for (int x = 0; x < Size; x++)
                for (int y = 0; y < Size; y++)
                    if (_blocks[x, y] != null &&
                        (x + newPos.X >= Constants.BlockAreaSizeX || x + newPos.X < 0 || blockArea.IsOccupied(x + newPos.X, y + newPos.Y)))
                        return false;
            Position = new Point(newPos.X, newPos.Y);
            return true;
        }
Beispiel #3
0
 internal bool IsValidDropPoint(Point position, IBlockArea blockArea)
 {
     for (int x = 0; x < Size; x++)
         for (int y = 0; y < Size; y++)
             if (_blocks[x, y] != null &&
                 (y + position.Y >= Constants.BlockAreaSizeY || blockArea.IsOccupied(x + position.X, y + position.Y)))
                 return false;
     return true;
 }
Beispiel #4
0
        // Rotation algorithm from Stackoverflow
        internal bool Rotate(Direction direction, IBlockArea blockArea)
        {
            if (direction != Direction.Right && direction != Direction.Left)
                throw new ArgumentException("Only left and right directions are supported", "direction");

            if (Position.Y < 0)
                return false;

            var newBlocks = new Block[Size,Size];

            if (direction == Direction.Left)
                for (int x = 0; x < Size; ++x)
                    for (int y = 0; y < Size; y++)
                        newBlocks[x, y] = _blocks[Size - y - 1, x];
            else // direction == Direction.Right
                for (int x = 0; x < Size; ++x)
                    for (int y = 0; y < Size; y++)
                        newBlocks[x, y] = _blocks[y, Size - x - 1];

            for (int x = 0; x < Size; x++)
                for (int y = 0; y < Size; y++)
                    if (newBlocks[x, y] != null && blockArea.IsOccupied(x + Position.X, y + Position.Y))
                        return false;

            _blocks = newBlocks;

            return true;
        }