示例#1
0
        public async Task Play(string controller, string secondary)
        {
            string logo = "Choose a figure => ";

            string[] options        = new string[] { "Rock", "Scissors", "Paper", "Exit" };
            Menu     randomGameMenu = new Menu(logo, options);

            Commands command   = Commands.Exit;
            bool     isRunning = true;

            while (isRunning)
            {
                var timer = new TimerClass(20000);
                timer.SetTimer();
                timer.StartTimer();
                if (timer.inGoing == "Exit")
                {
                    command = Commands.Exit;
                    await gameProcess.PostFigureAsync(controller, secondary, command, timer);

                    return;
                }

                int result = randomGameMenu.Run();

                switch (result)
                {
                case 0:
                    gameProcess.auth.Stat.RockCount++;
                    command = Commands.Stone;
                    break;

                case 1:
                    gameProcess.auth.Stat.ScissorsCount++;
                    command = Commands.Scissors;
                    break;

                case 2:
                    gameProcess.auth.Stat.PaperCount++;
                    command = Commands.Paper;
                    break;

                default:
                    command = Commands.Exit;
                    break;
                }
                isRunning = await gameProcess.PostFigureAsync(controller, secondary, command, timer);
            }
        }
示例#2
0
        public async Task <bool> PostFigureAsync(string firstRequest, string secondRequest, Commands commands, TimerClass timer)
        {
            PostRequest postRequest = new PostRequest(auth.client);
            var         player      = new Player()
            {
                Login    = auth.AuthUser.Login,
                Password = auth.AuthUser.Password,
                Command  = commands
            };
            var responseForGame = await postRequest.ExecuteAsync <Player>(player, $"/{firstRequest}/{auth.Guid}");


            if (commands == Commands.Exit)
            {
                await auth.client.GetAsync($"/{firstRequest}/{secondRequest}/{auth.Guid}");

                return(false);
            }

            Console.Write("\nWaiting for the oponent\n");
            while (true)
            {
                if (timer.inGoing == "Exit")
                {
                    await auth.client.GetAsync($"/{firstRequest}/{secondRequest}/{auth.Guid}");

                    return(false);
                }
                var response = await auth.client.GetAsync($"/{firstRequest}/{secondRequest}/{auth.Guid}");

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    var result = await response.Content.ReadAsStringAsync();

                    if (result.Equals("Draw"))
                    {
                        auth.Stat.Draws++;
                        Console.WriteLine("Draw");
                        auth.Stat.Draws++;
                    }
                    else if (result.Equals(auth.AuthUser.Login))
                    {
                        auth.Stat.Wins++;
                        Console.WriteLine("You won!");
                        auth.Stat.Wins++;
                    }
                    else if (result.Equals("Exit"))
                    {
                        return(false);
                    }
                    else
                    {
                        auth.Stat.Loses++;
                        Console.WriteLine("You loose :(");
                        auth.Stat.Loses++;
                    }
                    Console.ReadKey();
                    timer.TimerDispose();
                    return(true);
                }
                else
                {
                    //Console.WriteLine(response.StatusCode);
                    //Console.Write(".");
                }
            }
        }