예제 #1
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.gameBoard = ((System.Windows.Controls.Canvas)(target));
                return;

            case 2:
                this.PM = ((PacMan.Pacman)(target));
                return;
            }
            this._contentLoaded = true;
        }
예제 #2
0
 public GhostBehaviour(Pacman pacman, Level level)
 {
     this.pacman = pacman;
     this.level  = level;
 }
예제 #3
0
        // Même méthode que testCollision mais spécifique aux fantomes.
        // Permet de considérer la zone de départ (map i,j =2) comme une collision.
        public static Boolean testCollisionFantom(IAFantom iaFantom, String direction)
        {
            // On initialise une collision à false par défaut
            bool collision = false;
            // On récupère la position X/Y arrondie du pacman/fantome dans un tableau
            // On convertit la position x/y de pixel vers une case [i,j] de la matrice
            ObjetAnime objetAnime = iaFantom._fantom;

            int[] position = getPositionMatrice(objetAnime.Position.X, objetAnime.Position.Y);
            int   j        = position[0];
            int   i        = position[1];

            // Puis on test si le déplacement est possible selon le déplacement
            // On récupère la carte
            byte[,] map = Pacman.getMap();
            int VX = Pacman.getVX();
            int VY = Pacman.getVY();

            // on met à jour la position du fantôme en cas de hors limite

            iaFantom.updatePosition();
            // Si la case suivante est pas un mur
            // il y a collision
            // R L U D pour Right Left Up Down

            if (direction == "R")
            {
                if (j >= VY - 1) // Si dépasse de la matrice, amène de l'autre côté de l'écran
                {
                    j = -1;
                }
                if (map[i, j + 1] == 0 || map[i, j + 1] == 2)
                {
                    collision = true;
                }
            }
            else if (direction == "L")
            {
                if (j <= 1) // Si dépasse de la matrice, amène de l'autre côté de l'écran
                {
                    j = VY;
                }
                if (map[i, j - 1] == 0 || map[i, j - 1] == 2)
                {
                    collision = true;
                }
            }
            else if (direction == "U")
            {
                if (i <= 1) // Si dépasse de la matrice, amène de l'autre côté de l'écran
                {
                    i = VX;
                }
                if (map[i - 1, j] == 0 || map[i - 1, j] == 2)
                {
                    collision = true;
                }
            }
            else if (direction == "D")
            {
                if (i >= VX - 1) // Si dépasse de la matrice, amène de l'autre côté de l'écran
                {
                    i = -1;
                }
                if (map[i + 1, j] == 0 || map[i + 1, j] == 2)
                {
                    collision = true;
                }
            }

            return(collision);
        }
