예제 #1
0
        public void Adventure()
        {
            Console.Clear();

            List <ConsoleKey> availableKeys = new List <ConsoleKey>()
            {
                ConsoleKey.D1, ConsoleKey.D2, ConsoleKey.D3, ConsoleKey.D4, ConsoleKey.D5, ConsoleKey.D6, ConsoleKey.D7
            };


            nowIn = rooms[0];

            while (true)
            {
                nowIn.DrawSelfCurrentRoom();
                ConsoleKey        k     = ConsoleKey.A;
                List <ConsoleKey> canGo = new List <ConsoleKey>();
                for (int i = 0; i < nowIn.near.Count; i++)
                {
                    canGo.Add(availableKeys[i]);
                }
                canGo.Add(ConsoleKey.Q);
                do
                {
                    k = Console.ReadKey().Key;
                    if (k == ConsoleKey.Q)
                    {
                        Console.BackgroundColor = ConsoleColor.DarkRed; Console.Write("Are you sure to exit : y/n ");
                        k = Console.ReadKey().Key;
                        if (k == ConsoleKey.Y)
                        {
                            Console.ResetColor();
                            Console.Clear();
                            break;
                        }
                    }
                } while (canGo.IndexOf(k) < 0);

                if (k == ConsoleKey.Y)
                {
                    break;
                }

                int choosenRoad = canGo.IndexOf(k);
                nowIn.DrawSelf('.');

                if (nowIn == nowIn.near[choosenRoad].from)
                {
                    nowIn = nowIn.near[choosenRoad].to;
                }
                else
                {
                    nowIn = nowIn.near[choosenRoad].from;
                }
            }
        }