Beispiel #1
0
        private Point GetNextPoint(Point myPosition, Interface.Direction absoluteDirection)
        {
            switch (absoluteDirection)
            {
            case Interface.Direction.Top:
                return(new Point(myPosition.X, myPosition.Y - 1));

            case Interface.Direction.TopRight:
                return(new Point(myPosition.X + 1, myPosition.Y - 1));

            case Interface.Direction.Right:
                return(new Point(myPosition.X + 1, myPosition.Y));

            case Interface.Direction.BottomRight:
                return(new Point(myPosition.X + 1, myPosition.Y + 1));

            case Interface.Direction.Bottom:
                return(new Point(myPosition.X, myPosition.Y + 1));

            case Interface.Direction.BottomLeft:
                return(new Point(myPosition.X - 1, myPosition.Y + 1));

            case Interface.Direction.Left:
                return(new Point(myPosition.X - 1, myPosition.Y));

            case Interface.Direction.TopLeft:
                return(new Point(myPosition.X - 1, myPosition.Y - 1));
            }
            throw new InvalidProgramException("uuu");
        }
Beispiel #2
0
        private bool IsCrossColision(Point newPosition, Interface.Direction direction)
        {
            switch (direction)
            {
            case Interface.Direction.TopRight: return((_currentSurrond[newPosition.X, newPosition.Y + 1] != 0) && (_currentSurrond[newPosition.X - 1, newPosition.Y] != 0));

            case Interface.Direction.BottomRight: return((_currentSurrond[newPosition.X, newPosition.Y - 1] != 0) && (_currentSurrond[newPosition.X - 1, newPosition.Y] != 0));

            case Interface.Direction.BottomLeft: return((_currentSurrond[newPosition.X, newPosition.Y - 1] != 0) && (_currentSurrond[newPosition.X + 1, newPosition.Y] != 0));

            case Interface.Direction.TopLeft: return((_currentSurrond[newPosition.X, newPosition.Y + 1] != 0) && (_currentSurrond[newPosition.X + 1, newPosition.Y] != 0));
            }

            return(false);
        }
Beispiel #3
0
        private Interface.Direction GetAbsoluteDirection(Interface.Direction direction, Interface.Move move)
        {
            if (move == Interface.Move.Left)
            {
                if (direction == Interface.Direction.Top)
                {
                    return(Interface.Direction.TopLeft);
                }
                return(direction - 1);
            }

            if (move == Interface.Move.Right)
            {
                if (direction == Interface.Direction.TopLeft)
                {
                    return(Interface.Direction.Top);
                }
                return(direction + 1);
            }

            return(direction);
        }
Beispiel #4
0
        private bool GetIfMoveIsSafe(Point currentPosition, Interface.Direction currentDirection, Interface.Move move, int numberOfSafeMoves)
        {
            if (numberOfSafeMoves == 0)
            {
                return(true);
            }

            Interface.Direction absoluteDirection = GetAbsoluteDirection(currentDirection, move);

            Point nextPoint = GetNextPoint(currentPosition, absoluteDirection);

            if (nextPoint.X >= _sizeOfTable || nextPoint.X < 0 || nextPoint.Y >= _sizeOfTable || nextPoint.Y < 0)
            {
                return(false);
            }

            if (_currentSurrond[nextPoint.X, nextPoint.Y] != 0)
            {
                return(false);
            }

            if (IsCrossColision(nextPoint, absoluteDirection))
            {
                return(false);
            }

            numberOfSafeMoves--;

            foreach (var nextMove in _moveList)
            {
                if (GetIfMoveIsSafe(nextPoint, absoluteDirection, nextMove, numberOfSafeMoves))
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #5
0
 public void Init(int direction, int identificator)
 {
     _myCurrentDirection = (Interface.Direction)direction;
     _myIdentificatior   = identificator;
 }
Beispiel #6
0
 private void RecalculateNextPositionAndDirection(Interface.Move move)
 {
     _myCurrentDirection = GetAbsoluteDirection(_myCurrentDirection, move);
     MyCurrentPosition   = GetNextPoint(MyCurrentPosition, _myCurrentDirection);
 }