private void StartMethod() { Logger.Add(new Log(this.GetType().Name, MethodBase.GetCurrentMethod().Name, $"New game started")); #region Map Size/Blocks int size; int blocks; if (Int32.TryParse(ConfigurationManager.AppSettings["Map_Blocks"], out blocks)) { Logger.Add(new Log(this.GetType().Name, MethodBase.GetCurrentMethod().Name, $"Map_Blocks loaded from AppConfig - {blocks}")); } else { blocks = 20; Logger.Add(new Log(this.GetType().Name, MethodBase.GetCurrentMethod().Name, $"Map_Blocks set as default - {blocks}")); } if (Int32.TryParse(ConfigurationManager.AppSettings["Map_Size"], out size)) { Logger.Add(new Log(this.GetType().Name, MethodBase.GetCurrentMethod().Name, $"Map_Size loaded from AppConfig - {size}")); } else { size = 20; Logger.Add(new Log(this.GetType().Name, MethodBase.GetCurrentMethod().Name, $"Map_Size set as default - {size}")); } #endregion var tmp = new GanerateServise(size, blocks); // make it look like a square tmp.ResultGrid.Width = MyModel.GridParent.ActualHeight; MyModel.Field = tmp.ResultGrid; _field = new int[size, size]; _field = tmp.Field; _gameWinScore = SetGameWinScore(tmp.Field); if (IsPacmanDie) { IsPacmanDie = !IsPacmanDie; var s = UI.FindChild <Grid>(MyModel.GridParent, "MainField"); MyModel.GridParent.Children.Remove(s); Logger.Add(new Log(this.GetType().Name, MethodBase.GetCurrentMethod().Name, $"Old game field removed")); _score = 0; _ghostAnimation = new List <PointAnimationHelper>(); AnimationHelper = new PointAnimationHelper(); Logger.Add(new Log(this.GetType().Name, MethodBase.GetCurrentMethod().Name, $"Reset all start params")); } MyModel.GridParent.Children.Add(tmp.ResultGrid); Logger.Add(new Log(this.GetType().Name, MethodBase.GetCurrentMethod().Name, $"Game field Added at main View Model window")); pacman = new PacmanEssence(tmp.StartPoint, ImageCreator.CreateImage($@"Materials\Pacman\state1.png")); pacman.NextPoint = pacman.Point; Logger.Add(new Log(this.GetType().Name, MethodBase.GetCurrentMethod().Name, $"Pacman assign to game")); Draw_pacman(tmp.ResultGrid, pacman, true); PointAnimationHelper.FlickerImage(pacman.MainImage, TimeSpan.FromSeconds(0.3)); //pacman._animationStateImage.Add(ImageCreator.CreateImage($@"Materials\Pacman\state1.png")); //pacman._animationStateImage.Add(ImageCreator.CreateImage($@"Materials\Pacman\state2.png")); //StartMouthAnimation(); AbstractGhost.ResetIndex(); InitGhosts(); CreateGhosts(_greenGhostCount, _blueGhostCount, _redGhostCount); }
/// <summary> /// Create instance of game /// </summary> /// <param name="DynamicControls">The panel in which the playing field will be added</param> public GridViewModel(DockPanel DynamicControls) { Logger.Add(new Log(this.GetType().Name, MethodBase.GetCurrentMethod().Name, $"ViewModel Context Created")); _gridModel = new GridModel(); MyModel.GridParent = DynamicControls; StartCommand = new DelegateCommand(StartMethod); ExitCommand = new DelegateCommand <bool?>(ExitMethod); PauseCommand = new DelegateCommand(PauseMethod); MoveCommand = new DelegateCommand <string>(MoveMethod); _totalScore_Viewer = UI.FindChild <TextBlock>(MyModel.GridParent, "totalScore"); _playerName_Viewer = UI.FindChild <TextBlock>(MyModel.GridParent, "pName"); AnimationHelper = new PointAnimationHelper(); Logger.Add(new Log(this.GetType().Name, MethodBase.GetCurrentMethod().Name, $"ViewModel base objects successfully init")); }
private void ExitMethod(bool?closing = false) { try { IsPacmanDie = true; if (closing != true) { Logger.Add(new Log(this.GetType().Name, MethodBase.GetCurrentMethod().Name, $"Player exit game")); (UI.GetTopLevelControl(MyModel.GridParent) as Window).Close(); } else if (closing == true) { Logger.Add(new Log(this.GetType().Name, MethodBase.GetCurrentMethod().Name, $"Player close window")); MenuView menu = new MenuView(); menu.Visibility = Visibility.Visible; } } catch (Exception ex) { Logger.Add(new Log(this.GetType().Name, MethodBase.GetCurrentMethod().Name, $"Error", ex)); } }