예제 #4
0
        /// <summary>
        /// Static method that returns a mapped gamestate instance by reading a specified file
        /// </summary>
        /// <param name="string">File path of the game file</param>
        /// <returns>GameState instance</returns>
        public static GameState Parse(string fileContent)
        {
            GameState g    = new GameState();
            Maze      maze = new Maze();

            g.maze = maze;
            Pen pen = new Pen();

            g.pen = pen;
            GhostPack gp = new GhostPack();

            g.ghostpack   = gp;
            g.score       = new ScoreAndLives(g);
            g.score.Lives = 3;
            Pacman pac = new Pacman(g);

            g.pacman = pac;

            g.Pacman.Position = new Vector2(11, 17);
            Ghost assistant = null;
            Ghost gh;

            string[][] parse = getElements(fileContent);

            Tile[,] array = new Tile[parse[0].Length, parse.Length];

            for (int y = 0; y < parse.Length; y++)
            {
                for (int x = 0; x < parse[0].Length; x++)
                {
                    switch (parse[y][x])
                    {
                    case "ew":
                        array[x, y] = new Wall(x, y, WallType.EmtpyWall);
                        break;

                    case "w":
                        array[x, y] = new Wall(x, y, WallType.Horizontal);
                        break;

                    case "ww":
                        array[x, y] = new Wall(x, y, WallType.Vertical);
                        break;

                    case "cur":
                        array[x, y] = new Wall(x, y, WallType.CornerUR);
                        break;

                    case "cul":
                        array[x, y] = new Wall(x, y, WallType.CornerUL);
                        break;

                    case "cdr":
                        array[x, y] = new Wall(x, y, WallType.CornerDR);
                        break;

                    case "cdl":
                        array[x, y] = new Wall(x, y, WallType.CornerDL);
                        break;

                    case "cr":
                        array[x, y] = new Wall(x, y, WallType.ClosedR);
                        break;

                    case "cl":
                        array[x, y] = new Wall(x, y, WallType.ClosedL);
                        break;

                    case "cu":
                        array[x, y] = new Wall(x, y, WallType.ClosedU);
                        break;

                    case "cd":
                        array[x, y] = new Wall(x, y, WallType.ClosedD);
                        break;

                    case "tr":
                        array[x, y] = new Wall(x, y, WallType.ConnectorR);
                        break;

                    case "tl":
                        array[x, y] = new Wall(x, y, WallType.ConnectorL);
                        break;

                    case "td":
                        array[x, y] = new Wall(x, y, WallType.ConnectorD);
                        break;

                    case "tu":
                        array[x, y] = new Wall(x, y, WallType.ConnectorU);
                        break;

                    case "p":
                        Pellet p = new Pellet(10);
                        p.Collision += g.score.IncrementScore;
                        array[x, y]  = new Path(x, y, p);
                        break;

                    case "e":
                        Energizer e = new Energizer(g.Ghostpack, 100);
                        e.Collision += g.score.IncrementScore;
                        array[x, y]  = new Path(x, y, e);
                        break;

                    case "m":
                        array[x, y] = new Path(x, y, null);
                        break;

                    case "x":
                        array[x, y] = new PenPath(x, y);
                        g.pen.AddTile(array[x, y]);
                        break;

                    case "P":
                        array[x, y]           = new Path(x, y, null);
                        g.pacman.Position     = new Vector2(x, y);
                        g.pacman.initPosition = new Vector2(x, y);
                        break;

                    case "1":

                        gh                    = new Ghost(g, x, y, GhostState.Chase, new Color(255, 0, 0), GhostName.Blinky);
                        assistant             = gh;
                        pen.Entrance          = new Vector2(x, y);
                        gh.Points             = 200;
                        Ghost.ReleasePosition = new Vector2(x, y);
                        gh.Collision         += g.score.IncrementScore;
                        gh.PacmanDied        += g.score.DeadPacman;
                        g.ghostpack.Add(gh);
                        array[x, y] = new Path(x, y, null);
                        break;

                    case "2":
                        gh             = new Ghost(g, x, y, GhostState.Chase, new Color(255, 192, 203), GhostName.Speedy);
                        gh.Points      = 200;
                        gh.Collision  += g.score.IncrementScore;
                        gh.PacmanDied += g.score.DeadPacman;
                        g.ghostpack.Add(gh);
                        array[x, y] = new Path(x, y, null);
                        g.pen.AddTile(array[x, y]);
                        g.pen.AddToPen(gh);
                        break;

                    case "3":
                        gh = new Ghost(g, x, y, GhostState.Chase, new Color(64, 224, 208), GhostName.Inky);
                        gh.GhostAssistant = assistant;
                        gh.Points         = 200;
                        gh.Collision     += g.score.IncrementScore;
                        gh.PacmanDied    += g.score.DeadPacman;
                        g.ghostpack.Add(gh);
                        array[x, y] = new Path(x, y, null);
                        g.pen.AddTile(array[x, y]);
                        g.pen.AddToPen(gh);
                        break;

                    case "4":
                        gh = new Ghost(g, x, y, GhostState.Chase, new Color(255, 165, 0), GhostName.Clyde);

                        gh.Points      = 200;
                        gh.Collision  += g.score.IncrementScore;
                        gh.PacmanDied += g.score.DeadPacman;
                        g.ghostpack.Add(gh);
                        array[x, y] = new Path(x, y, null);
                        g.pen.AddTile(array[x, y]);
                        g.pen.AddToPen(gh);
                        break;
                    }
                }
            }
            g.maze.SetTiles(array);

            //sets home positions for scatter mode
            foreach (Ghost ghost in g.ghostpack)
            {
                switch (ghost.Name)
                {
                case GhostName.Blinky:
                    ghost.HomePosition = new Vector2(g.maze.Length - 2, 1);
                    break;

                case GhostName.Speedy:
                    ghost.HomePosition = new Vector2(1, 1);
                    break;

                case GhostName.Inky:
                    ghost.HomePosition = new Vector2(g.maze.Length - 2, g.maze.Height - 2);
                    break;

                case GhostName.Clyde:
                    ghost.HomePosition = new Vector2(1, g.maze.Height - 2);
                    break;
                }
            }
            g.maze.PacmanWon += g.Score.IncrementScore;
            g.pacman.SubToGhosts();
            g.Score.Pause += g.Ghostpack.Pause;
            g.Score.Pause += g.Pen.Pause;
            return(g);
        }
