示例#1
0
        private async Task RunGame(ICity city, Game game)
        {
            await game.StartGame();

            cityToChat.TryRemove(city, out var chatId);
            Console.WriteLine($"Successfully removed city with chat.Id {chatId}");

            foreach (var person in city.Population)
            {
                personToChat.TryRemove(person, out var personChat);
                Console.WriteLine($"Successfully removed person with chat.Id {personChat}");
            }
        }
示例#2
0
        private async Task EndRecordMethod(long chatId)
        {
            IGameRecord record;

            var lockTaken = false;

            try
            {
                await playSemaphore.WaitAsync();

                lockTaken = true;

                if (!gameRecords.TryRemove(chatId, out record))
                {
                    await bot.SendTextMessageAsync(chatId, $"There no opened game record\nType {PlayCommand} to start one");
                }
            }
            finally
            {
                if (lockTaken)
                {
                    playSemaphore.Release();
                }
            }

            if (record == null)
            {
                return;
            }

            var population = new List <IPerson>();

            foreach (var(userId, person) in record.ExtractPersons())
            {
                population.Add(person);
                personToChat[person] = userId;
                var message = person.NightRole == null
                    ? $"Your name is {person.Name} and you are Peaceful"
                    : $"Your name is {person.Name} and you are {person.NightRole.Name}";
                await SendUsersSaveMessage(message, userId, chatId);
            }

            var settings = record.Settings;
            var city     = new City(population, settings.CityName);

            cityToChat[city]  = chatId;
            citiToAwake[city] = true;
            var game = new Game(settings, city, this);

            await RunGame(city, game);
        }