Beispiel #1
0
        static void Main(string[] args)
        {
            //string contents = File.ReadAllText(@"Input.txt", Encoding.UTF16);

            try
            {
                Room room = new Room(5, 5);

                Hoover hoover = new Hoover(new RoomLocation(1, 2, room));

                Dirt dirts = new Dirt(
                    new List <RoomLocation>
                {
                    new RoomLocation(1, 0, room),
                    new RoomLocation(2, 2, room),
                    new RoomLocation(2, 3, room),
                }
                    );

                Instruction instruction = new Instruction("NNESEESWNWW");

                hoover.Move(instruction, dirts, room);
            }
            catch (OutOfBoundsException ex)
            {
                Console.WriteLine(ex);
            }

            catch (HitWallException ex)
            {
                Console.WriteLine(ex);
            }
        }
Beispiel #2
0
 public int Clean(Dirt dirts)
 {
     foreach (var dirt in dirts.Location.ToArray())
     {
         if (Location.X.Equals(dirt.X) && Location.Y.Equals(dirt.Y))
         {
             dirts.Location.Remove(dirt);
             dirtCollected += 1;
         }
     }
     Console.WriteLine($"Hoover totals dirt collected is: {dirtCollected}");
     return(dirtCollected);
 }
Beispiel #3
0
        public string Move(Instruction instruction, Dirt dirts, Room room)
        {
            char[] steps;
            steps = instruction.Coordinates.ToCharArray();

            foreach (char step in steps)
            {
                if (step.Equals('N'))
                {
                    Location.Y += 1;
                }

                if (step.Equals('S'))
                {
                    Location.Y -= 1;
                }

                if (step.Equals('E'))
                {
                    Location.X += 1;
                }

                if (step.Equals('W'))
                {
                    Location.X -= 1;
                }

                if (Location.X < 0 || Location.Y > room.Width || Location.Y < 0 || Location.Y > room.Height)
                {
                    throw new HitWallException("Sorry hoover can't go further");
                }
                Clean(dirts);
            }
            Console.WriteLine($"Final hoover location is X: {Location.X} and Y: {Location.Y}");
            return($"Final hoover location is X: {Location.X} and Y: {Location.Y}");
        }