public void SaveGame(string fileName) { actionLog = controller.actionLog; roomName = controller.roomNavigation.currentRoom.roomName; inventory = controller.interactableItems.nounsInInventory; inventoryHistory = controller.interactableItems.nounsInInventoryHistory; equipment = controller.interactableItems.nounsInEquipment; score = controller.Score; moves = controller.Moves; BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/" + fileName + ".tbg", FileMode.OpenOrCreate); GameStateInfo myInfo = new GameStateInfo(); //put what ever you're saving as myInfo.whatever //myInfo.gameText = gameText; myInfo.actionLog = actionLog; myInfo.roomName = roomName; myInfo.inventory = inventory; myInfo.inventoryHistory = inventoryHistory; myInfo.equipment = equipment; myInfo.score = score; myInfo.moves = moves; bf.Serialize(file, myInfo); file.Close(); controller.LogStringWithReturn("Game saved as " + fileName); }
public GameFieldViewModel(Game game, GameStateInfo gameStateInfo, INavigation navigation) { GameFieldModel = new GameFieldModel(game, gameStateInfo); Navigation = navigation; GoBackCommand = new Command(GoBack); GameFieldModel.PropertyChanged += (obj, args) => { if (args.PropertyName == "NumTurns") { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("NumTurns")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("GameScoreLabelText")); } else if (args.PropertyName == "TurnState") { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("InfoTurnLabelText")); } else if (args.PropertyName == "IsFinished") { if (IsFinished) { FinishGame(); } PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsFinished")); } }; }
public GameFieldModel(Game game, GameStateInfo gameStateInfo) { serverWorker = ServerWorker.GetServerWorker(); this.Game = game; this.GameStateInfo = gameStateInfo; FillGameTrajectory(); }
/// <summary> /// 状态开始 /// </summary> /// <param name="currStateName"></param> /// <param name="nextStateName"></param> public void OnBeginStateEnter(string currStateName, string nextStateName) { _loadLevelExceptionCount = 0; CreateDynamicManager(); GameStateConf _stateConf = GameStateConf.GetInstance(); if (null == _stateConf) { this.Error("OnBeginStateEnter()::The game state conf is invalid!!!"); return; } GameStateInfo _nextStateInfo = Array.Find( _stateConf.States.ToArray(), c => c.Name == nextStateName); if (null != _nextStateInfo) { List <string> _managerNames = _nextStateInfo.Managers; if ((null != _managerNames) && (0 < _managerNames.Count)) { try { AddDynamicManager(_managerNames.ToArray()); } catch (Exception e) { ShowExceptionPopup(e, _evtOnExceptionPopupConfirm, "AddDynamicManager"); } } } for (int i = 0; i < _constManagers.Count; i++) { IManagerBase manager = _constManagers[i]; try { manager.OnBeginStateEnter(currStateName, nextStateName); } catch (Exception e) { ShowExceptionPopup(e, _evtOnExceptionPopupConfirm, manager.GetType().Name); } } for (int i = 0; i < _dynamicManagers.Count; i++) { IManagerBase mgr = _dynamicManagers[i]; try { mgr.OnBeginStateEnter(currStateName, nextStateName); } catch (Exception e) { ShowExceptionPopup(e, _evtOnExceptionPopupConfirm, mgr.GetType().Name); } } }
public GameField(Game game, GameStateInfo gameStateInfo, INavigation navigation) { InitializeComponent(); ViewModel = new GameFieldViewModel(game, gameStateInfo, navigation); BindingContext = ViewModel; canvasView.PaintSurface += OnCanvasViewPaintSurface; StartGameControls(); NavigationPage.SetHasNavigationBar(this, false); }
//set all values to default private void Restart() { levelControl.Restart(); level = null; stats = null; //setup game info info = new GameStateInfo(); }
private void OnEnable() { //notify game controller that active and that the game controller needs to set the game stats START(this); //get game stats from game controller info = GameController.Instance.GetStateInfo(); points.text = info.points.ToString(); movement.text = info.levelMovementSpeed.ToString(); fireRate.text = info.levelFireRate.ToString(); }
public void SplitGroup(List <string> unitIdList) { if (unitIdList == null || unitIdList.Count == 0) { return; } var wp = new Waypoint(); var newGroup = new Group(); var activeWaypoint = MainUnit.GetActiveWaypoint(); if (activeWaypoint != null) { wp = activeWaypoint.Clone(); } else { wp = new Waypoint(MainUnit.Position.Offset(new PositionOffset(0, 1000, 0))); } // Cache the owner player as the group might be marked for deletion if only one unit is remaining after splitting from group. Player ownerPlayer = OwnerPlayer; foreach (var id in unitIdList) { var unit = ownerPlayer.GetUnitById(id); if (unit != null) { unit.SetDirty(GameConstants.DirtyStatus.UnitChanged); unit.FormationPositionId = string.Empty; RemoveUnit(unit); if (wp != null) { unit.MovementOrder = new MovementOrder(wp); } newGroup.AddUnit(unit); } } ownerPlayer.AddGroup(newGroup); SetDirty(GameConstants.DirtyStatus.UnitChanged); newGroup.SetDirty(GameConstants.DirtyStatus.NewlyCreated); if (Formation != null) { newGroup.Formation = Formation.Clone(); } newGroup.AutoAssignUnitsToFormation(); newGroup.Name = Name + " (2)"; GameManager.Instance.Log.LogDebug( string.Format("Group.SplitGroup: Group {0} split. New group formed: {1}.", ToString(), newGroup.ToString())); var splitMsg = new GameStateInfo(GameConstants.GameStateInfoType.GroupHasBeenSplit, this.Id, newGroup.Id); ownerPlayer.Send(splitMsg); newGroup.RemoveIfSingleUnit(); }
public void newGame() { deleteSavedGame(); currentGameStateInfo = new GameStateInfo(); addEmptyWorkBench(); createDefaultInventory(); createRandomHeroes(); saveContentInfo(); reloadScene(); }
public override void Tick(double timer) { base.Tick(timer); if (this.IsMarkedForDeletion || this.Position == null || ReadyInSec > 0 || GameManager.Instance.Game == null) { return; } var timePassedSinceLastTickSec = GameManager.Instance.Game.GameCurrentTime.Subtract(_timeLastTick).TotalSeconds; if (timePassedSinceLastTickSec < 10) { return; } _timeLastTick = DateTime.FromBinary(GameManager.Instance.Game.GameCurrentTime.ToBinary()); var enemyUnits = OwnerPlayer.GetEnemyUnitsInAreaByUnitType(GameConstants.UnitType.SurfaceShip, this.Position.Coordinate, GameConstants.MAX_MINE_DETECTION_RANGE_M); foreach (var unit in enemyUnits) { if (unit.SupportsRole(GameConstants.Role.MineCountermeasures)) { var msgToMineOwner = new GameStateInfo(GameConstants.GameStateInfoType.MineDestroyedByEnemy, this.Id); OwnerPlayer.Send(msgToMineOwner); var msgToMineDestroyer = new GameStateInfo(GameConstants.GameStateInfoType.MineDestroyedByUs, unit.Id); unit.OwnerPlayer.Send(msgToMineDestroyer); //var msg = OwnerPlayer.CreateNewMessage( // string.Format("A {0} has been destroyed by enemy mine countermeasures.", ToShortString())); //msg.Position = this.Position.Clone(); //var msg2 = unit.OwnerPlayer.CreateNewMessage( // string.Format("An enemy {0} has been destroyed by mine countermeasures from {1}.", // UnitClass.UnitClassShortName, unit.ToShortString())); //msg2.Position = unit.Position.Clone(); this.IsMarkedForDeletion = true; return; } double distanceM = MapHelper.CalculateDistanceM(this.Position.Coordinate, unit.Position.Coordinate); if (distanceM <= GameConstants.MAX_MINE_IMPACT_RANGE_M) { GameManager.Instance.Log.LogDebug( string.Format("Mine->Tick() reports IMPACT between mine {0} and unit {1}", ToShortString(), unit.ToShortString())); unit.InflictDamageFromProjectileHit(this); this.IsMarkedForDeletion = true; return; } } }
private bool SaveGameState(GameStateInfo gameStateInfo) { try { this.unitOfWork.GameStateSafes.Add(gameStateInfo); this.unitOfWork.Commit(); } catch (Exception) { return(false); } return(true); }
// Use this for initialization void Start() { //load saved game //if saved null, create new GameStateInfo currentGameStateInfo = loadSavedGame(); if (currentGameStateInfo == null) { currentGameStateInfo = new GameStateInfo(); } loadWorkBenches(); loadInventory(); loadHeroes(); }
public bool SaveGame(string safeName) { var time = DateTime.Now; var currentRegion = this.parentEngine.RegionEntities.GetCurrentRegionName(); var player = this.parentEngine.RegionEntities.Player; var regionStateList = this.GetRegionStates(); var gameState = new GameStateInfo( safeName, time, currentRegion, player as CharacterUnit, regionStateList); return(this.SaveGameState(gameState)); }
GameStateInfo loadSavedGame() { GameStateInfo savedGameState = null; if (File.Exists(Application.persistentDataPath + "/" + "savegame.gam")) { BinaryFormatter bf = new BinaryFormatter(); FileStream fs = File.Open(Application.persistentDataPath + "/" + "savegame.gam", FileMode.Open); savedGameState = (GameStateInfo)bf.Deserialize(fs); fs.Close(); } return(savedGameState); }
private async Task <GameStateInfo> GetGameState(int idGame) { try { GameStateInfo currentResponse = await PostData <GameStateInfo>(GameStateCommand, new Dictionary <string, object>() { { "id_game", idGame } } ); return(currentResponse); } catch (System.Net.WebException) { return(null); } }
public static ErrorType GetTargetEntityError(Entity source, Entity target) { if (!s_initialized) { return(ErrorType.NONE); } Player owningPlayer = GetOwningPlayer(source); if (owningPlayer == null) { return(ErrorType.NONE); } SourceEntityInfo sourceInfo = source.ConvertToSourceInfo(GetPlayRequirementInfo(source), null); PlayerInfo playerInfo = owningPlayer.ConvertToPlayerInfo(); GameStateInfo gameInfo = GameState.Get().ConvertToGameStateInfo(); Marshaled_PlayErrorsParams playErrorsParams = new Marshaled_PlayErrorsParams(sourceInfo, playerInfo, gameInfo); Marshaled_TargetEntityInfo info4 = Marshaled_TargetEntityInfo.ConvertFromTargetEntityInfo(target.ConvertToTargetInfo()); List <Marshaled_TargetEntityInfo> marshaledEntitiesInPlay = GetMarshaledEntitiesInPlay(); return(DLL_GetTargetEntityError(playErrorsParams, info4, marshaledEntitiesInPlay.ToArray(), marshaledEntitiesInPlay.Count)); }
public static ErrorType GetPlayEntityError(Entity source) { Log.PlayErrors.Print(string.Concat(new object[] { "GetPlayEntityError (", s_initialized, ") ", source }), new object[0]); if (!s_initialized) { return(ErrorType.NONE); } Player owningPlayer = GetOwningPlayer(source); if (owningPlayer == null) { return(ErrorType.NONE); } SourceEntityInfo sourceInfo = source.ConvertToSourceInfo(GetPlayRequirementInfo(source), null); PlayerInfo playerInfo = owningPlayer.ConvertToPlayerInfo(); GameStateInfo gameInfo = GameState.Get().ConvertToGameStateInfo(); Marshaled_PlayErrorsParams playErrorsParams = new Marshaled_PlayErrorsParams(sourceInfo, playerInfo, gameInfo); List <Marshaled_TargetEntityInfo> marshaledEntitiesInPlay = GetMarshaledEntitiesInPlay(); List <Marshaled_SourceEntityInfo> marshaledSubCards = GetMarshaledSubCards(source); return(DLL_GetPlayEntityError(playErrorsParams, marshaledSubCards.ToArray(), marshaledSubCards.Count, marshaledEntitiesInPlay.ToArray(), marshaledEntitiesInPlay.Count)); }
public void LoadGame(string fileName) { if (File.Exists(Application.persistentDataPath + "/" + fileName + ".tbg")) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/" + fileName + ".tbg", FileMode.Open); GameStateInfo myLoadedInfo = (GameStateInfo)bf.Deserialize(file); //gameText = myLoadedInfo.gameText; actionLog = myLoadedInfo.actionLog; roomName = myLoadedInfo.roomName; inventory = myLoadedInfo.inventory; inventoryHistory = myLoadedInfo.inventoryHistory; equipment = myLoadedInfo.equipment; score = myLoadedInfo.score; moves = myLoadedInfo.moves; SetUpGame(fileName); } else { controller.LogStringWithReturn("Could not find saved game: " + fileName); } }
private void HandleGameStateInfo(IMarshallable dataReceived) { GameStateInfo gameInfo = dataReceived as GameStateInfo; if (gameInfo != null) { if (gameInfo.InfoType == GameConstants.GameStateInfoType.UnitIsDestroyed) { if (_selectedUnitInfo != null && _selectedUnitInfo.Id == gameInfo.Id) { _selectedUnitInfo = null; } _Units.RemoveAll(u => u.Id == gameInfo.Id); lstUnits.Items.Refresh(); } else if (gameInfo.InfoType == GameConstants.GameStateInfoType.DetectedContactIsLost || gameInfo.InfoType == GameConstants.GameStateInfoType.DetectedContactIsDestroyed) { _Detections.RemoveAll(d => d.Id == gameInfo.Id); lstDetections.Items.Refresh(); } else if (gameInfo.InfoType == GameConstants.GameStateInfoType.DetectedContactGroupIsLost) { _DetectedGroups.RemoveAll(d => d.Id == gameInfo.Id); } else if (gameInfo.InfoType == GameConstants.GameStateInfoType.AircraftIsLanded) { _Units.RemoveAll(u => u.Id == gameInfo.Id); lstUnits.Items.Refresh(); ShowInfo("Aircraft has landed : " + gameInfo.Id); } else if (gameInfo.InfoType == GameConstants.GameStateInfoType.MissileLaunch) { } ShowInfo("***GameStateInfo: " + gameInfo.ToString()); } }
public void Init() { mArchievementSystem = new ArchievementSystem(); mCampSystem = new CampSystem(); mCharacterSystem = new CharacterSystem(); mEnergySystem = new EnergySystem(); mStageSystem = new StageSystem(); mCampInfoUI = new CampInfoUI(); mGamePauseUI = new GamePauseUI(); mGameStateInfo = new GameStateInfo(); mSoldierInfoUI = new SoldierInfoUI(); mArchievementSystem.Init(); mCampSystem.Init(); mCharacterSystem.Init(); mEnergySystem.Init(); mStageSystem.Init(); mCampInfoUI.Init(); mGamePauseUI.Init(); mGameStateInfo.Init(); mSoldierInfoUI.Init(); }
public UserPage(ServerWorker _serverWorker, SystemSettings _systemSettings) { NavigationPage.SetHasNavigationBar(this, false); this.systemSettings = _systemSettings; this.serverWorker = _serverWorker; this.Title = "Started games"; userprofilStackLayout = new StackLayout() { VerticalOptions = LayoutOptions.Fill, HorizontalOptions = LayoutOptions.Fill }; StackLayout globalStackLayout = new StackLayout() { VerticalOptions = LayoutOptions.Fill, HorizontalOptions = LayoutOptions.Fill }; relativeLayout = new RelativeLayout() { VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.Fill }; absoluteLayout = new AbsoluteLayout() { VerticalOptions = LayoutOptions.Fill, HorizontalOptions = LayoutOptions.Fill }; userName = new Label() { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Start, TextColor = Color.White, FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)), FontAttributes = FontAttributes.Bold, Margin = new Thickness(20, 10, 20, 10), }; var statisticsInfoLabel = new Label() { HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.Center, //BackgroundColor = Color.FromHex("#39bafa"), TextColor = Color.White, FontAttributes = FontAttributes.Bold, TextDecorations = TextDecorations.Underline, HorizontalTextAlignment = TextAlignment.Center, Text = "Statistics", FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), Margin = new Thickness(0, 3, 0, 3), }; performanceCenterLabel = new Label() { HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.Center, //BackgroundColor = Color.FromHex("#39bafa"), TextColor = Color.White, FontAttributes = FontAttributes.Bold, HorizontalTextAlignment = TextAlignment.Center, FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), }; performanceBorderLabel = new Label() { HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.Center, //BackgroundColor = Color.FromHex("#39bafa"), TextColor = Color.White, FontAttributes = FontAttributes.Bold, HorizontalTextAlignment = TextAlignment.Center, FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), }; RatingLabel = new Label() { HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.Center, //BackgroundColor = Color.FromHex("#39bafa"), TextColor = Color.White, FontAttributes = FontAttributes.Bold, HorizontalTextAlignment = TextAlignment.Center, FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), }; var ratingInfoLabel = new Label() { HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.Center, //BackgroundColor = Color.FromHex("#39bafa"), TextColor = Color.White, FontAttributes = FontAttributes.Bold, HorizontalTextAlignment = TextAlignment.Center, Text = "Rating", FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), }; Image performanceBorderImage = new Image() { HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.Center, //BackgroundColor = Color.FromHex("#39bafa"), Source = "top_score_border.png", Margin = 0, HeightRequest = ratingInfoLabel.FontSize }; Image performanceCenterImage = new Image() { HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.Center, //BackgroundColor = Color.FromHex("#39bafa"), Source = "top_score_center.png", Margin = 0, HeightRequest = ratingInfoLabel.FontSize }; Grid gridPlayerInfo = new Grid { RowDefinitions = { new RowDefinition { Height = GridLength.Auto }, }, ColumnDefinitions = { new ColumnDefinition { Width = new GridLength(3, GridUnitType.Star) }, new ColumnDefinition { Width = new GridLength(3, GridUnitType.Star) }, }, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.Start, //ColumnSpacing = 1, RowSpacing = 0, Margin = new Thickness(0, 10, 5, 0) }; Grid gridPlayerScore = new Grid { ColumnDefinitions = { new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }, new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }, new ColumnDefinition { Width = new GridLength(1.3, GridUnitType.Star) }, }, RowDefinitions = { new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, }, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.Start, //ColumnSpacing = 5, RowSpacing = 0, Margin = new Thickness(0, 0, 0, 0) }; gridPlayerScore.Children.Add(performanceCenterLabel, 0, 2); Grid.SetColumnSpan(performanceCenterLabel, 1); Grid.SetRowSpan(performanceCenterLabel, 1); gridPlayerScore.Children.Add(performanceCenterImage, 0, 1); Grid.SetColumnSpan(performanceCenterImage, 1); Grid.SetRowSpan(performanceCenterImage, 1); gridPlayerScore.Children.Add(performanceBorderLabel, 1, 2); Grid.SetColumnSpan(performanceBorderLabel, 1); Grid.SetRowSpan(performanceBorderLabel, 1); gridPlayerScore.Children.Add(performanceBorderImage, 1, 1); Grid.SetColumnSpan(performanceBorderImage, 1); Grid.SetRowSpan(performanceBorderImage, 1); gridPlayerScore.Children.Add(RatingLabel, 2, 2); Grid.SetColumnSpan(RatingLabel, 1); Grid.SetRowSpan(RatingLabel, 1); gridPlayerScore.Children.Add(ratingInfoLabel, 2, 1); Grid.SetColumnSpan(ratingInfoLabel, 1); Grid.SetRowSpan(ratingInfoLabel, 1); gridPlayerScore.Children.Add(statisticsInfoLabel, 0, 0); Grid.SetColumnSpan(statisticsInfoLabel, 3); Grid.SetRowSpan(statisticsInfoLabel, 1); gridPlayerInfo.Children.Add(userName, 0, 0); Grid.SetColumnSpan(userName, 1); Grid.SetRowSpan(userName, 1); gridPlayerInfo.Children.Add(gridPlayerScore, 1, 0); Grid.SetColumnSpan(gridPlayerScore, 1); Grid.SetRowSpan(gridPlayerScore, 1); var actionStandings = new TapGestureRecognizer(); actionStandings.Tapped += async(s, e) => { await Navigation.PushAsync(new StandingsPage(serverWorker, systemSettings)); }; gridPlayerScore.GestureRecognizers.Add(actionStandings); StackLayout stackLayoutListView = new StackLayout() { VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.Fill, Margin = new Thickness(10, 0, 0, 0), }; gamesListView = new ListView { VerticalOptions = LayoutOptions.CenterAndExpand, ItemTemplate = new DataTemplate(typeof(DateCellView)), IsPullToRefreshEnabled = true, }; gameListViewEmptyMessage = new Label { VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.Center, TextColor = Color.White, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), FontAttributes = FontAttributes.Bold, Margin = new Thickness(20, 10, 20, 10), Text = "Here we place your current games.\nTo play tap bot or friend.", HorizontalTextAlignment = TextAlignment.Center, IsVisible = false }; gamesListView.RefreshCommand = new Command(async() => { await UpdateGameList(); gamesListView.IsRefreshing = false; }); _ = UpdateGameList(); gamesListView.ItemSelected += async delegate { if ((ElementsOfViewCell)gamesListView.SelectedItem == null) { return; } if (isGameStarted) { return; } Game game = await GameProcesses.MakeSavedGame(serverWorker, ((ElementsOfViewCell)gamesListView.SelectedItem).game.IdGame); bool cancelGame = await GameProcesses.StartGame(serverWorker, game); if (!cancelGame) { GameStateInfo gameStateInfo = await serverWorker.TaskGetGameState(game.IdGame); await Navigation.PushAsync(new GameField(serverWorker, systemSettings, game, gameStateInfo)); isGameStarted = true; } gamesListView.SelectedItem = null; //await UpdateGameList(); }; stackLayoutListView.Children.Add(gameListViewEmptyMessage); stackLayoutListView.Children.Add(gamesListView); StackLayout buttonStack = new StackLayout() { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Fill, Margin = new Thickness(20, 10, 20, 10), Orientation = StackOrientation.Horizontal }; var stackLayoutPlayWithAnotherPlayer = new StackLayout { Spacing = 0, HorizontalOptions = LayoutOptions.CenterAndExpand, }; Label labelPlayWithAnotherPlayer = new Label() { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, TextColor = Color.White, FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), FontAttributes = FontAttributes.Bold, Text = "Friend" }; ImageButton PlayWithAnotherPlayer = new ImageButton() { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, //Text = "PVP", BackgroundColor = Color.FromHex("#39bafa"),//7ad3ff //TextColor = Color.White, IsEnabled = true, Source = "pvp.png", HeightRequest = 30, WidthRequest = 60, Padding = 0, }; PlayWithAnotherPlayer.Clicked += async delegate { if (isGameStarted) { return; } isGameStarted = true; await Navigation.PushAsync(new RealPlayerChoicePage(serverWorker, systemSettings)); }; var stackLayoutPlayWithBot = new StackLayout { Spacing = 0, HorizontalOptions = LayoutOptions.CenterAndExpand, }; Label labelPlayWithBot = new Label() { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, TextColor = Color.White, FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), FontAttributes = FontAttributes.Bold, Text = "Bot" }; ImageButton PlayWithBot = new ImageButton() { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, //Text = "Bot", BackgroundColor = Color.FromHex("#39bafa"), //TextColor = Color.White, Source = "bot.png", HeightRequest = 30, WidthRequest = 60, Padding = 0, }; PlayWithBot.Clicked += async delegate { if (isGameStarted) { return; } isGameStarted = true; Game game = await GameProcesses.MakeGameWithBot(serverWorker); GameStateInfo gameStateInfo = await serverWorker.TaskGetGameState(game.IdGame); await Navigation.PushAsync(new GameField(serverWorker, systemSettings, game, gameStateInfo)); await UpdateGameList(); }; /*var guide = new CarouselView * { * IsVisible = false, * IsEnabled = false, * HorizontalScrollBarVisibility = ScrollBarVisibility.Always * };*/ /*var guideImages = new ObservableCollection<CarouselItem>(); * guideImages.Add(new CarouselItem { Picture = ImageSource.FromFile("guidePlayWithBot.png") }); * guideImages.Add(new CarouselItem { Picture = ImageSource.FromFile("guidePlayWithFriend.png") }); * guideImages.Add(new CarouselItem { Picture = ImageSource.FromFile("guideRating.png") }); * guideImages.Add(new CarouselItem { Picture = ImageSource.FromFile("guideGoal.png") }); * guideImages.Add(new CarouselItem { Picture = ImageSource.FromFile("guideMove.png") }); * guideImages.Add(new CarouselItem { Picture = ImageSource.FromFile("guideScore.png") });*/ StackLayout stackLayoutHelp = new StackLayout { Spacing = 0, HorizontalOptions = LayoutOptions.CenterAndExpand, }; Label helpLabel = new Label { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, TextColor = Color.White, FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), FontAttributes = FontAttributes.Bold, Text = "Help" }; ImageButton helpButton = new ImageButton { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, BackgroundColor = Color.FromHex("#39bafa"), Source = "help.png", //IsEnabled = true, HeightRequest = 30, WidthRequest = 60, Padding = 0 }; Label infoLabel = new Label { Text = "Press button", TextColor = Color.White, HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.Center, }; introGuide = new List <GuideStep> { new GuideStep(null, "Welcome to Random Walk!\nTap to see game guide"), new GuideStep(stackLayoutHelp, "Check out our guide!"), new GuideStep(stackLayoutPlayWithBot, "Play with a bot!"), new GuideStep(stackLayoutPlayWithAnotherPlayer, "Play with a friend!"), new GuideStep(gridPlayerScore, "Check out your rating!"), new GuideStep(null, "Try to play with a bot now =)") }; SKCanvasView canvasView = new SKCanvasView { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Fill, Margin = new Thickness(0, 0, 0, 0), IsEnabled = false, IsVisible = false, HeightRequest = systemSettings.ScreenHeight, WidthRequest = systemSettings.ScreenWidth, }; tourGuide = new TourGuide(canvasView); if (!Application.Current.Properties.ContainsKey("FirstUse")) { Application.Current.Properties["FirstUse"] = false; Application.Current.SavePropertiesAsync(); tourGuide.StartIntroGuide(introGuide); } helpButton.Clicked += delegate { //StartGuide(guideImages, guide); List <GuideStep> introGuideShorten = new List <GuideStep> { new GuideStep(null, "Welcome to Random Walk!\nTap to see game guide"), new GuideStep(stackLayoutPlayWithBot, "Play with a bot!"), new GuideStep(stackLayoutPlayWithAnotherPlayer, "Play with a friend!"), new GuideStep(gridPlayerScore, "Check out your rating!"), new GuideStep(null, "Enjoy the game =)") }; tourGuide.StartIntroGuide(introGuideShorten); }; stackLayoutPlayWithAnotherPlayer.Children.Add(PlayWithAnotherPlayer); stackLayoutPlayWithAnotherPlayer.Children.Add(labelPlayWithAnotherPlayer); stackLayoutPlayWithBot.Children.Add(PlayWithBot); stackLayoutPlayWithBot.Children.Add(labelPlayWithBot); stackLayoutHelp.Children.Add(helpButton); stackLayoutHelp.Children.Add(helpLabel); buttonStack.Children.Add(stackLayoutPlayWithAnotherPlayer); buttonStack.Children.Add(stackLayoutPlayWithBot); buttonStack.Children.Add(stackLayoutHelp); userprofilStackLayout.Children.Add(gridPlayerInfo); userprofilStackLayout.Children.Add(stackLayoutListView); userprofilStackLayout.Children.Add(buttonStack); //globalStackLayout.Children.Add(userprofilStackLayout); //globalStackLayout.Children.Add(canvasView); //absoluteLayout.Children.Add(globalStackLayout, new Rectangle(0, 0, App.ScreenWidth, App.ScreenHeight)); //absoluteLayout.Children.Add(canvasView, new Rectangle(0, 0, App.ScreenWidth, App.ScreenHeight)); //absoluteLayout.Children.Add(buttonStack, new Rectangle(0, App.ScreenHeight - 120, App.ScreenWidth, PlayWithBot.Height)); relativeLayout.Children.Add(userprofilStackLayout, xConstraint: Constraint.Constant(0), yConstraint: Constraint.Constant(0), widthConstraint: Constraint.RelativeToParent((parent) => { return(parent.Width); }), heightConstraint: Constraint.RelativeToParent((parent) => { return(parent.Height); })); relativeLayout.Children.Add(canvasView, xConstraint: Constraint.Constant(0), yConstraint: Constraint.Constant(0), widthConstraint: Constraint.RelativeToParent((parent) => { return(parent.Width); }), heightConstraint: Constraint.RelativeToParent((parent) => { return(parent.Height); })); Content = relativeLayout; }
public void Setup(SO_LevelPattern levelPattern, Transform map, SO_Drops allDrops, GameStateInfo info) { //setup components timer = new TimeManager(timerUI, levelTime); points = new PointsManager(pointsUI); spawn = new SpawnManager(this, levelPattern, map); enemy = new EnemyManager(spawn); drop = new DropManager(allDrops, info.levelDropRate); //setup player player.Setup(playerHealthUI, info); isActive = true; }
public RealPlayerChoicePage(ServerWorker _serverWorker, SystemSettings systemSettings) { serverWorker = _serverWorker; this.BackgroundColor = Color.FromHex("#39bafa"); NavigationPage.SetHasNavigationBar(this, false); /*Grid grid = new Grid * { * RowDefinitions = * { * new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, * new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, * new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, * new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, * new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, * new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, * new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, * new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, * new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, * new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, * new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, * new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, * new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, * new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, * new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, * }, * ColumnDefinitions = * { * new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }, * new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }, * new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }, * }, * Margin = new Thickness(5, 15, 5, 15), * };*/ var stackLayout = new StackLayout { VerticalOptions = LayoutOptions.Fill, HorizontalOptions = LayoutOptions.Fill, Margin = new Thickness(10, 0, 10, 0), Spacing = 0, }; Label headLabel = new Label() { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.CenterAndExpand, Text = "Play with friend", TextColor = Color.White, FontAttributes = FontAttributes.Bold, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), Margin = new Thickness(0, 10), }; Entry entryLogin = new Entry() { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand, Placeholder = "Enter player login", TextColor = Color.White, BackgroundColor = Color.FromHex("#39bafa"), PlaceholderColor = Color.LightGray, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), Margin = new Thickness(0, 5), }; //Подумай над удалением после выбора entryLogin.TextChanged += async delegate { try { if (entryLogin != null && entryLogin.Text != null && entryLogin.Text.Length > 0 && !hasLoginSelected) { playersList = await serverWorker.TaskGetPlayerList(entryLogin.Text); if (playersList != null) { List <ElementsOfViewCell> currentElementsList = new List <ElementsOfViewCell>(); for (int i = 0; i < playersList.Count; i++) { currentElementsList.Add(new ElementsOfViewCell(playersList[i].Login, playersList[i].IdPlayer)); } listPlayer.ItemsSource = currentElementsList; listPlayer.SelectedItem = null; } else { listPlayer.ItemsSource = null; } } else { listPlayer.ItemsSource = null; if (hasLoginSelected) { hasLoginSelected = false; } } } catch (Exception ex) { string exceptionStackTrace = ex.StackTrace; } }; listPlayer = new ListView { VerticalOptions = LayoutOptions.FillAndExpand }; listPlayer.ItemTemplate = new DataTemplate(typeof(DateCellView)); listPlayer.ItemSelected += delegate { hasLoginSelected = true; if ((ElementsOfViewCell)listPlayer.SelectedItem == null) { return; } string selectedLogin = ((ElementsOfViewCell)listPlayer.SelectedItem).Login; selectedIdPlayer = ((ElementsOfViewCell)listPlayer.SelectedItem).IdPlayer; entryLogin.Text = selectedLogin; listPlayer.ItemsSource = null; listPlayer.SelectedItem = null; }; //listPlayer.ItemsSource = Button backButton = new Button() { Text = "Back", TextColor = Color.White, FontAttributes = FontAttributes.Bold, BackgroundColor = Color.FromHex("#69c6f5") }; backButton.Clicked += async delegate { await Navigation.PopAsync(); }; Button playButton = new Button() { Text = "Play!", TextColor = Color.White, FontAttributes = FontAttributes.Bold, BackgroundColor = Color.FromHex("#69c6f5"), HeightRequest = 40, VerticalOptions = LayoutOptions.Center, }; playButton.Clicked += async delegate { //проверим введённый ник if (playersList != null) { selectedIdPlayer = -1; foreach (var player in playersList) { if (player.Login == entryLogin.Text) { selectedIdPlayer = player.IdPlayer; } } } if (entryLogin.Text == "" || entryLogin.Text is null || selectedIdPlayer != -1) // !(await serverWorker.TaskCheckLogin(entryLogin.Text)) { Game game = await GameProcesses.MakeGameWithPlayer(serverWorker, selectedIdPlayer); cancelGame = await GameProcesses.StartGame(serverWorker, game); if (!cancelGame) { GameStateInfo gameStateInfo = await serverWorker.TaskGetGameState(game.IdGame); Navigation.RemovePage(this); await Navigation.PushAsync(new GameField(serverWorker, systemSettings, game, gameStateInfo)); isGameStarted = true; } else { await serverWorker.TaskCancelGame(game.IdGame); } }
public void Setup(RectTransform healthUI, GameStateInfo info) { playerInfo = info; UpgradesController u = UpgradesController.Instance; healthMax = u.GetHealthValue(info.levelHealth); healthCurrent = healthMax; this.healthUI = healthUI; movementSpeed = u.GetMovementValue(info.levelMovementSpeed); bullet.AdjustFireRate(u.GetFireRateValue(info.levelFireRate)); //create object pool for bullets bullet.Setup(); //NEW INPUT SYSTEM input = new Input_Gameplay(); input.GamePlay.Exit.performed += (ctx) => { //temporary so player can exit level DEATH(); }; input.GamePlay.Move.performed += (ctx) => { velocity = (transform.forward * ctx.ReadValue <Vector2>().y + transform.right * ctx.ReadValue <Vector2>().x).normalized; }; input.GamePlay.Aim.performed += (ctx) => { local = (transform.forward * ctx.ReadValue <Vector2>().y + transform.right * ctx.ReadValue <Vector2>().x).normalized; //Debug.Log($"<color==green>Hello World!!</color>"); }; input.GamePlay.AimMouse.performed += (ctx) => { Debug.Log($"<color=white>{ctx.ReadValue<Vector2>()}</color>"); Vector2 dir = (ctx.ReadValue <Vector2>() - new Vector2(Screen.width / 2f, Screen.height / 2f)).normalized; local = (transform.forward * dir.y + transform.right * dir.x).normalized; }; input.GamePlay.Fire.started += (ctx) => { bullet.BeginFire(body); }; input.GamePlay.Fire.canceled += (ctx) => { bullet.StopFire(); }; input.GamePlay.Enable(); //set values map = GameController.Instance.GetMap().transform; //sketchy... transform.position = map.GetChild(0).transform.position; mapLayer = GameController.Instance.GetMapLayer(); obstacleLayer = GameController.Instance.GetObstacleLayer(); //make sure player is setup correctly RaycastHit hit; if (Physics.Raycast(transform.position, (map.position - transform.position).normalized, out hit, float.PositiveInfinity, mapLayer)) { transform.position = hit.point + hit.normal; transform.rotation = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation; } }
private void AdjustStats() { //grab updated info from statsManager, and set to game state info = stats.GetStats(); }
private void HandleGameStateInfo(IMarshallable dataReceived) { //GameManager.Instance.MessageManager.AddMessage(dataReceived.ToString(), GameManager.MessageTypes.Game, null); GameStateInfo gameInfo = dataReceived as GameStateInfo; if (gameInfo != null) { switch (gameInfo.InfoType) { case CommsMarshaller.GameStateInfoType.UnitIsDestroyed: PlayerUnit unit = GameManager.Instance.UnitManager.FindUnitById(gameInfo.Id); if (unit != null) { unit.Kill(true); } //~ ShowMessage("GameStateInfo object, UnitIsDestroyed"); break; case CommsMarshaller.GameStateInfoType.DetectedContactIsLost: //~ ShowMessage("GameStateInfo object, DetectedContactIsLost"); Debug.Log(string.Format("Lost detection Id: {0} - Time:{1}", gameInfo.Id, Time.time)); Enemy e = GameManager.Instance.UnitManager.FindEnemyById(gameInfo.Id); if (e != null) { e.Kill(); } else { Debug.Log("Lost contact with unit not in enemy list. Error?"); } break; case CommsMarshaller.GameStateInfoType.AircraftIsLanded: { PlayerUnit launchPlatform = GameManager.Instance.UnitManager.FindUnitById(gameInfo.SecondaryId); PlayerUnit aircraft = GameManager.Instance.UnitManager.FindUnitById(gameInfo.Id); Debug.Log(string.Format("Aircraft has landed: {0} on {1}", aircraft.Info.UnitName, launchPlatform.Info.UnitName)); if (aircraft != null) { Debug.Log(string.Format("Killing off unit: {0}. ", aircraft.Info.UnitName)); aircraft.Kill(false); Debug.Log(string.Format("{0} killed ", aircraft.Info.UnitName)); } else { Debug.Log("Aircraft is null"); break; } //gameInfo. if (launchPlatform != null) { AnimationLauncher al = launchPlatform.GetComponent <AnimationLauncher>(); Debug.Log(string.Format("Animation launcher is on: {0}", al.gameObject.name)); if (al != null) { UnitClass uc = GameManager.Instance.GetUnitClass(aircraft.Info.UnitClassId); Debug.Log(string.Format("Unitclass found: {0}. ", uc.UnitClassShortName)); al.TakeOffMode = uc.UnitType == GameConstants.UnitType.Helicopter ? AnimationLauncher.AnimMode.HelicopterLanding : AnimationLauncher.AnimMode.FixedWingLanding; Debug.Log(string.Format("Changed takeoffmode to: {0}. Attempting launch...", al.TakeOffMode.ToString())); al.LaunchAnimation(); Debug.Log(string.Format("Animation launched...")); } else { Debug.Log("AnimationLauncher is null"); } } else { Debug.Log("Launchplatform is null"); } //if (carrier != null) //{ // GameManager.Instance.UnitManager.SelectedUnit = carrier; //} //~ ShowMessage("GameStateInfo object, AircraftIsLanded"); break; } case CommsMarshaller.GameStateInfoType.AircraftTakeoff: { PlayerUnit launchPlatform = GameManager.Instance.UnitManager.FindUnitById(gameInfo.SecondaryId); //gameInfo. if (launchPlatform != null) { AnimationLauncher al = launchPlatform.GetComponent <AnimationLauncher>(); if (al != null) { UnitClass uc = GameManager.Instance.GetUnitClass(gameInfo.UnitClassId); al.TakeOffMode = uc.UnitType == GameConstants.UnitType.Helicopter ? AnimationLauncher.AnimMode.HelicopterTakeOff : AnimationLauncher.AnimMode.FixedWingTakeOff; al.LaunchAnimation(); } } break; } case CommsMarshaller.GameStateInfoType.MissileLaunch: PlayerUnit shooter = GameManager.Instance.UnitManager.FindUnitById(gameInfo.SecondaryId); if (shooter != null) { shooter.FireMissile(); } else { Debug.Log(gameInfo.SecondaryId + " is not a unit here"); } break; } } }
public GameHistoryPage(ServerWorker _serverWorker, SystemSettings _systemSettings) { serverWorker = _serverWorker; systemSettings = _systemSettings; NavigationPage.SetHasNavigationBar(this, false); this.Title = "Games history"; this.BackgroundColor = Color.FromHex("#39bafa"); gamesListView = new ListView(); StackLayout stackLayout = new StackLayout() { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Fill, Margin = new Thickness(10, 10, 0, 10), }; stackLayout.Children.Add(gamesListView); gameListViewEmptyMessage = new Label { VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.Center, TextColor = Color.White, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), FontAttributes = FontAttributes.Bold, Margin = new Thickness(20, 10, 20, 10), Text = "Here we place your finished games.\nThanks for playing =)", HorizontalTextAlignment = TextAlignment.Center, IsVisible = false }; stackLayout.Children.Add(gameListViewEmptyMessage); gamesListView.ItemTemplate = new DataTemplate(typeof(UserPage.DateCellView)); gamesListView.ItemSelected += async delegate { if ((UserPage.ElementsOfViewCell)gamesListView.SelectedItem == null) { return; } if (isGameStarted) { return; } isGameStarted = true; Game game = await GameProcesses.MakeSavedGame(serverWorker, ((UserPage.ElementsOfViewCell)gamesListView.SelectedItem).game.IdGame); //await GameProcesses.StartGame(serverWorker, game, () => false); GameStateInfo gameStateInfo = await serverWorker.TaskGetGameState(game.IdGame); await Navigation.PushAsync(new GameField(serverWorker, systemSettings, game, gameStateInfo)); gamesListView.SelectedItem = null; await UpdateGameList(); //filesList.SelectedItem = null; }; gamesListView.ItemsSource = customListViewRecords; _ = UpdateGameList(); this.Content = stackLayout; }