Exemplo n.º 1
0
 /// <summary>
 ///     Deliver a present to the House.
 /// </summary>
 /// <param name="house"></param>
 private static void DeliverPresent(House house)
 {
     house.Presents++;
     int numPresents = house.Presents;
     Console.WriteLine(
         $" {numPresents} present{(numPresents == 1 ? "" : "s")} delivered to house.");
 }
Exemplo n.º 2
0
        /// <summary>
        ///     Move Santa to next position based on character.
        /// </summary>
        /// <param name="house">The House that Santa has just delivered a present to</param>
        /// <param name="direction">The direction Santa needs to go</param>
        /// <param name="santaNumber">Indictaes if Santa or RoboSanta is delivering presents</param>
        /// <returns>Index of next house.</returns>
        private static int Move(House house, char direction, int santaNumber)
        {
            int x = house.X;
            int y = house.Y;
            string point;

            switch (direction)
            {
                case '^':
                    y++;
                    point = "North";
                    break;
                case 'v':
                    y--;
                    point = "South";
                    break;
                case '>':
                    x++;
                    point = "East";
                    break;
                case '<':
                default:
                    x--;
                    point = "West";
                    break;
            }

            Console.Write($"{(santaNumber%2==0?"Santa":"RoboSanta")} moves {point} to {x}/{y}");
            int index = Houses.FindIndex(h => h.X == x && h.Y == y);
            if (index == -1)
            {
                House newHouse = new House(x, y);
                Houses.Add(newHouse);
                index = Houses.IndexOf(newHouse);
                Console.Write(" (New house)");
            }
            Console.Write(".");
            return index;
        }