Exemplo n.º 1
0
        static void Gallows_Thread_Start(object obj_id)
        {
            long user_id = (long)obj_id;

            // var g = new Gallows(user_id);
            EngBot.users[user_id].keyb = User.Gallows_KeyBoard;
            EngBot.SendMessage(user_id, "Это игра виселица, необходимо отгадать английское слово за ограниченное количество попыток!");
            EngBot.SendMessage(user_id, "Присылай мне по одной букве или пришли всё слово, если уже отгадал его", null, true);
            var gal = new Gallows(user_id);

            SendMessage(gal);
            if (Wait_answers_gallows(gal))
            {
                EngBot.users[user_id].gall_passed++;
            }
            EngBot.users[user_id].on_Test = false;
        }
Exemplo n.º 2
0
        static void SendMessage(Gallows gal)
        {
            Stopwatch stp = new Stopwatch();

            stp.Start();

            string message = "Слово: " + string.Join("", gal.show).ToUpper() + "\n" +
                             "Количество попыток: " + gal.attempts_remain + "\n" +
                             "Использованные буквы: " + string.Join(", ", gal.used) + "\n" +
                             // "Часть речи: " + EngBot.dictionary[gal.word_id];
                             "Перевод: " + string.Join(", ", gal.tr);


            try
            {
                EngBot.bot.Api.Messages.Send(new VkNet.Model.RequestParams.MessagesSendParams()
                {
                    RandomId = Environment.TickCount64,
                    UserId   = gal.user_id,
                    Message  = message
                });
                stp.Stop();
            }
            catch (VkNet.Exception.TooMuchOfTheSameTypeOfActionException)
            {
                Console.WriteLine("VK poshel v zhopu");
            }
            catch (VkNet.Exception.PublicServerErrorException)
            {
                Console.WriteLine("Server error with sending message!");
            }
            catch (VkNet.Exception.CannotSendToUserFirstlyException)
            {
                Console.WriteLine("Server error with sending message!");
            }
            catch (Exception e)
            {
                Console.WriteLine("Some error with sending cross");
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
            Console.WriteLine("Elapsed for sending: " + stp.ElapsedMilliseconds);
        }
Exemplo n.º 3
0
        static bool Wait_answers_gallows(Gallows gal)
        {
            int wait_time = 10;
            var ind       = IndicatorTimer(wait_time);
            var user      = EngBot.users[gal.user_id];

            string text      = user.lastMsg.Item1.ToLower();
            long   ident_msg = user.lastMsg.Item3;

            bool exit_by_hint = false;

            while (true)
            {
                if (gal.attempts_remain == 0)
                {
                    user.keyb = User.Main_Keyboard;
                    EngBot.SendMessage(gal.user_id, "Попытки закончились :(\nЗагаданное слово: " + gal.word, null, true);
                    return(false);
                }

                if (gal.success)
                {
                    user.keyb = User.Main_Keyboard;
                    EngBot.SendMessage(gal.user_id, exit_by_hint ? "Вы отгадали слово с помощью подсказки, так не честно :)" : "Поздравляю! Вы выйграли!", null, true);
                    return(exit_by_hint);
                }

                if (ind.x)
                {
                    user.keyb = User.Main_Keyboard;
                    EngBot.SendMessage(gal.user_id, "Ладно, тогда поиграем позже...", null, true);
                    return(false);
                }

                if (ident_msg == user.lastMsg.Item3)
                {
                    Thread.Sleep(100);
                    continue;
                }

                ind.x = true;
                ind   = IndicatorTimer(wait_time);

                ident_msg = user.lastMsg.Item3;
                text      = EngBot.GetFormatedWord(user.lastMsg.Item1);
                if (text == null || text.Length == 0)
                {
                    EngBot.SendMessage(gal.user_id, "Я жду текстовые ответы");
                    continue;
                }
                var words = text.Split(' ', StringSplitOptions.RemoveEmptyEntries);

                if (text == "/hint" || text == "подсказать букву")
                {
                    EngBot.SendMessage(gal.user_id, "Вот подсказка ;)");
                    for (int i = 0; i < gal.word.Length; i++)
                    {
                        if (gal.show[i] == '?')
                        {
                            gal.OpenLetter(gal.word[i], true);
                            SendMessage(gal);
                            exit_by_hint = true;
                            break;
                        }
                    }
                    continue;
                }

                if (text == "/give_up" || text == "я сдаюсь")
                {
                    user.keyb = User.Main_Keyboard;
                    EngBot.SendMessage(gal.user_id, @"Ну как хочешь :-\");
                    EngBot.SendMessage(gal.user_id, "Было загадано слово:\n" + gal.word.ToUpper(), null, true);
                    return(false);
                }

                if (words.Length > 1)
                {
                    EngBot.SendMessage(gal.user_id, @"Что-то не так с количеством cлов :-\");
                    continue;
                }

                if (words[0].Length != 1)
                {
                    // EngBot.SendMessage(gal.user_id, @"Что-то не так с количеством букв :-\");
                    if (gal.word == words[0].ToLower())
                    {
                        user.keyb = User.Main_Keyboard;
                        EngBot.SendMessage(gal.user_id, @"Поздравляем! Вы выиграли!", null, true);
                        return(true);
                    }
                    else
                    {
                        EngBot.SendMessage(gal.user_id, @"Вы не угадали слово :(");
                        gal.attempts_remain -= 1;
                        SendMessage(gal);
                    }
                    continue;
                }

                char c = words[0].ToLower()[0];

                if (!char.IsLetter(c))
                {
                    EngBot.SendMessage(gal.user_id, @"Это не буква :-/");
                    continue;
                }

                if (gal.used.Contains(c))
                {
                    EngBot.SendMessage(gal.user_id, "Эта буква уже отгадана!");
                    continue;
                }

                if (gal.word.IndexOf(c) >= 0)
                {
                    gal.OpenLetter(c);
                    SendMessage(gal);
                }
                else
                {
                    EngBot.SendMessage(gal.user_id, "Такой буквы в слове нет");
                    --gal.attempts_remain;
                    SendMessage(gal);
                }
            }
        }