Beispiel #1
0
        private void NavigateToResult(IGameResultModel gameResultModel)
        {
            var gameResultEntity = GameResultTranslator.Translate(gameResultModel);

            gameResultRepository.Write(gameResultEntity);

            SceneManager.LoadSceneAsync(Constant.SceneName.Result);
        }
Beispiel #2
0
        public void Initialize()
        {
            var gameStateEntity = gameStateRepository.GetEntity();
            var gameStateModel  = gameStateModelTranslator.Translate(gameStateEntity);

            var gameResultEntity = gameResultRepository.GetEntity();
            var gameResultModel  = GameResultTranslator.Translate(gameResultEntity);

            Observable
            .EveryUpdate()
            .Subscribe(_ => gameStateModel.RemainingTime.Value -= Time.deltaTime);

            gameStateModel
            .RemainingTime
            .Where(x => x >= 0.0f)
            .Subscribe(x => gamePresenter.RenderTimer(x));

            gameStateModel
            .RemainingTime
            .Where(x => x < 0.0f)
            .First()
            .Subscribe(_ => NavigateToResult(gameResultModel));

            var currentFormulaModel = new ReactiveProperty <IFormulaModel>(FormulaModelFactory.Create());

            currentFormulaModel
            .Subscribe(x => gamePresenter.RenderFormula(x));

            gamePresenter
            .OnSelectOperation()
            .Subscribe(x =>
            {
                if (currentFormulaModel.Value.IsCorrect(x))
                {
                    gameStateModel.OnCorrectSubject.OnNext(x);
                }
                else
                {
                    gameStateModel.OnIncorrectSubject.OnNext(x);
                }
            });

            gameStateModel
            .OnCorrectSubject
            .Subscribe(x => gamePresenter.Correct(x));

            gameStateModel
            .OnCorrectSubject
            .Subscribe(_ => IncreaseScore(gameResultModel));

            gameResultModel
            .Score
            .Subscribe(x => gamePresenter.RenderScore(x));

            gameStateModel
            .OnCorrectSubject
            .Subscribe(_ => currentFormulaModel.Value = FormulaModelFactory.Create());

            gameStateModel
            .OnIncorrectSubject
            .Subscribe(x => gamePresenter.Incorrect(x));
        }