Esempio n. 1
0
        private static Ant TurnAndMove(Ant ant, TurnDirection dir)
        {
            AntCoordinates newCoordinates = new AntCoordinates(ant.coord.X, ant.coord.Y);

            if (dir == TurnDirection.Clockwise)
            {
                switch (ant.facing)
                {
                case Facing.North:
                {
                    newCoordinates.X = ant.coord.X + 1;
                    newCoordinates   = CheckBounds(newCoordinates, _canvasSize);
                    ant.facing       = Facing.East;
                    break;
                }

                case Facing.East:
                {
                    newCoordinates.Y = ant.coord.Y + 1;
                    newCoordinates   = CheckBounds(newCoordinates, _canvasSize);
                    ant.facing       = Facing.South;
                    break;
                }

                case Facing.South:
                {
                    newCoordinates.X = ant.coord.X - 1;
                    newCoordinates   = CheckBounds(newCoordinates, _canvasSize);
                    ant.facing       = Facing.West;
                    break;
                }

                case Facing.West:
                {
                    newCoordinates.Y = ant.coord.Y - 1;
                    newCoordinates   = CheckBounds(newCoordinates, _canvasSize);
                    ant.facing       = Facing.North;
                    break;
                }
                }
            }
            else
            {
                switch (ant.facing)
                {
                case Facing.North:
                {
                    newCoordinates.X = ant.coord.X - 1;
                    newCoordinates   = CheckBounds(newCoordinates, _canvasSize);
                    ant.facing       = Facing.West;

                    break;
                }

                case Facing.East:
                {
                    newCoordinates.Y = ant.coord.Y - 1;
                    newCoordinates   = CheckBounds(newCoordinates, _canvasSize);
                    ant.facing       = Facing.North;
                    break;
                }

                case Facing.South:
                {
                    newCoordinates.X = ant.coord.X + 1;
                    newCoordinates   = CheckBounds(newCoordinates, _canvasSize);
                    ant.facing       = Facing.East;
                    break;
                }

                case Facing.West:
                {
                    newCoordinates.Y = ant.coord.Y + 1;
                    newCoordinates   = CheckBounds(newCoordinates, _canvasSize);
                    ant.facing       = Facing.South;
                    break;
                }
                }
            }
            ant.coord = newCoordinates;
            return(ant);
        }