/// <summary>
 /// Controls Ghosts trough Input and manages it's own list.
 /// </summary>
 public Player()
 {
     for (int i = 0; i < 3; i++)
     {
         myGhosts[0][i] = new RedGhost(this);
         myGhosts[1][i] = new BlueGhost(this);
         myGhosts[2][i] = new YellowGhost(this);
     }
 }
Exemple #2
0
    // Constructor

    public Game()
    {
        //Implementing the 4 type of ghost
        myGhosts[0] = new OrangeGhost();
        myGhosts[1] = new BlueGhost();
        myGhosts[2] = new RedGhost();
        myGhosts[3] = new PinkGhost();
        //Implementing the player
        myPlayer = new Player();
        //Implementing the level
        myLevel = new Level(1);
    }
Exemple #3
0
        public int[] door;  // coordinates of the door to ghosts' home

        public GamePlan(string pathToMap, int dotPoints, int ghostPoints, int[] redStart, int[] redHome, int[] pinkStart, int[] pinkHome,
                        int[] blueStart, int[] blueHome, int[] yellowStart, int[] yellowHome)
        {
            // reads map from file and creates 4 ghosts according to initial data
            // redStart - coordinates of the red ghost starting tile
            // redHome - coordinates of the red ghost home - tile where it goes in Scatter mode
            ReadMapFromFile(pathToMap);
            this.dotPoints   = dotPoints;
            this.ghostPoints = ghostPoints;
            this.curPoints   = 0;
            dotsEaten        = 0;
            livesLeft        = Global.MAXLIVES;
            RedGhost    red    = new RedGhost(redStart[0], redStart[1], this, GhostMode.Chase, redHome[0], redHome[1]);
            PinkGhost   pink   = new PinkGhost(pinkStart[0], pinkStart[1], this, GhostMode.Wait, pinkHome[0], pinkHome[1]);
            BlueGhost   blue   = new BlueGhost(blueStart[0], blueStart[1], this, GhostMode.Wait, blueHome[0], blueHome[1]);
            YellowGhost yellow = new YellowGhost(yellowStart[0], yellowStart[1], this, GhostMode.Wait, yellowHome[0], yellowHome[1]);

            ghosts = new Ghost[] { red, pink, blue, yellow };
        }
        private void CreateGhosts(int Green, int Blue, int Red)
        {
            try
            {
                var dir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName + "\\Plugins\\";
                if (Directory.Exists(dir))
                {
                    foreach (string fileName in Directory.GetFiles(dir))
                    {
                        if (fileName.Contains(".dll"))
                        {
                            if (fileName.Contains("Core") || fileName.Contains("Prism") || fileName.Contains("Logs") || fileName.Contains("ValueTuple"))
                            {
                                continue;
                            }
                            Type[] file = Assembly.LoadFrom(fileName).GetTypes();
                            var    AIfromConfiguration = ConfigurationManager.AppSettings["AI_behavior"];
                            int    AI_index            = 0;
                            Int32.TryParse(AIfromConfiguration.Substring(0, 1), out AI_index);
                            dynamic sAI = Activator.CreateInstance(file[AI_index], _field);
                            for (int i = 0; i < Blue; i++)
                            {
                                var tmpGhost = new BlueGhost(sAI, ImageCreator.CreateImage($@"Materials\Ghosts\BlueGhost.png"));
                                tmpGhost.FieldPointNow    = sAI.RandomPoint();
                                tmpGhost.FieldPointTarget = sAI.RandomPoint();
                                tmpGhost.Path             = new PathCreator(_field).GetWay(tmpGhost.FieldPointNow, tmpGhost.FieldPointTarget);
                                tmpGhost.Speed            = _blueGhostSpeed;

                                DrawGhost(MyModel.Field, tmpGhost);
                                _ghostAnimation.Add(new PointAnimationHelper());
                                _ghostAnimation[tmpGhost.Index].PointAnimationHelperNotify += GhostMoving;
                                _ghostAnimation[tmpGhost.Index].PacmanPosition             += PacmanCatchUp;
                                _ghostAnimation[tmpGhost.Index].MoveGost(tmpGhost, tmpGhost.Speed);
                            }
                            for (int i = 0; i < Red; i++)
                            {
                                var tmpGhost = new RedGhost(sAI, ImageCreator.CreateImage($@"Materials\Ghosts\RedGhost.png"));
                                tmpGhost.FieldPointNow    = sAI.RandomPoint();
                                tmpGhost.FieldPointTarget = sAI.RandomPoint();
                                tmpGhost.Path             = new PathCreator(_field).GetWay(tmpGhost.FieldPointNow, tmpGhost.FieldPointTarget);
                                tmpGhost.Speed            = _redGhostSpeed;

                                DrawGhost(MyModel.Field, tmpGhost);
                                _ghostAnimation.Add(new PointAnimationHelper());
                                _ghostAnimation[tmpGhost.Index].PointAnimationHelperNotify += GhostMoving;
                                _ghostAnimation[tmpGhost.Index].PacmanPosition             += PacmanCatchUp;
                                _ghostAnimation[tmpGhost.Index].MoveGost(tmpGhost, tmpGhost.Speed);
                            }
                            for (int i = 0; i < Green; i++)
                            {
                                var tmpGhost = new GreenGhost(sAI, ImageCreator.CreateImage($@"Materials\Ghosts\GreenGhost.png"));
                                tmpGhost.FieldPointNow    = sAI.RandomPoint();
                                tmpGhost.FieldPointTarget = sAI.RandomPoint();
                                tmpGhost.Path             = new PathCreator(_field).GetWay(tmpGhost.FieldPointNow, tmpGhost.FieldPointTarget);
                                tmpGhost.Speed            = _greenGhostSpeed;

                                DrawGhost(MyModel.Field, tmpGhost);
                                _ghostAnimation.Add(new PointAnimationHelper());
                                _ghostAnimation[tmpGhost.Index].PointAnimationHelperNotify += GhostMoving;
                                _ghostAnimation[tmpGhost.Index].PacmanPosition             += PacmanCatchUp;
                                _ghostAnimation[tmpGhost.Index].MoveGost(tmpGhost, tmpGhost.Speed);
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Plugins folder not found", "Worning", MessageBoxButton.OK);
                }
            }
            catch (Exception ex)
            {
                Logger.Add(new Log(this.GetType().Name, MethodBase.GetCurrentMethod().Name, $"Error", ex));
            }
        }
        private static Ghost AddGhost(ushort x, ushort y, string command = "")
        {
            if (FieldElementsArray[x, y] != null) return null;
            Ghost tempGhost;
            try
            {
                switch (command)
                {
                    case "yellow":
                        tempGhost = new YellowGhost
                        {
                            Width = Squaresize,
                            Height = Squaresize
                        };
                        break;
                    case "red":
                        tempGhost = new RedGhost
                        {
                            Width = Squaresize,
                            Height = Squaresize
                        };
                        break;
                    default:
                        tempGhost = new Ghost
                        {
                            Width = Squaresize,
                            Height = Squaresize
                        };
                        break;
                }
            }
            catch (AlreadyInstatiated)
            {
                return null;
            }

            MainWindow.Wm.Battlfield.Children.Add(tempGhost);
            Canvas.SetLeft(tempGhost, Squaresize * x);
            Canvas.SetTop(tempGhost, Squaresize * y);

            FieldElementsArray[x, y] = tempGhost;
            GhostsList.Add(tempGhost);
            return tempGhost;
        }