Beispiel #1
0
 public GameController(
     ApplicationDbContext dbContext,
     IGameUsecase gameUsecase,
     IFriendPresenter gamePresenter
     )
 {
     this.dbContext     = dbContext;
     this.gameUsecase   = gameUsecase;
     this.gamePresenter = gamePresenter;
 }
Beispiel #2
0
        public ResultPageViewModel(INavigationService navigationService, IGameUsecase gameUsecase) : base(navigationService)
        {
            _gameUsecase = gameUsecase;

            IsWinner = Observable.CombineLatest(
                _gameUsecase.MyPlayer.Where(x => x is not null),
                _gameInfo.Where(x => x is not null),
                (player, info) => info.Winner == player !.Side)
                       .ToReadOnlyReactivePropertySlim()
                       .AddTo(_disposables);

            Side = _gameUsecase.MyPlayer.Where(x => x is not null)
                   .Select(x => x !.Side).ToReadOnlyReactivePropertySlim()
                   .AddTo(_disposables);
        }
Beispiel #3
0
        public GamePageViewModel(INavigationService navigationService, IGameUsecase gameUsecase, IUserDialogs userDialogs) : base(navigationService)
        {
            _gameUsecase = gameUsecase;
            _userDialogs = userDialogs;

            _gameUsecase.PhaseChanged
            .Subscribe(info => _gameInfo.Value = info)
            .AddTo(_disposables);

            Observable.CombineLatest(
                _gameUsecase.MyPlayer.Where(p => p is not null).Take(1),
                _gameInfo.Where(info => info is not null && info.Phase is Phase.Noon or Phase.Night),
                (myPlayer, info) => (myPlayer, info))
            .Subscribe(t =>
            {
                var canSelect =
                    !(t.myPlayer !.IsDied ||
                      t.info.Phase == Phase.Start || t.info.Phase == Phase.End ||
                      (t.info.Phase == Phase.Night && t.info.Day == 1) ||
                      (t.info.Phase == Phase.Night && t.myPlayer !.Role != Role.Werewolf));

                _players.Value = _gameUsecase.Players.Select(player =>
                {
                    var actionType = ActionType.None;

                    if (_gameInfo.Value is not null)
                    {
                        actionType = _gameInfo.Value.Phase switch
                        {
                            Phase.Noon => ActionType.Vote,
                            Phase.Night => ActionType.Kill,
                            _ => ActionType.None,
                        };
                    }

                    var statusList = new List <string>();
                    if (t.myPlayer !.Id == player.Id)
                    {
                        statusList.Add("自分");
                    }
                    if (player.Role != Role.Unkown)
                    {
                        statusList.Add(player.Role.ToName());
                    }
                    if (player.IsDied)
                    {
                        statusList.Add("死亡");
                    }

                    var status = string.Join(" ", statusList);

                    return(new PlayerData
                    {
                        Id = player.Id,
                        Name = player.Name,
                        Index = player.Index,
                        Role = player.Role,
                        Side = player.Side,
                        IsDied = player.IsDied,
                        IsMe = t.myPlayer !.Id == player.Id,
                        CanSelect = canSelect &&
                                    t.myPlayer !.Id != player.Id &&
                                    !player.IsDied,
                        ActionType = actionType,
                        Status = status
                    });
                })
                                 .ToArray();
            })
Beispiel #4
0
        public MainPageViewModel(INavigationService navigationService, IGameUsecase gameUsecase, IUserDialogs userDialogs) : base(navigationService)
        {
            _gameUsecase = gameUsecase;
            _userDialogs = userDialogs;

            CreateCommand = _busyNotifier
                            .Inverse()
                            .ObserveOn(SynchronizationContext.Current)
                            .ToAsyncReactiveCommand()
                            .WithSubscribe(() => NavigationService.NavigateAsync("CreatePage"))
                            .AddTo(_disposables);

            JoinCommand = _busyNotifier
                          .Inverse()
                          .ObserveOn(SynchronizationContext.Current)
                          .ToAsyncReactiveCommand()
                          .WithSubscribe(() => NavigationService.NavigateAsync("JoinPage"))
                          .AddTo(_disposables);

            _gameUsecase.PhaseChanged
            .Subscribe(info => _gameInfo.Value = info)
            .AddTo(_disposables);

            _createRequested.SelectMany(_ => Observable.Using(() =>
            {
                return(new CompositeDisposable()
                {
                    _busyNotifier.ProcessStart(),
                    _userDialogs.Loading(""),
                });
            }, _ => Observable.Amb(
                                                                  _gameUsecase.StartNewGameResponsed.Select(_ => true),
                                                                  _gameUsecase.ErrorOccurred.Select(_ => false))
                                                              .Take(1)
                                                              .SelectMany(b => b ?
                                                                          _gameInfo.Where(info => info is not null)
                                                                          .Select <GameInfo, (GameInfo?info, bool success)>(info => (info, b)) :
                                                                          Observable.Return <(GameInfo?info, bool success)>((null, b)))
                                                              .Take(1)))
            .ObserveOn(SynchronizationContext.Current)
            .Subscribe(async t =>
            {
                if (!t.success)
                {
                    _userDialogs.Alert("ゲーム開始に失敗しました", "エラー");
                }
                else
                {
                    await _userDialogs.AlertAsync($"ゲームID: {t.info!.GameId}", "確認");
                    _waitRequested.OnNext(t.info);
                }
            })
            .AddTo(_disposables);

            _joinRequested.SelectMany(_ => Observable.Using(() =>
            {
                return(new CompositeDisposable()
                {
                    _busyNotifier.ProcessStart(),
                    _userDialogs.Loading(""),
                });
            }, _ => Observable.Amb(
                                                                _gameUsecase.JoinResponsed.Select(_ => true),
                                                                _gameUsecase.ErrorOccurred.Select(_ => false))
                                                            .Take(1)
                                                            .SelectMany(b => b ?
                                                                        _gameInfo.Where(info => info is not null && info.Phase == Phase.Night && info.Day == 1)
                                                                        .Select <GameInfo, (GameInfo?info, bool success)>(info => (info, b)) :
                                                                        Observable.Return <(GameInfo?info, bool success)>((null, b)))
                                                            .Take(1)))
            .ObserveOn(SynchronizationContext.Current)
            .Subscribe(t =>
            {
                if (!t.success)
                {
                    _userDialogs.Alert("ゲーム参加に失敗しました", "エラー");
                }
                else
                {
                    NavigationService.NavigateAsync("/GamePage",
                                                    (GamePageViewModel.GameInfoParameterKey, t.info));
                }
            })
            .AddTo(_disposables);

            _waitRequested.SelectMany(info => Observable.Using(() =>
            {
                return(new CompositeDisposable()
                {
                    _busyNotifier.ProcessStart(),
                    _userDialogs.Loading($"ゲームID: {info.GameId}"),
                });
            }, _ => _gameInfo.Where(info => info is not null && info.Phase == Phase.Night && info.Day == 1)
                                                               .Take(1)))
            .ObserveOn(SynchronizationContext.Current)
            .Subscribe(info =>
            {
                NavigationService.NavigateAsync("/GamePage",
                                                (GamePageViewModel.GameInfoParameterKey, info));
            })
            .AddTo(_disposables);
        }