/// <summary> /// press space to start or pause, Escape to switch in game over mode /// </summary> /// <param name="key"></param> public void KeyPressed(PacmanKey key) { // Gestion des flèches pour le déplacement du pacman if (key == PacmanKey.Pause) { // touche Pause ou P Paused = !Paused; } else if (key == PacmanKey.Space && ((GameMode.GAME_OVER_DEATH == Status) || (GameMode.GAME_OVER_ESC == Status))) { SetMode(GameMode.READY); } else if (key == PacmanKey.Escape) { SetMode(GameMode.GAME_OVER_ESC); } else if (key == PacmanKey.NextLevel) { Labyrinth.getCurrent().RemainingPills = 0; } else if (_Pacman != null) { _cfg.play.Add(new GameRecord(oturn + 1, key)); } }
/// <summary> /// press space to start or pause, Escape to switch in game over mode /// </summary> /// <param name="key"></param> public void KeyPressed(PacmanKey key) { // Gestion des flèches pour le déplacement du pacman if (key == PacmanKey.Pause) { // touche Pause ou P Paused = !Paused; } if (_Pacman != null) { switch (key) { case PacmanKey.Left: _Pacman.Left(); break; case PacmanKey.Right: _Pacman.Right(); break; case PacmanKey.Down: _Pacman.Down(); break; case PacmanKey.Up: _Pacman.Up(); break; } } if (key == PacmanKey.Space && GameMode.GAME_OVER == Status) { // passe en mode de jeu READY numLaby = 0; Level = 1; SetLabyrinth(numLaby); // initialisation du score, des vies, ... Lives = 3; LifeScore = 5000; Score = 0; SetMode(GameMode.READY); if (Audio != null) { Audio.PlayIntro(); } } else if (key == PacmanKey.Escape) { SetMode(GameMode.GAME_OVER); } else if (key == PacmanKey.NextLevel) { Labyrinth.getCurrent().RemainingPills = 0; } }
void _CurrentGame_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == "CurrentLabyrinth") { if (_Labyrinth != null) { _Labyrinth.PillEated -= new PillEatedDelegate(_Labyrinth_PillEated); _Labyrinth.PillUpdated -= new PillEatedDelegate(_Labyrinth_PillUpdated); } _Labyrinth = _CurrentGame.CurrentLabyrinth; if (_Labyrinth != null) { _Labyrinth.PillEated += new PillEatedDelegate(_Labyrinth_PillEated); _Labyrinth.PillUpdated += new PillEatedDelegate(_Labyrinth_PillUpdated); } ConstructWallAndPills(_CurrentGame.CurrentLabyrinth); } else if (e.PropertyName == "Status") { NotifyPropertyChanged("IsReady"); NotifyPropertyChanged("IsGameOver"); } else if (e.PropertyName == "userTypeSpeed") { if ((_CurrentGame.freqList.freqsSum == 0) && (_CurrentGame.userTypeSpeed > CurrentGame.userMinTypeSpeed)) { _CurrentGame.taskBox.tskProvider.incTskCount(); _CurrentGame.setGhostsState(GhostState.REST); _CurrentGame.Audio.PlayGhostScared(); } } }
private WallSide GetSide(int i, int j, Labyrinth laby) { //first column if (i == 0) { if (j == 0) return WallSide.InnerTopLeft; if (j == Labyrinth.HEIGHT - 1) return WallSide.InnerBottomLeft; if (laby[i + 1, j] == 5 && laby[i, j - 1] == 5 && laby[i + 1, j - 1] != 5) return WallSide.InnerBottomLeft; if (laby[i + 1, j] == 5 && laby[i, j + 1] == 5 && laby[i + 1, j + 1] != 5) return WallSide.InnerTopLeft; if (laby[i, j - 1] == 5 && laby[i, j + 1] == 5 && (laby[i + 1, j] == 5 || laby[i + 1, j] == 4 || laby[i + 1, j] == 0)) return WallSide.None; return WallSide.Right; } //last column else if (i == Labyrinth.WIDTH - 1) { if (j == 0) return WallSide.InnerTopRight; if (j == Labyrinth.HEIGHT - 1) return WallSide.InnerBottomRight; if (laby[i - 1, j] == 5 && laby[i, j - 1] == 5 && laby[i - 1, j - 1] != 5) return WallSide.InnerBottomRight; if (laby[i - 1, j] == 5 && laby[i, j + 1] == 5 && laby[i - 1, j + 1] != 5) return WallSide.InnerTopRight; return WallSide.Left; } //first row else if (j == 0) { if (laby[i + 1, j + 1] != 5 && laby[i, j + 1] == 5) return WallSide.InnerTopLeft; if (laby[i - 1, j + 1] != 5 && laby[i, j + 1] == 5) return WallSide.InnerTopRight; if (laby[i - 1, j] == 5 && laby[i + 1, j] == 5 && (laby[i, j + 1] == 5 || laby[i, j + 1] == 0)) return WallSide.None; return WallSide.Bottom; } //last row else if (j == Labyrinth.HEIGHT - 1) { if (laby[i - 1, j - 1] != 5 && laby[i, j - 1] == 5) return WallSide.InnerBottomRight; if (laby[i + 1, j - 1] != 5 && laby[i, j - 1] == 5) return WallSide.InnerBottomLeft; if (laby[i - 1, j] == 5 && laby[i + 1, j] == 5 && (laby[i, j - 1] == 5 || laby[i, j - 1] == 0)) return WallSide.None; return WallSide.Top; } else if (j > 0 && j < Labyrinth.HEIGHT - 1 && i > 0 && i < Labyrinth.WIDTH - 1) { //Corners if (laby[i - 1, j - 1] != 5 && laby[i - 1, j] != 5 && laby[i, j - 1] != 5) return WallSide.TopLeft; if (laby[i + 1, j - 1] != 5 && laby[i + 1, j] != 5 && laby[i, j - 1] != 5) return WallSide.TopRight; if (laby[i + 1, j + 1] != 5 && laby[i + 1, j] != 5 && laby[i, j + 1] != 5) return WallSide.BottomRight; if (laby[i - 1, j + 1] != 5 && laby[i - 1, j] != 5 && laby[i, j + 1] != 5) return WallSide.BottomLeft; //Top and Bottom if (laby[i, j - 1] != 5 && laby[i, j - 1] != 4) return WallSide.Top; if (laby[i, j + 1] != 5) return WallSide.Bottom; //Left and Right if (laby[i - 1, j] != 5 && laby[i - 1, j] != 4) return WallSide.Left; if (laby[i + 1, j] != 5) return WallSide.Right; //inner corners if (laby[i - 1, j - 1] != 5) return WallSide.InnerBottomRight; if (laby[i + 1, j + 1] != 5) return WallSide.InnerTopLeft; if (laby[i - 1, j + 1] != 5) return WallSide.InnerTopRight; if (laby[i + 1, j - 1] != 5) return WallSide.InnerBottomLeft; } return WallSide.None; }
private Geometry GetGeometry(int i, int j, int xScreen, int yScreen, Labyrinth laby) { if (i == 0 && j == 0) { PathGeometry path = new PathGeometry(); PathFigure pf = new PathFigure() { IsClosed = true, IsFilled = true }; path.Figures.Add(pf); pf.StartPoint = new Point(xScreen + Constants.GRID_WIDTH_2, yScreen + Constants.GRID_HEIGHT); pf.Segments.Add(new ArcSegment() { Size = new Size(Constants.GRID_WIDTH_2, Constants.GRID_WIDTH_2), Point = new Point(xScreen + Constants.GRID_WIDTH, yScreen + Constants.GRID_HEIGHT_2), SweepDirection = SweepDirection.Clockwise }); pf.Segments.Add(new LineSegment() { Point = new Point(xScreen + Constants.GRID_WIDTH, yScreen + Constants.GRID_HEIGHT) }); return path; } else { RectangleGeometry r; PathGeometry corner; PathFigure pf; int OffsetX; int OffsetY; WallSide side = GetSide(i, j, laby); switch (side) { case WallSide.InnerTopLeft: case WallSide.TopLeft: OffsetX = side == WallSide.InnerTopLeft ? Constants.GRID_WIDTH_2 : 0; OffsetY = side == WallSide.InnerTopLeft ? Constants.GRID_HEIGHT_2 : 0; corner = new PathGeometry(); pf = new PathFigure() { IsClosed = true, IsFilled = true }; corner.Figures.Add(pf); pf.StartPoint = new Point(xScreen + OffsetX, yScreen + Constants.GRID_HEIGHT_2 + OffsetY); pf.Segments.Add(new ArcSegment() { Size = new Size(Constants.GRID_WIDTH_2, Constants.GRID_WIDTH_2), Point = new Point(xScreen + Constants.GRID_WIDTH_2 + OffsetX, yScreen + OffsetY), SweepDirection = SweepDirection.Clockwise }); if (side == WallSide.InnerTopLeft) { pf.Segments.Add(new LineSegment() { Point = new Point(xScreen + Constants.GRID_WIDTH, yScreen + Constants.GRID_HEIGHT) }); } else { pf.Segments.Add(new LineSegment() { Point = new Point(xScreen + Constants.GRID_WIDTH, yScreen) }); pf.Segments.Add(new LineSegment() { Point = new Point(xScreen + Constants.GRID_WIDTH, yScreen + Constants.GRID_HEIGHT_2) }); pf.Segments.Add(new LineSegment() { Point = new Point(xScreen + Constants.GRID_WIDTH_2, yScreen + Constants.GRID_HEIGHT_2) }); pf.Segments.Add(new LineSegment() { Point = new Point(xScreen + Constants.GRID_WIDTH_2, yScreen + Constants.GRID_HEIGHT) }); pf.Segments.Add(new LineSegment() { Point = new Point(xScreen, yScreen + Constants.GRID_HEIGHT) }); } return corner; case WallSide.InnerTopRight: case WallSide.TopRight: OffsetX = side == WallSide.InnerTopRight ? -Constants.GRID_WIDTH_2 : 0; OffsetY = side == WallSide.InnerTopRight ? Constants.GRID_HEIGHT_2 : 0; corner = new PathGeometry(); pf = new PathFigure() { IsClosed = true, IsFilled = true }; corner.Figures.Add(pf); pf.StartPoint = new Point(xScreen + Constants.GRID_WIDTH_2 + OffsetX, yScreen + OffsetY); pf.Segments.Add(new ArcSegment() { Size = new Size(Constants.GRID_WIDTH_2, Constants.GRID_WIDTH_2), Point = new Point(xScreen + Constants.GRID_WIDTH + OffsetX, yScreen + Constants.GRID_HEIGHT_2 + OffsetY), SweepDirection = SweepDirection.Clockwise }); if (side == WallSide.InnerTopRight) { pf.Segments.Add(new LineSegment() { Point = new Point(xScreen, yScreen + Constants.GRID_HEIGHT) }); } else { pf.Segments.Add(new LineSegment() { Point = new Point(xScreen + Constants.GRID_WIDTH, yScreen + Constants.GRID_HEIGHT) }); pf.Segments.Add(new LineSegment() { Point = new Point(xScreen + Constants.GRID_WIDTH_2, yScreen + Constants.GRID_HEIGHT) }); pf.Segments.Add(new LineSegment() { Point = new Point(xScreen + Constants.GRID_WIDTH_2, yScreen + Constants.GRID_HEIGHT_2) }); pf.Segments.Add(new LineSegment() { Point = new Point(xScreen, yScreen + Constants.GRID_HEIGHT_2) }); pf.Segments.Add(new LineSegment() { Point = new Point(xScreen, yScreen) }); } return corner; case WallSide.InnerBottomRight: case WallSide.BottomRight: OffsetX = side == WallSide.InnerBottomRight ? -Constants.GRID_WIDTH_2 : 0; OffsetY = side == WallSide.InnerBottomRight ? -Constants.GRID_HEIGHT_2 : 0; corner = new PathGeometry(); pf = new PathFigure() { IsClosed = true, IsFilled = true }; corner.Figures.Add(pf); pf.StartPoint = new Point(xScreen + Constants.GRID_WIDTH + OffsetX, yScreen + Constants.GRID_HEIGHT_2 + OffsetY); pf.Segments.Add(new ArcSegment() { Size = new Size(Constants.GRID_WIDTH_2, Constants.GRID_WIDTH_2), Point = new Point(xScreen + Constants.GRID_WIDTH_2 + OffsetX, yScreen + Constants.GRID_HEIGHT + OffsetY), SweepDirection = SweepDirection.Clockwise }); if (side == WallSide.InnerBottomRight) { pf.Segments.Add(new LineSegment() { Point = new Point(xScreen, yScreen) }); } else { pf.Segments.Add(new LineSegment() { Point = new Point(xScreen, yScreen + Constants.GRID_HEIGHT) }); pf.Segments.Add(new LineSegment() { Point = new Point(xScreen, yScreen + Constants.GRID_HEIGHT_2) }); pf.Segments.Add(new LineSegment() { Point = new Point(xScreen + Constants.GRID_WIDTH_2, yScreen + Constants.GRID_HEIGHT_2) }); pf.Segments.Add(new LineSegment() { Point = new Point(xScreen + Constants.GRID_WIDTH_2, yScreen) }); pf.Segments.Add(new LineSegment() { Point = new Point(xScreen + Constants.GRID_WIDTH, yScreen) }); } return corner; case WallSide.InnerBottomLeft: case WallSide.BottomLeft: OffsetX = side == WallSide.InnerBottomLeft ? Constants.GRID_WIDTH_2 : 0; OffsetY = side == WallSide.InnerBottomLeft ? -Constants.GRID_HEIGHT_2 : 0; corner = new PathGeometry(); pf = new PathFigure() { IsClosed = true, IsFilled = true }; corner.Figures.Add(pf); pf.StartPoint = new Point(xScreen + Constants.GRID_WIDTH_2 + OffsetX, yScreen + Constants.GRID_HEIGHT + OffsetY); pf.Segments.Add(new ArcSegment() { Size = new Size(Constants.GRID_WIDTH_2, Constants.GRID_WIDTH_2), Point = new Point(xScreen + OffsetX, yScreen + Constants.GRID_HEIGHT_2 + OffsetY), SweepDirection = SweepDirection.Clockwise }); if (side == WallSide.InnerBottomLeft) { pf.Segments.Add(new LineSegment() { Point = new Point(xScreen + Constants.GRID_WIDTH, yScreen) }); } else { pf.Segments.Add(new LineSegment() { Point = new Point(xScreen, yScreen) }); pf.Segments.Add(new LineSegment() { Point = new Point(xScreen + Constants.GRID_WIDTH_2, yScreen) }); pf.Segments.Add(new LineSegment() { Point = new Point(xScreen + Constants.GRID_WIDTH_2, yScreen + Constants.GRID_HEIGHT_2) }); pf.Segments.Add(new LineSegment() { Point = new Point(xScreen + Constants.GRID_WIDTH, yScreen + Constants.GRID_HEIGHT_2) }); pf.Segments.Add(new LineSegment() { Point = new Point(xScreen + Constants.GRID_WIDTH, yScreen + Constants.GRID_HEIGHT) }); } return corner; case WallSide.Left: r = new RectangleGeometry(); r.Rect = new Rect(xScreen, yScreen, Constants.GRID_WIDTH_2, Constants.GRID_HEIGHT); return r; case WallSide.Right: r = new RectangleGeometry(); r.Rect = new Rect(xScreen + Constants.GRID_WIDTH_2, yScreen, Constants.GRID_WIDTH_2, Constants.GRID_HEIGHT); return r; case WallSide.Top: r = new RectangleGeometry(); r.Rect = new Rect(xScreen, yScreen, Constants.GRID_WIDTH, Constants.GRID_HEIGHT_2); return r; case WallSide.Bottom: r = new RectangleGeometry(); r.Rect = new Rect(xScreen, yScreen + Constants.GRID_HEIGHT_2, Constants.GRID_WIDTH, Constants.GRID_HEIGHT_2); return r; default: return null; } } }
/// <summary> /// construct geometry of wall and pills for a specific level /// </summary> /// <param name="newValue"></param> private void ConstructWallAndPills(Labyrinth newValue) { this.Wall.Children.Clear(); this.Pills.Children.Clear(); CurrentGame._pillCoord.Clear(); if (newValue == null) return; TPillGame.RemainingPills = 0; for (int xx = 0; xx < Labyrinth.WIDTH; xx++) { for (int yy = 0; yy < Labyrinth.HEIGHT; yy++) { UInt16 b = newValue[xx, yy]; if (b == 0) continue; double x, y; newValue.GetScreenCoord(xx, yy, out x, out y); switch (b) { case 1://pill case 2: TPillGame pill = new TPillGame(this); this.Pills.Children.Add(pill); CurrentGame._pillCoord.Add(new Point(xx, yy), pill); pill.Width = Constants.GRID_WIDTH*1.5; pill.Height = Constants.GRID_HEIGHT*1.5; pill.tsk = newValue.chars[xx, yy]; pill.center = new Point(x + Constants.GRID_WIDTH_2, y + Constants.GRID_HEIGHT_2); pill.init(); pill.isBig = (b == 2); break; case 4: //gate of ghost's house break; case 5://wall Geometry current = GetGeometry(xx, yy, (int)x, (int)y, newValue); //if (current == null) //{ // RectangleGeometry r = new RectangleGeometry(); // //if (i == 0) // // r.Rect = new Rect(x + Constants.GRID_WIDTH_2, y, Constants.GRID_WIDTH_2, Constants.GRID_HEIGHT); // //else // r.Rect = new Rect(x, y, Constants.GRID_WIDTH, Constants.GRID_HEIGHT); // current = r; //} if (current != null) this.Wall.Children.Add(current); break; } } } }
private void SetLabyrinth(int numLaby) { Labyrinth.SetCurrent(numLaby); taskBox.lab = Labyrinth.getCurrent(); DoPropertyChanged("CurrentLabyrinth"); }
// Le jeu est dans l'état PLAY private void AnimatePlay() { GameRecord record; while (_cfg.play.Count > 0) { record = _cfg.play[0]; if (record.tim > oturn) { break; } _cfg.play.RemoveAt(0); _cfg.playerCfg.record.Add(record); if (record.tim == oturn) { if (record.isKey) { switch (record.key) { case PacmanKey.Back: { TXYList xyList = _Pacman.xyList; if (!xyList.empty) { xyList.deAdd(); } } break; case PacmanKey.Left: _Pacman.Left(); break; case PacmanKey.Right: _Pacman.Right(); break; case PacmanKey.Down: _Pacman.Down(); break; case PacmanKey.Up: _Pacman.Up(); break; } } else { intProcessKey(record.tsk); } } } if (Labyrinth.getCurrent().RemainingPills <= 0) { // toutes les pastilles ont été mangées, changement de niveau // accélère un peu le jeu Level++; SleepTime -= 1; numLaby = (numLaby + 1) % 4; SetLabyrinth(numLaby); SetMode(GameMode.READY); } else { int i; int xp, yp; GhostState state; EraseSprites(); ErasePoints(); // testes de collisions xp = _Pacman.X; yp = _Pacman.Y; // collisions avec les fantomes foreach (Ghost ghost in _Ghosts) { state = ghost.State; // teste si le Pacman est en collision avec le Fantome i if (_Pacman.HasCollision(ghost)) { if (state.isHunt() || state.isRandom()) { // Perdu une vie SetMode(GameMode.DEATH); return; } else if (state.isFlee()) { // le fantome est mangé ghost.setState(GhostState.EYE); AddScore(_GhostScore); FantScore *= 2; AddPoints(_GhostScore); if (Audio != null) { Audio.PlayEatGhost(); } } } } // collisions avec le bonus if (CurrentBonus != null) { // le bonus existe if (_Pacman.HasCollision(CurrentBonus)) { int points = Math.Min(1600, Level * 100); AddScore(points); AddPoints(points); CurrentBonus = null; if (Audio != null) { Audio.PlayBonus(); } } if (CurrentBonus != null && CurrentBonus.animate() <= 0) { // le bonus est en fin de vie CurrentBonus = null; } } else { // pas de bonus if (Game.GetRandom(1000) < 5) { CurrentBonus = new Bonus(Level - 1); } } // animate pacman if (speedCheck(Config.SpeedPacman)) { i = _Pacman.animate(); if (i == 1) { // une pastille est mangée AddScore(10); Audio.PlayPill(); } else if (i == 2) { FantScore = 100; // Les fantomes qui chasse deviennent fuyards AddScore(50); Audio.PlayBigPill(); setGhostsState(GhostState.FLEE); } } // animate fantomes // bool siren = false; foreach (Ghost ghost in _Ghosts) { switch (ghost.State.ToEnum()) { case GhostStateEnum.FLEE: ghost.speedDevider = Config.GhostSpeedFlee; break; case GhostStateEnum.EYE: ghost.speedDevider = Config.GhostSpeedEye; break; default: if (Math.Sqrt((_Pacman.xLaby - ghost.xLaby) ^ 2 + (_Pacman.yLaby - ghost.yLaby) ^ 2) < Config.SafeRadius) { if (ghost.State.isHunt()) { if (GetRandom(Config.GhostSpeedSwitchTime) == 2) { if (GetRandom(1) == 1) { ghost.speedDevider = Config.GhostSpeedHunt; } else { ghost.speedDevider = Config.GhostSpeedHuntPulse; } } } else { ghost.speedDevider = Config.GhostSpeed; } } else { ghost.speedDevider = Config.GhostSpeedOutSafe; } break; } if (!speedCheck(ghost.speedDevider)) { ghost.timers(); continue; } ghost.setPacmanCoor(xp, yp); ghost.animate(); // if (!siren && ghosts[i].getState().isHunt()) { // siren = true; // Audio.playSiren(); // } } // animate points foreach (FlyingScore pt in _FlyingScores) { pt.animate(); } DrawSprites(); DrawPoints(); DrawScore(); DrawLives(); //if (DEBUG) //{ // foreach(Ghost ghost in _Ghosts) // { // //draw.drawDebugString(4, 12 + i * 12, 12, ghosts[i].toString()); // } //} } }
bool intProcessKey(TTsk keyTsk) { bool speedOk = true; if (lastKeyTurn > 0) { Double speed; if (lastKeyTurn == turn) { speed = lastSpeed + lastMomentSpeed; } else { speed = 1000.0 * 60 / SleepTime / (turn - lastKeyTurn); lastMomentSpeed = speed; } lastSpeed = speed; if (speed > fUserTypeSpeed) { userTypeSpeed = Config.FilterSpeedUp * speed + (1 - Config.FilterSpeedUp) * fUserTypeSpeed; userMinTypeSpeed = Config.FilterAvgSpeedUp * speed + (1 - Config.FilterAvgSpeedUp) * fUserMinTypeSpeed; } else { userTypeSpeed = Config.FilterSpeedDown * speed + (1 - Config.FilterSpeedDown) * fUserTypeSpeed; userMinTypeSpeed = Config.FilterAvgSpeedDown * speed + (1 - Config.FilterAvgSpeedDown) * fUserMinTypeSpeed; } speedOk = (speed > userMinTypeSpeed); } lastKeyTurn = turn; UInt16 x, y; if (keyTsk.tskNo < 1) { return(false); } if (_Pacman == null) { return(false); } TPillPoint xy = _Pacman.xyList.head; x = xy.x; y = xy.y; foreach (TXYDir dir in xyDirs) { dir.x = x; dir.y = y; dir.skip = false; } int dirCnt = xyDirs.Length; do { foreach (TXYDir xyDir in xyDirs) { if (xyDir.skip) { continue; } Labyrinth.translate(ref xyDir.x, ref xyDir.y, xyDir.dir); if (!Labyrinth.outBound(xyDir.x, xyDir.y)) { if (CurrentLabyrinth.laby[xyDir.y][xyDir.x] == 0) { foreach (Direction dir in Direction.directions) { if (dir.Opposite == xyDir.dir) { continue; } if (dir == xyDir.dir) { continue; } int xx = xyDir.x; int yy = xyDir.y; Labyrinth.translate(ref xx, ref yy, dir); if (chkKey(keyTsk, speedOk, xx, yy)) { return(true); } } continue; } else { if (chkKey(keyTsk, speedOk, xyDir.x, xyDir.y)) { double halfSpeed = userMinTypeSpeed / 2; Audio.PlayGoodPill(Math.Max(Math.Min((userTypeSpeed - halfSpeed) / halfSpeed, 1), 0)); return(true); } } } dirCnt--; xyDir.skip = true; } } while (dirCnt > 0); taskBox.tskProvider.tskBad(keyTsk); if (Audio != null) { Audio.PlayWrongPill(); } return(false); }
public static void SetCurrent(int num) { instance = new Labyrinth(num); }
private void SetLabyrinth(int numLaby) { Labyrinth.SetCurrent(numLaby); DoPropertyChanged("CurrentLabyrinth"); }
// Le jeu est dans l'état PLAY private void AnimatePlay() { if (Labyrinth.getCurrent().RemainingPills <= 0) { // toutes les pastilles ont été mangées, changement de niveau // accélère un peu le jeu Level++; SleepTime -= 1; numLaby = (numLaby + 1) % 4; SetLabyrinth(numLaby); SetMode(GameMode.READY); } else { int i; int xp, yp; GhostState state; EraseSprites(); ErasePoints(); // testes de collisions xp = _Pacman.X; yp = _Pacman.Y; // collisions avec les fantomes foreach (Ghost ghost in _Ghosts) { state = ghost.State; // teste si le Pacman est en collision avec le Fantome i if (_Pacman.HasCollision(ghost)) { if (state.isHunt() || state.isRandom()) { // Perdu une vie SetMode(GameMode.DEATH); if (Audio != null) { Audio.PlayDeath(); } //Audio.playDeath(); return; } else if (state.isFlee()) { // le fantome est mangé ghost.setState(GhostState.EYE); AddScore(_GhostScore); FantScore *= 2; AddPoints(_GhostScore); if (Audio != null) { Audio.PlayEatGhost(); } //Audio.playEatGhost(); } } } // collisions avec le bonus if (CurrentBonus != null) { // le bonus existe if (_Pacman.HasCollision(CurrentBonus)) { int points = Math.Min(1600, Level * 100); AddScore(points); AddPoints(points); CurrentBonus = null; if (Audio != null) { Audio.PlayBonus(); } //Audio.playBonus(); } if (CurrentBonus != null && CurrentBonus.animate() <= 0) { // le bonus est en fin de vie CurrentBonus = null; } } else { // pas de bonus if (Game.GetRandom(1000) < 5) { CurrentBonus = new Bonus(Level - 1); } } // animate pacman i = _Pacman.animate(); if (i == 1) { // une pastille est mangée AddScore(10); if (Audio != null) { Audio.PlayPill(); } //Audio.playPil(); } else if (i == 2) { FantScore = 100; // Les fantomes qui chasse deviennent fuyards AddScore(50); foreach (Ghost ghost in _Ghosts) { ghost.setState(GhostState.FLEE); } } // animate fantomes // bool siren = false; foreach (Ghost ghost in _Ghosts) { ghost.setPacmanCoor(xp, yp); ghost.animate(); // if (!siren && ghosts[i].getState().isHunt()) { // siren = true; // Audio.playSiren(); // } } // animate points foreach (FlyingScore pt in _FlyingScores) { pt.animate(); } DrawSprites(); DrawPoints(); DrawScore(); DrawLives(); //if (DEBUG) //{ // foreach(Ghost ghost in _Ghosts) // { // //draw.drawDebugString(4, 12 + i * 12, 12, ghosts[i].toString()); // } //} } }
public TChars(Labyrinth laby) { fLaby = laby; }