Esempio n. 1
0
        public GameRoles ChangeTurn()
        {
            var passedRole = CurrentRole;

            CurrentRole = (GameRoles)((int)CurrentRole ^ 1);
            return(passedRole);
        }
Esempio n. 2
0
 public static string GetRoleName(this GameRoles role)
 {
     return(role switch
     {
         GameRoles.Citizen => "Мирный житель",
         GameRoles.Doctor => "Доктор",
         GameRoles.Cop => "Коммисар",
         GameRoles.Mafia => "Мафиози",
         _ => ""
     });
Esempio n. 3
0
        private async Task <bool> KillGamer(GameSession session, GameRoles killerRole, GameSessionMember actionTarget,
                                            GameSessionMember?healingTarget)
        {
            // healed by doctor
            if (actionTarget.Id == healingTarget?.Id)
            {
                return(false);
            }
            actionTarget.IsDead = true;
            await _frontend.SendMessageToRoom(session.Room,
                                              $"Был убит: <i>{actionTarget.Role.GetRoleName()}</i> <b>{actionTarget.GamerAccount.NickName}</b>");

            AskForLastWord(session, actionTarget).ConfigureAwait(false);
            return(true);
        }
Esempio n. 4
0
        private async Task InspectGamer(GameSession session, GameRoles instectorRole, GameSessionMember inspectorTarget)
        {
            await _frontend.SendMessageToGamer(inspectorTarget.GamerAccount, "Кто-то наводит справки по тебе...");

            var roleName = inspectorTarget.Role switch
            {
                GameRoles.Citizen => "горожанин",
                GameRoles.Cop => "коммисар",
                GameRoles.Doctor => "доктор",
                GameRoles.Mafia => "мафия"
            };
            var messageText =
                $"Наши люди нашли важную информацию: <b>{inspectorTarget.GamerAccount.NickName}</b> это <b>{roleName}</b>.";

            switch (instectorRole)
            {
            case GameRoles.Cop:
            {
                var cop = session.GetCop();
                if (cop == null)
                {
                    Console.WriteLine($"{session.Id} - Cop is null!");
                    return;
                }

                await _frontend.SendMessageToGamer(cop.GamerAccount, messageText);

                break;
            }

            case GameRoles.Mafia:
                var mafiaMembers = session.GetMafia();
                var messageTasks =
                    mafiaMembers.Select(m => _frontend.SendMessageToGamer(m.GamerAccount, messageText));
                await Task.WhenAll(messageTasks);

                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(instectorRole), instectorRole,
                                                      "Supported only for Cop and Mafia");
            }
        }