Example #1
0
        private static void HymeckAndRacotyScholarsMate(string gameId = "1")
        {
            var hymeckClient = new ChessClient("Hymeck", "hymeckpass");
            var racotyClient = new ChessClient("Racoty", "racotypass");

            WriteLine(hymeckClient.MakeMove(gameId, "e2e4"));
            WriteLine("\n");
            WriteLine(racotyClient.MakeMove(gameId, "e7e5"));
            WriteLine("\n");
            WriteLine(hymeckClient.MakeMove(gameId, "d1h5"));
            WriteLine("\n");
            WriteLine(racotyClient.MakeMove(gameId, "b8c6"));
            WriteLine("\n");
            WriteLine(hymeckClient.MakeMove(gameId, "f1c4"));
            WriteLine("\n");
            WriteLine(racotyClient.MakeMove(gameId, "g8f6"));
            WriteLine("\n");
            WriteLine(hymeckClient.MakeMove(gameId, "h5f7"));
        }
        void Start()
        {
            System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            int USER = random.Next(10000);

            client = new ChessClient(HOST, USER);
            Console.WriteLine(client.host);

            while (true)
            {
                string param = Console.ReadLine();
                Console.Clear();
                if (param == "r")
                {
                    Console.WriteLine(client.GetGame(true));
                    continue;
                }

                if (param == "q")
                {
                    client.CloseGame();
                    break;
                }

                if (param == "")
                {
                    Console.WriteLine(client.GetGame(false));
                }
                else if (param.Length == 5)//проверка на дурака ,т.к ход должен содержать 5 символов
                {
                    Console.WriteLine(client.MakeMove(param));
                }
                else//проверка на дурака ,т.к ход должен содержать 5 символов
                {
                    Console.WriteLine("Неверный формат хода или " + client.MakeMove(param));
                }
            }
        }
Example #3
0
 public void JoinParty(ChessClient client)
 {
     _clients.Add(client);
 }
Example #4
0
        public async Task GameCycle()
        {
            WriteLine("Даровень. Занесло в консольный клиент ChessWeb.");
labelInput:
            WriteLine("1: Проникнуть в существующую учетную запись.");
            WriteLine("2: Уйти из зоопарка.");
            var input = ReadLine();

            int.TryParse(input, out var choice);
            if (choice == 2)
            {
                WriteLine("Передайте парашют выходящему из окна нажатием на любую клавишу.");
                return;
            }

            if (choice != 1)
            {
                WriteLine("Пж, 1 либо 2.");
                goto labelInput;
            }

            Clear();

            var username = "";
            var password = "";

            ChessClient client;

            while (true)
            {
                Write("Погоняло: ");
                username = ReadLine();
                Write("Пароль: ");
                InputPassword(out password);
                WriteLine();
                try
                {
                    client = new ChessClient(username, password);
                    break;
                }
                catch (WebException)
                {
                    WriteLine("Пж, неверные вводы либо учтная запись в небытие.");
                }
            }

            WriteLine("Проникновение произошло успешно.");
            Write("Загрузка ");
            for (var i = 0; i < 3; i++)
            {
                await Task.Delay(1000);

                Write('.');
            }

            await Task.Delay(1000);

            WriteLine();
            Clear();

            GameInfo lastActiveGame;
            var      move = "";
            string   userColor;
            bool     isWhite;

            do
            {
                lastActiveGame = client.LastActiveUserGame;
                isWhite        = lastActiveGame.whiteUsername == username;
                userColor      = isWhite
                    ? "White"
                    : "Black";
                var rows = client.BoardHandler.GetBoard(lastActiveGame.fen);
                client.BoardHandler.PrintBoard(rows, isWhite, Write);

                if (lastActiveGame.status == 3)
                {
                    WriteLine($"Пж, игра завершена. Взобравшийся на голову: {lastActiveGame.winner}.");
                    break;
                }

                if (lastActiveGame.activeColor == userColor)
                {
                    Write("Выпад: ");
                    move = ReadLine();

                    if (move == "q")
                    {
                        WriteLine("Досрочный уход из зоопарка.");
                        break;
                    }

                    client.MakeMove(lastActiveGame.gameId.ToString(), move);
                }

                else
                {
                    WriteLine("Нет череда... Ввод клавиши для обновления экрана: ");
                    move = ReadLine();

                    if (move == "q")
                    {
                        WriteLine("Досрочный уход из зоопарка.");
                        break;
                    }
                }

                await Task.Delay(500);

                Clear();
            }while (true);

            WriteLine("Передайте парашют выходящему из окна нажатием на любую клавишу.");
        }