예제 #1
0
        public static Boolean PlayAdventure()
        {
            string instanceID;
            string move;
            bool   error;
            string errormsg = "";



            var _httpClient = new System.Net.Http.HttpClient();
            var _client     = new swaggerClient(_httpClient)
            {
                BaseUrl = ApiUrl
            };



            move = "";

            try
            {
                DisplayIntro();
                Console.WriteLine();
                SetColor(ConsoleColor.Yellow);
                Console.WriteLine("cquit = quit game and capi = Display API endpoint");
                SetColor(ConsoleColor.Green);
                Console.WriteLine("");


                // default to game 1 until I we have selection system
                // Gets the first game and sets up the game
                gmr        = _client.Adventure3Async(1).GetAwaiter().GetResult();
                instanceID = gmr.InstanceID;
                error      = false;
            }
            catch (Exception e)
            {
                // oops! Looks like we had a problem starting the game.
                SetColor(ConsoleColor.Red);
                errormsg = "Error: Can not create new game (" + ApiUrl + ")";
                Console.WriteLine(errormsg);
                Console.WriteLine(e.ToString());
                SetColor(ConsoleColor.Green);
                return(false);
            }

            while (move != "cquit")
            {
                switch (move)
                {
                case "capi":
                    Console.WriteLine();
                    SetColor(ConsoleColor.Yellow);
                    Console.WriteLine("Api:" + ApiUrl);
                    SetColor(ConsoleColor.Green);
                    Console.WriteLine();
                    move = "";
                    break;

                default:

                    Console.WriteLine();
                    SetColor(ConsoleColor.Yellow);
                    Console.Write(gmr.RoomName);
                    Console.WriteLine();
                    SetColor(ConsoleColor.Green);
                    Console.WriteLine(gmr.RoomMessage);
                    SetColor(ConsoleColor.DarkCyan);
                    Console.WriteLine(gmr.ItemsMessage);
                    Console.WriteLine();
                    SetColor(ConsoleColor.White);
                    Console.Write("What now?"); SetColor(ConsoleColor.Green); Console.Write(" >"); SetColor(ConsoleColor.Green);

                    if (error == true)
                    {
                        Console.WriteLine();
                        SetColor(ConsoleColor.Red);
                        Console.WriteLine("Client Error:");
                        Console.WriteLine(errormsg);
                        SetColor(ConsoleColor.Green);
                        Console.WriteLine();
                    }

                    move = Console.ReadLine();

                    try
                    {
                        // once the game is setup by calling the get that returns the first gmr you then
                        // just pass the game move with the instance id
                        gmr = _client.Adventure2Async(instanceID, move).GetAwaiter().GetResult();
                    }
                    catch (Exception)
                    {
                        error = true;
                        SetColor(ConsoleColor.Red);
                        errormsg        = "Error: Can not Process Move - Possible Timeout. Try move again or LOOK.";
                        gmr.RoomMessage = errormsg;     // report the error ro the user;
                        SetColor(ConsoleColor.Green);
                    }
                    break;
                }
            }

            if (error)
            {
                Console.WriteLine(errormsg);
            }

            return(error);
        }