Example #1
0
        /// <summary>
        ///  Move Ghost to him next  path point with custom speed
        /// </summary>
        /// <param name="ghost">Ghost what moving</param>
        /// <param name="speed">desired speed</param>
        public void MoveGost(AbstractGhost ghost, Speeds speed)
        {
            if (_pathIndex == 0)//ExitPoint
            {
                return;
            }
            double         time             = ((double)speed) / 100;
            TransformGroup myTransformGroup = new TransformGroup();
            var            forvardVector    = GetForwardForGost(ghost);

            TranslateTransform trans = new TranslateTransform();

            myTransformGroup.Children.Add(trans);

            if (forvardVector.VectorType == "Y")
            {
                DoubleAnimation anim1 = new DoubleAnimation(forvardVector.range, 0,
                                                            TimeSpan.FromSeconds(time));
                anim1.Completed += (s, e) => GhostAnimationCoplete(ghost, time);

                trans.BeginAnimation(TranslateTransform.YProperty, anim1);
            }

            if (forvardVector.VectorType == "X")
            {
                DoubleAnimation anim2 = new DoubleAnimation(forvardVector.range, 0,
                                                            TimeSpan.FromSeconds(time));
                anim2.Completed += (s, e) => GhostAnimationCoplete(ghost, time);
                trans.BeginAnimation(TranslateTransform.XProperty, anim2);
            }
            ghost.Model.RenderTransform = myTransformGroup;
        }
        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);
        }
Example #3
0
        private ForvardVectorMovingRange GetForwardForGost(AbstractGhost ghost)
        {
            ForvardVectorMovingRange res;

            if (ghost.Path == null)
            {
                res.VectorType = "Y";
                res.range      = 0;
                ghost.Dispose();
                GC.Collect();
                return(res);
            }
            if (ghost.Path.Count < 2)
            {
                res.VectorType = "Y";
                res.range      = 0;
                return(res);
            }
            if (ghost.Path.Count <= _pathIndex)
            {
                Grid.SetRow(ghost.Model, ghost.FieldPointNow.X);
                Grid.SetColumn(ghost.Model, ghost.FieldPointNow.Y);
                _pathIndex = 1;
            }
            double range = 50 * ImageCreator._scale;
            var    tmp   = ghost.FieldPointNow - ghost.Path[_pathIndex];

            if (tmp.Y == -1)//right
            {
                res.VectorType = "X";
                res.range      = -range;
            }
            else if (tmp.Y == 1)//left
            {
                res.VectorType = "X";
                res.range      = range;
            }
            else if (tmp.X == 1)//up
            {
                res.VectorType = "Y";
                res.range      = range;
            }
            else if (tmp.X == -1)//down
            {
                res.VectorType = "Y";
                res.range      = -range;
            }
            else
            {
                res.VectorType = "Y";
                res.range      = range;
            }
            ghost.FieldPointNow = ghost.Path[_pathIndex];
            _pathIndex++;
            Grid.SetRow(ghost.Model, ghost.FieldPointNow.X);
            Grid.SetColumn(ghost.Model, ghost.FieldPointNow.Y);
            return(res);
        }
Example #4
0
    void ActivateGhost(AbstractGhost ghost, float thresholdTimer)
    {
        Vector3Int spawnPosition = Vector3Int.FloorToInt(Gate.transform.position) + Vector3Int.left;

        if (ghost.state == GhostState.Disabled && spawnTimer >= thresholdTimer)
        {
            ghost.transform.position = spawnPosition;
            ghost.currentCell        = ConvertToCell(spawnPosition);
            ghost.state = GhostState.Chase;
        }
    }
 private void GhostMoving(AbstractGhost ghost)
 {
     if (IsPacmanDie)
     {
         _ghostAnimation[ghost.Index].PacmanPosition             -= PacmanCatchUp;
         _ghostAnimation[ghost.Index].PointAnimationHelperNotify -= GhostMoving;
     }
     else
     {
         _ghostAnimation[ghost.Index].MoveGost(ghost, ghost.Speed);
     }
 }
 private void DrawGhost(Grid grid, AbstractGhost ghost)
 {
     try
     {
         Grid.SetRow(ghost.Model, ghost.FieldPointNow.X);
         Grid.SetColumn(ghost.Model, ghost.FieldPointNow.Y);
         grid.Children.Add(ghost.Model);
         Logger.Add(new Log(this.GetType().Name, MethodBase.GetCurrentMethod().Name, $"Ghost was drawing to grid"));
     }
     catch (Exception ex)
     {
         Logger.Add(new Log(this.GetType().Name, MethodBase.GetCurrentMethod().Name, $"Error", ex));
     }
 }
 private PacmanEssence PacmanCatchUp(AbstractGhost ghost)
 {
     try
     {
         if (ghost.FieldPointNow == pacman.Point)
         {
             if (!IsPacmanDie)
             {
                 Logger.Add(new Log(this.GetType().Name, MethodBase.GetCurrentMethod().Name, $"Pacman die at {pacman.Point}"));
                 IsPacmanDie = true;
                 PacmanDie();
             }
         }
         return(pacman);
     }
     catch (Exception ex)
     {
         Logger.Add(new Log(this.GetType().Name, MethodBase.GetCurrentMethod().Name, $"Error", ex));
         return(pacman);
     }
 }
Example #8
0
        private void GhostAnimationCoplete(AbstractGhost ghost, double time)
        {
            if (_pathIndex == 0)//ExitPoint
            {
                return;
            }
            var pacman = PacmanPosition?.Invoke(ghost);

            if (ghost.Path == null)
            {
                ghost.Dispose();
                GC.Collect();
            }
            if (_pathIndex < ghost.Path.Count)
            {
                MoveGost(ghost, ghost.Speed);
            }
            else
            {
                ghost.Behavior.Think(ghost, pacman);
                _pathIndex = 1;
                PointAnimationHelperNotify?.Invoke(ghost);
            }
        }
Example #9
0
 /// <summary>
 /// Action logic when ghost complete moving
 /// </summary>
 /// <param name="ghost">Current ghost</param>
 /// <param name="pacman">Context pacman</param>
 public void Think(AbstractGhost ghost, PacmanEssence pacman)
 {
     _ghost = ghost;
     MoveTo(RandomPointNearPlayer(3, pacman), ghost.Speed);
 }
 /// <summary>
 /// Action logic when ghost complete moving
 /// </summary>
 /// <param name="ghost">Current ghost</param>
 /// <param name="pacman">Context pacman</param>
 public void Think(AbstractGhost ghost, PacmanEssence pacman)
 {
     _ghost = ghost;
     MoveTo(PlayerPoint(pacman), ghost.Speed);
 }