Example #1
0
        public async Task <Authentification> LoginAsync()
        {
            if (auth.CountOfBadLogin == 3)
            {
                Console.WriteLine("You're been blocked for too many try to login");
                return(null);
            }
            Console.WriteLine("Login: "******"Password: "******"/login", user);

            if (isSuccess)
            {
                auth.AuthUser = user;
                PersonalStatistic personalStatistic = new PersonalStatistic(auth);
                var stats = await personalStatistic.GetStatsAsync(user);

                stat = JsonConvert.DeserializeObject <PlayerPersonalStat>(stats);
                if (stat == null)
                {
                    stat = new PlayerPersonalStat()
                    {
                        Login          = user.Login,
                        TimeInGame     = "00:00:00",
                        ChangesWinrate = new Dictionary <DateTime, float>()
                    }
                }
                ;
                auth.Stat = stat;
                //Console.WriteLine("You successfuly loged in");
                return(auth);
            }
            Console.WriteLine("\nYou enterd wrong login or password");
            Console.WriteLine("Press any button to go back to main menu");
            Console.ReadKey();
            return(null);
        }
    }
Example #2
0
        public async Task RunGameMenuAsync()
        {
            string logo = @" _____                                            _      
|  __ \                                          | |     
| |  \/ __ _ _ __ ___   ___   _ __ ___   ___   __| | ___ 
| | __ / _` | '_ ` _ \ / _ \ | '_ ` _ \ / _ \ / _` |/ _ \
| |_\ \ (_| | | | | | |  __/ | | | | | | (_) | (_| |  __/
 \____/\__,_|_| |_| |_|\___| |_| |_| |_|\___/ \__,_|\___|
                                                         
                                                         ";

            string[] options = new string[] { "Random game", "Private game", "Training with bot",
                                              "Show personal statistic", "Back" };
            Menu gameMenu = new Menu(logo, options);
            int  selected = gameMenu.Run();

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            PersonalStatistic ps = new PersonalStatistic(auth);

            switch (selected)
            {
            case 0:
                Console.Clear();
                RandomGame randomGame = new RandomGame(auth);
                await randomGame.RandomGameAsync("api/RandomPlay", "game");

                break;

            case 1:
                Console.Clear();
                PrivateGame privateGame = new PrivateGame(auth);
                await privateGame.PrivateGameAsync("api/PrivatePlay", "game");

                break;

            case 2:
                Console.Clear();
                GameWithBot gameWithBot = new GameWithBot(auth);
                await gameWithBot.BotGame("api/BotPlay");

                break;

            case 3:
                Console.WriteLine(auth.Stat);
                Console.ReadKey();
                break;

            case 4:
                Console.Clear();
                stopWatch.Stop();
                TimeSpan timeSpan = stopWatch.Elapsed;
                TimeSpan ts       = TimeSpan.Parse(auth.Stat.TimeInGame).Multiply(100);
                auth.Stat.TimeInGame = ts.Add(timeSpan).ToString();
                await ps.PostStatsAsync(auth.Stat);

                return;
            }


            //stopWatch.Stop();
            //TimeSpan ts = stopWatch.Elapsed;
            //stat.TimeInGame.Add(ts);
            //await PostStatsAsync(stat);

            await RunGameMenuAsync();
        }