예제 #5
0
        public void SetLevel(Level level)
        {
            currentLevel     = level;
            hud.CurrentLevel = level;


            int oldScore = 0;

            if (pacman != null)
            {
                oldScore = pacman.Score;
            }

            SpriteSheet pacmanSheet = new SpriteSheet(characterSheet.Texture, Vector2.Zero, new Vector2(80, 16), new Vector2(16, 16));

            pacman       = new Pacman(pacmanSheet, level, 5);
            pacman.Score = oldScore;

            Tile pacmanSpawnTile = level.GetTile(1, 1);

            if (level.PacmanSpawn != null)
            {
                pacmanSpawnTile = level.PacmanSpawn;
            }

            pacman.Position = pacmanSpawnTile.Position + new Vector2(level.TileSize / 2);

            hud.Pacman         = pacman;
            this.levelPosition = new Vector2((window.ClientBounds.Width / 2) - (level.PixelWidth / 2), (window.ClientBounds.Height / 2) - (level.PixelHeight / 2));



            ghosts.Clear();
            int ghostBehaviourIndex = 0;

            foreach (Tile spawn in level.GhostSpawns)
            {
                SpriteSheet redGhostSheet    = new SpriteSheet(characterSheet.Texture, new Vector2(0, 16), new Vector2(128, 16), new Vector2(16, 16));
                SpriteSheet pinkGhostSheet   = new SpriteSheet(characterSheet.Texture, new Vector2(0, 32), new Vector2(128, 16), new Vector2(16, 16));
                SpriteSheet blueGhostSheet   = new SpriteSheet(characterSheet.Texture, new Vector2(0, 48), new Vector2(128, 16), new Vector2(16, 16));
                SpriteSheet orangeGhostSheet = new SpriteSheet(characterSheet.Texture, new Vector2(0, 64), new Vector2(128, 16), new Vector2(16, 16));
                SpriteSheet runGhostSheet    = new SpriteSheet(characterSheet.Texture, new Vector2(0, 80), new Vector2(64, 16), new Vector2(16, 16));

                GhostBehaviour behaviour        = null;
                SpriteSheet    ghostSpritesheet = null;
                switch (ghostBehaviourIndex)
                {
                case 0:
                    behaviour        = new GhostPatrolling(pacman, level);
                    ghostSpritesheet = blueGhostSheet;
                    break;

                case 1:
                    behaviour        = new GhostPathfinding(pacman, level);
                    ghostSpritesheet = orangeGhostSheet;
                    break;

                default:
                    behaviour        = new GhostFullyRandom(pacman, level);
                    ghostSpritesheet = redGhostSheet;
                    break;
                }

                Ghost ghost = new Ghost(ghostSpritesheet, runGhostSheet, level, pacman, behaviour);
                ghost.Position = spawn.Position + new Vector2(level.TileSize / 2);
                ghosts.Add(ghost);
                ghostBehaviourIndex++;
                ghostBehaviourIndex %= 3;
            }
        }
