Esempio n. 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);
            }
        }
Esempio n. 2
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();
            }
        }
Esempio n. 3
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;
        }