Example #1
0
        public async void LoadAndPlayGame(int id, AppShell appShell)
        {
            var restClient = new RestClient.RestClient();

            var gameResource = await restClient.GetFullGameByIdAsync(id);

            var converter = new FullGameConverter();

            var game = converter.Convert(gameResource);

            LocationChecker = new LocationChecker();

            AppShell = appShell;

            Model = game;

            MapService = new MapService(AppShell);

            Introduction = new IntroductionViewModel(AppShell, Model.Introduction.Title);

            if (Model.Introduction.DisplayObjects != null)
            {
                foreach (DisplayObject obj in Model.Introduction.DisplayObjects)
                {
                    Introduction.AddDisplayObject(obj);
                }
            }

            Text InfoAboutGame = new Text()
            {
                Title = "Hráči, kteří se podíleli na této hře",
                PositionInIntroduction = 0,
                OwnText = ""
            };

            foreach (User user in Model.Owners)
            {
                InfoAboutGame.OwnText = InfoAboutGame.OwnText + user.UserName + " ";
            }

            Introduction.AddText(InfoAboutGame);

            if (Model.Introduction.MapPositions != null)
            {
                MapService.AddNotStops(Model.Introduction.MapPositions as List <MapPosition>);
            }

            StartingTime = DateTime.UtcNow;

            foreach (Stop stop in Model.Stops)
            {
                SetUpStopModel(stop);
            }
        }
        public TextQuestionService(AppShell appShell, TextQuestion textQuestion, MapService mapService)
        {
            Model = textQuestion;

            Model.Service = this;

            MapService = mapService;

            ViewModel = new TextQuestionViewModel(appShell, textQuestion);

            ViewModel.ConfirmedQuestionEvent += OnConfirm;
        }
Example #3
0
        private void SetAsUnlockedWithoutActions()
        {
            if (State == 3)
            {
                return;
            }

            if (FirstlyUnlocked)
            {
                if (Model.PositionsDisplayAfterUnlock != null)
                {
                    MapService.AddNotStops(Model.PositionsDisplayAfterUnlock as List <MapPosition>);
                }

                if (Model.DisplayObjectsRewards != null)
                {
                    foreach (DisplayObjectStopDisplayAfterUnlock displayObject in Model.DisplayObjectsRewards)
                    {
                        ViewModel.AddDisplayObject(displayObject.DisplayObject, (int)displayObject.Position);
                    }
                }
                FirstlyUnlocked = false;
            }


            if (Model.Position != null && PinOfTheStop == null)
            {
                PinOfTheStop = MapService.AddStop(Model.Position, 3, IsVisibleInState2);
            }
            else if (PinOfTheStop != null)
            {
                MapService.SetPinViewModelToState(PinOfTheStop, 3, IsVisibleInState2);
            }

            if (State == 2)
            {
                foreach (PasswordService password in Passwords)
                {
                    password.Unshow();
                }
            }

            State = 3;

            if ((bool)Model.IsFinal)
            {
                GameService.End();
            }
        }
Example #4
0
        private void SetAsUnvisible()
        {
            if (State == 1)
            {
                return;
            }

            if (State == 2 || State == 3)
            {
                ViewModel.RemoveFromBar();
            }

            if (PinOfTheStop != null)
            {
                MapService.SetPinViewModelToState(PinOfTheStop, 1, IsVisibleInState2);
            }

            State = 1;
        }
Example #5
0
        public StopService(Stop stopModel, AppShell appShell, MapService mapService, LocationChecker locationChecker, GameService gameService)
        {
            Model           = stopModel;
            Model.Service   = this;
            ViewModel       = new StopViewModel(appShell, Model.Name);
            MapService      = mapService;
            LocationChecker = locationChecker;
            GameService     = gameService;
            if (Model.Position != null)
            {
                IsVisibleInState2 = Model.Position.IsVisibleAsStopPosition;
            }

            State = 0;
            if ((bool)Model.IsInitial)
            {
                SetAsVisible();
            }
            else
            {
                SetAsUnvisible();
            }
        }
Example #6
0
        private void SetAsUnlocked()
        {
            if (State == 3)
            {
                return;
            }

            if (FirstlyUnlocked)
            {
                if (Model.PositionsDisplayAfterUnlock != null)
                {
                    MapService.AddNotStops(Model.PositionsDisplayAfterUnlock as List <MapPosition>);
                }

                if (Model.DisplayObjectsRewards != null)
                {
                    foreach (DisplayObjectStopDisplayAfterUnlock displayObject in Model.DisplayObjectsRewards)
                    {
                        ViewModel.AddDisplayObject(displayObject.DisplayObject, (int)displayObject.Position);
                    }
                }

                FirstlyUnlocked = false;
            }


            if (Model.Position != null && PinOfTheStop == null)
            {
                PinOfTheStop = MapService.AddStop(Model.Position, 3, IsVisibleInState2);
            }
            else if (PinOfTheStop != null)
            {
                MapService.SetPinViewModelToState(PinOfTheStop, 3, IsVisibleInState2);
            }

            if (Model.Opens != null)
            {
                foreach (StopStop opening in Model.Opens)
                {
                    opening.Opens.Service.ProcessChange(opening.IfUnvisible, opening.IfVisible, opening.IfUnlocked, (int)opening.Value);
                }
            }

            if (Model.Questions != null)
            {
                foreach (Question question in Model.Questions)
                {
                    question.Service.Ask();
                }
            }

            if (State == 2)
            {
                foreach (PasswordService password in Passwords)
                {
                    password.Unshow();
                }
            }

            State = 3;

            if ((bool)Model.IsFinal)
            {
                GameService.End();
            }
        }
Example #7
0
        private void SetAsVisible()
        {
            if (State == 2)
            {
                return;
            }

            if (State == 1 || State == 0)
            {
                ViewModel.AddToBar();
            }
            if (FirstlyVisible)
            {
                if (Model.PositionsDisplayAfterDisplay != null)
                {
                    MapService.AddNotStops(Model.PositionsDisplayAfterDisplay as List <MapPosition>);
                }

                if (Model.DisplayObjectsHints != null)
                {
                    foreach (DisplayObjectStopDisplayAfterDisplay displayObject in Model.DisplayObjectsHints)
                    {
                        ViewModel.AddDisplayObject(displayObject.DisplayObject, (int)displayObject.Position);
                    }
                }

                if (Model.Passwords != null)
                {
                    foreach (PasswordGameRequirement password in Model.Passwords)
                    {
                        var passwordService = new PasswordService(this, password);
                        Passwords.Add(passwordService);
                    }
                }

                FirstlyVisible = false;
            }

            if (Model.Position != null && PinOfTheStop == null)
            {
                PinOfTheStop = MapService.AddStop(Model.Position, 2, IsVisibleInState2);
            }
            else if (PinOfTheStop != null)
            {
                MapService.SetPinViewModelToState(PinOfTheStop, 2, IsVisibleInState2);
            }

            RequierementToUnlock = Model.Passwords.Count;
            RequierementValue    = 0;

            foreach (PasswordService password in Passwords)
            {
                password.AskForPassword();
                password.PasswordCompleted += OnPasswordRequierementDone;
            }

            if (Model.Position != null)
            {
                RequierementToUnlock++;
                var locationToCheck = new LocationToCheck(Model.Position.X, Model.Position.Y, Model.Position.Radius);
                locationToCheck.LocationReached += OnPositionRequierementDone;
                LocationChecker.AddLocation(locationToCheck);
            }
            else if (RequierementToUnlock == 0)
            {
                SetAsUnlocked();
                return;
            }

            State = 2;
        }