using System.Drawing; using Pacman.Properties; using PathFinder; /* *Cette classe contient l'ensemble des propriétés et des fonctions attachés aux fantômes dans le jeu. * */ namespace Pacman { // public class Ghost { //Position en X du fantôme private int xPosition = 0; //Position en Y du fantôme private int yPosition = 0; //État du fantôme (true si le pacman a une super pastille, faux si il n'en a pas). private static bool cowardState = false; //Nombre de fantômes private const int instancecount = 4; //Nombre de mise à jours private int nbUpdates = 0; //Nombre de mise à jours effectués avant un déplacement private int nbUpdatesBeforeMove = 5; //x Initial du fantôme private int initX = 0; //y initial du fantôme private int initY = 0; //Élément en dessous du fantôme PacmanElement elementUnderGhost = PacmanElement.Undefined; /// /// Constructeur de ghost; initialise les composantes selon des valeurs données. /// /// Position en X reçue /// Position en Y reçue public Ghost(int gridX, int gridY) { xPosition = gridX; yPosition = gridY; cowardState = false; nbUpdates = 0; initX = gridX; initY = gridY; elementUnderGhost = PacmanElement.Undefined; } /// /// Constructeur de ghost; Initialise les composantes. /// public Ghost() { cowardState = false; nbUpdates = 0; elementUnderGhost = PacmanElement.Undefined; } /// /// Obtient la position en X du fantôme /// /// position en X du fantôme public int GetX() { return xPosition; } /// /// Obtient la position en Y du fantôme /// /// position en Y du fantôme public int GetY() { return yPosition; } /// /// Modifie la position en X selon un paramêtre reçu /// /// entier reçu public void SetX(int recievedX) { xPosition = recievedX; } /// /// Modifie la position en Y selon un paramêtre reçu /// /// entier reçu public void SetY(int recievedY) { yPosition = recievedY; } /// /// Déplace le fantôme dans la grille du jeu selon le paramêtre reçu /// /// direction du fantôme /// Grille du jeu public void Move(Direction direction, PacmanGrid aMaze) { aMaze.SetMazeElementAt(xPosition, yPosition, elementUnderGhost); if (direction == Direction.East) { xPosition++; } else if (direction == Direction.West) { xPosition--; } else if (direction == Direction.North) { yPosition--; } else if (direction == Direction.South) { yPosition++; } elementUnderGhost = aMaze.GetMazeElementAt(xPosition, yPosition); aMaze.SetMazeElementAt(xPosition,yPosition, PacmanElement.Ghost); } /// /// Met à jour le fantôme selon la position du pacman /// /// Grille du jeu /// Instance du pacman public void Update(PacmanGrid aMaze,Pacman pacman) { nbUpdates++; if (nbUpdates % nbUpdatesBeforeMove == 0) { Point ghostPoint = new Point(xPosition, yPosition); Point pacPoint = new Point((int)(pacman.GetX()/20f), (int)(pacman.GetY()/20f)); if (cowardState == true) { Move(PathFinder.PathFinder.FindShortestPath(aMaze,ghostPoint, new Point(initX,initY)),aMaze); } else { Move(PathFinder.PathFinder.FindShortestPath(aMaze, ghostPoint, pacPoint), aMaze); } } } /// /// Cette fonction change l'état du fantôme /// /// État peureux du fantôme public static void GhostChangeState(bool coward) { cowardState = coward; } /// /// Dessine le fantôme sur l'écran du jeu. /// /// /// /// public void Draw(Graphics g, int ELEMENT_WIDTH, int ELEMENT_HEIGHT) { if (GetState() == false) { g.DrawImage(Resources.Ghost, xPosition * ELEMENT_WIDTH, yPosition * ELEMENT_HEIGHT, ELEMENT_WIDTH, ELEMENT_HEIGHT); } else { g.DrawImage(Resources.GhostWeak, xPosition * ELEMENT_WIDTH, yPosition * ELEMENT_HEIGHT, ELEMENT_WIDTH, ELEMENT_HEIGHT); } } /// /// Obtient la valeur de l'état de choc du fantôme /// /// État de peur du fantôme public static bool GetState() { return cowardState; } /// /// Obtient la condition de si le fantôme est au dessus d'une pastille /// /// true si il a une pastille, faux si il n'en a pas public bool HasPill() { return (elementUnderGhost == PacmanElement.Pill || elementUnderGhost == PacmanElement.SuperPill); } } } //