예제 #6
0
        public Ghost(SpriteSheet spriteSheet, SpriteSheet runSpriteSheet, Level level, Pacman pacman, GhostBehaviour behaviour) : base(spriteSheet, level)
        {
            this.pacman    = pacman;
            this.direction = new Vector2(0, -1);

            this.behaviour          = behaviour;
            this.behaviour.Ghost    = this;
            this.runBehaviour       = new GhostRunAwayBehaviour(pacman, level);
            this.runBehaviour.Ghost = this;
            this.speed = 2;

            this.defaultSpriteSheet = spriteSheet;
            this.runSpriteSheet     = runSpriteSheet;
        }
예제 #7
0
        public static void NactiMapu()
        {
            pohyblivePrvky = new List <PohyblivyPrvek>();
            System.IO.StreamReader sr = new System.IO.StreamReader("mapa.txt");
            sirka            = int.Parse(sr.ReadLine());
            vyska            = int.Parse(sr.ReadLine());
            mapa             = new char[vyska, sirka];
            mapaJidlaABonusu = new char[vyska, sirka];
            mapaVObrazcich   = new PictureBox[vyska, sirka];
            sr.ReadLine();
            dx = Form1.sirkaFormulare / sirka;
            dy = Form1.vyskaFormulare / vyska - 4;

            for (int y = 0; y < vyska; y++)
            {
                string radek = sr.ReadLine();
                for (int x = 0; x < sirka; x++)
                {
                    char znak = radek[x];
                    mapa[y, x]           = znak;
                    mapaVObrazcich[y, x] = new PictureBox();
                    PictureBox pomBox = mapaVObrazcich[y, x];
                    pomBox.Parent          = Form.ActiveForm;
                    pomBox.Height          = dy;
                    pomBox.Width           = dx;
                    pomBox.Top             = dy * y + 40;
                    pomBox.Left            = dx * x;
                    pomBox.Visible         = true;
                    pomBox.BackColor       = Color.Black;
                    mapaJidlaABonusu[y, x] = 'V';

                    switch (znak)
                    {
                    case 'P': Pacman pacMan = new Pacman(y, x);
                        souradnicePacmana = new Policko(y, x);
                        puvP = new Policko(y, x);
                        pohyblivePrvky.Add(pacMan);
                        break;

                    case '1':
                        DuchOranzovy D_Oran = new DuchOranzovy(y, x, '<');
                        puvO = new Policko(y, x);
                        pohyblivePrvky.Add(D_Oran);
                        break;

                    case '2':
                        DuchCerveny D_Cerv = new DuchCerveny(y, x);
                        puvC = new Policko(y, x);
                        pohyblivePrvky.Add(D_Cerv);
                        break;

                    case '3':
                        DuchRuzovy D_Ruz = new DuchRuzovy(y, x);
                        pohyblivePrvky.Add(D_Ruz);
                        break;

                    case '4':
                        DuchModry D_Mod = new DuchModry(y, x, '>');
                        puvM = new Policko(y, x);
                        pohyblivePrvky.Add(D_Mod);
                        break;

                    //jeste promyslet co s jidlem
                    case 'J':
                        KolikZbyvaJidla++;
                        mapaJidlaABonusu[y, x] = 'J';
                        break;

                    case 'B':
                        KolikZbyvaBonusu++;
                        mapaJidlaABonusu[y, x] = 'B';
                        break;

                    case 'G':
                        mapaJidlaABonusu[y, x] = 'G';
                        break;

                    default:
                        break;
                    }
                }
            }
            sr.Close();
        }
예제 #8
0
 private void InitiolyzePacman()
 {
     _pacman = new Pacman(this, new Coord(DefaultSettings.PACMAN_START_POS_X, DefaultSettings.PACMAN_START_POS_Y));
 }