Пример #1
0
        public override TurtleSituation CalculateSituation(TurtleSituation currentSituation)
        {
            var result = new TurtleSituation();
            int newAngle;

            if (TurnAngle >= 0)
            {
                newAngle = (currentSituation.Angle + TurnAngle) % 360;
            }
            else
            {
                int turnAngleAbs = Math.Abs(TurnAngle);
                if (turnAngleAbs >= currentSituation.Angle)
                {
                    newAngle = 360 - (turnAngleAbs - currentSituation.Angle);
                }
                else
                {
                    newAngle = currentSituation.Angle - turnAngleAbs;
                }
            }
            result.Angle     = newAngle;
            result.TurnAngle = currentSituation.TurnAngle + TurnAngle;
            result.Position  = currentSituation.Position;
            result.Change    = TurtleSituationChange.Turned;
            return(result);
        }
Пример #2
0
        private int CalculateY(TurtleSituation currentSituation, int newY)
        {
            int result;

            if ((currentSituation.Angle <= 180 && Math.Sign(Distance) > 0) ||
                (currentSituation.Angle > 180 && Math.Sign(Distance) < 0))
            {
                result = currentSituation.Position.Y + newY;
            }
            else
            {
                result = currentSituation.Position.Y - newY;
            }
            return(result);
        }
Пример #3
0
        public override TurtleSituation CalculateSituation(TurtleSituation currentSituation)
        {
            var result = new TurtleSituation();
            int newX   = Convert.ToInt32(Math.Round(Distance * Math.Cos(DegreesToRadian(currentSituation.Angle))));
            int newY   = Convert.ToInt32(Math.Round(Math.Sqrt(Distance * Distance - newX * newX)));

            result.Position = new Position
            {
                X = currentSituation.Position.X + newX,
                Y = CalculateY(currentSituation, newY)
            };
            result.Angle     = currentSituation.Angle;
            result.TurnAngle = currentSituation.TurnAngle;
            result.Change    = TurtleSituationChange.Moved;
            return(result);
        }
Пример #4
0
 public virtual TurtleSituation CalculateSituation(TurtleSituation currentSituation)
 {
     return(currentSituation);
 }