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); } }
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(); } }
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(); } }
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; }