public void Eaten(object sender, EventArgs e) { for (int i = 0; i < Monsters.Count; i++) { if (Monsters[i].GetCoordMonster() == PacMan.GetCoordMonster()) { if (Monsters[i].PrevSymbol == 2) { DoPointInGame(this, EventArgs.Empty); } else if (Monsters[i].PrevSymbol == 3) { DoSuperPointInGame(this, EventArgs.Empty); } Monsters[i].PrevSymbol = 0; if (i == 0) { Monsters[0].SetCoordMonster(Monsters[0].GetCoordMonsterStart().y, Monsters[0].GetCoordMonsterStart().x); } if (i == 1) { Monsters[1].SetCoordMonster(Monsters[1].GetCoordMonsterStart().y, Monsters[1].GetCoordMonsterStart().x); } if (i == 2) { Monsters[2].SetCoordMonster(Monsters[2].GetCoordMonsterStart().y, Monsters[2].GetCoordMonsterStart().x); } Monsters[i].Draw(Map); } } }
// this method changes the direction of the ghost when he collides with a wall // the direction that is choosen is based on the behavior public void changeDirection(PacMan player, int tempX, int tempY) { // for the red ghost if (behavior == "aggressive") { if (xSpeed == -GameScreen.GHOST_SPEED) { xSpeed = 0; ySpeed = GameScreen.GHOST_SPEED; } else if (ySpeed == -GameScreen.GHOST_SPEED) { xSpeed = -GameScreen.GHOST_SPEED; ySpeed = 0; } else if (ySpeed == GameScreen.GHOST_SPEED) { xSpeed = -GameScreen.GHOST_SPEED; ySpeed = 0; } else if (xSpeed == GameScreen.GHOST_SPEED) { xSpeed = -GameScreen.GHOST_SPEED; ySpeed = 0; } // set position of ghost to temp position setPosition(tempX, tempY); } // for the green ghost else if (behavior == "patrol") { if (xSpeed == GameScreen.GHOST_SPEED) { xSpeed = 0; ySpeed = -GameScreen.GHOST_SPEED; } else if (ySpeed == -GameScreen.GHOST_SPEED) { xSpeed = -GameScreen.GHOST_SPEED; ySpeed = 0; } else if (xSpeed == -GameScreen.GHOST_SPEED) { xSpeed = 0; ySpeed = GameScreen.GHOST_SPEED; } else if (ySpeed == GameScreen.GHOST_SPEED) { xSpeed = GameScreen.GHOST_SPEED; ySpeed = 0; } // set position back to when the ghost isn't colliding setPosition(tempX, tempY); } }
public void LoadGame(Memento m) { Map = m.MMap; TheSuperPoint = m.MTheSuperPoint; ThePoint = m.MThePoint; PacMan.Draw(Map); for (int i = 0; i < Monsters.Count; i++) { Monsters[i].Draw(Map); } // PacMan.CancelSuperPoint(PacMan, EventArgs.Empty); PacMan.Life--; }
public Memento SaveGame() { for (int i = 0; i < Monsters.Count; i++) { Monsters[i].DeleteDraw(Map); Monsters[i].PrevSymbol = 0; Monsters[i].Direction = 1; Monsters[i].SuperMonster = false; Monsters[i].SetCoordMonster(Monsters[i].GetCoordMonsterStart()); } PacMan.SetCoordMonster(PacMan.GetCoordMonsterStart()); return(new Memento(Map, TheSuperPoint, ThePoint)); }
public void Eat(object sender, EventArgs e) { for (int i = 0; i < Monsters.Count; i++) { if (Monsters[i].GetCoordMonster() == PacMan.GetCoordMonster()) { Caretaker caretaker = new Caretaker(this); caretaker.Backup(); caretaker.Undo(); break; } } }
public void PacManMove() { ConsoleLib.Coord temp = PacMan.DirectionalCheck(); Thread.Sleep(100); if (Console.KeyAvailable == true) { PacMan.Move(Map); } else if (Map.GetPointInMap(temp.y, temp.x) != 1) { PacMan.DeleteDraw(Map); PacMan.SetCoordMonster(temp); PacMan.Draw(Map); } }
public void Play() { Console.CursorVisible = false; Map.Draw(6, 20); PacMan.Draw(Map); for (int i = 0; i < Monsters.Count; i++) { Monsters[i].Draw(Map); } TimerStartGame(); bool win = false; do { //----------------------------------------------------------------// /* for (int i = 0; i < Map.SizeY; i++) * { * ConsoleLib.GotoXY(80, 6 + i); * for (int j = 0; j < Map.SizeX; j++) * { * Console.Write(Map.GetPointInMap(i, j)); * } * }*/ //-----------------------------------------------------------------// PacManMove(); if (ExitFromGame == true) { break; } MonsterMove(); ConsoleLib.GotoXY(1, 1); /// на посмотреть Console.WriteLine("point count : {0}", ThePoint.PointCount); // на посмотреть ConsoleLib.GotoXY(20, 5); // вывод рекорда на посмотреть Console.Write("score :: {0}", PacMan.Score); if (ThePoint.PointCount < 3) { win = WinCheck(); } } while (((ThePoint.PointCount + TheSuperPoint.SuperPointCount) != 0 || win != true) && PacMan.Life != 0); }
private void ResetActors() { var pacOrigin = new Vector2(48 * Sprite.Scale / 2f, 48 * Sprite.Scale / 2f); var ghostOrigin = new Vector2(48 * Sprite.Scale / 2f, 51 * Sprite.Scale / 2f); PacMan = new PacMan(this, ScreenManager.PacManTileset, PacmanStartingPosition); //Blinky = new Blinky(this, ScreenManager.GhostBlinkyTileset, BlinkyStartingPosition); Blinky = new Blinky(this, ScreenManager.GhostBlinkyTileset, Utils.GridToAbs(new Vector2(26, 4), ghostOrigin)); //Pinky = new Pinky(this, ScreenManager.GhostPinkyTileset, PinkyStartingPosition); Pinky = new Pinky(this, ScreenManager.GhostPinkyTileset, Utils.GridToAbs(new Vector2(4, 4), ghostOrigin)); //Inky = new Inky(this, ScreenManager.GhostInkyTileset, InkyStartingPosition); Inky = new Inky(this, ScreenManager.GhostInkyTileset, Utils.GridToAbs(new Vector2(24, 32), ghostOrigin)); //Clyde = new Clyde(this, ScreenManager.GhostClydeTileset, ClydeStartingPosition); Clyde = new Clyde(this, ScreenManager.GhostClydeTileset, Utils.GridToAbs(new Vector2(4, 32), ghostOrigin)); }
public void move(PacMan player) { if (behavior == "patrol") { // move the green ghost // up when he reaches (662, 500) if ((rect.X >= 655) && (rect.Y >= 490)) { xSpeed = 0; ySpeed = -GameScreen.GHOST_SPEED; } else if ((rect.X >= 655) && (rect.Y <= 95)) { xSpeed = -GameScreen.GHOST_SPEED; ySpeed = 0; } } else if (behavior == "aggressive") { if ((rect.X >= 100) && (rect.Y >= 495)) { xSpeed = GameScreen.GHOST_SPEED; ySpeed = 0; } if ((rect.X >= 485) && (rect.Y >= 495)) { xSpeed = 0; ySpeed = -GameScreen.GHOST_SPEED; } if ((rect.X >= 485) && (rect.Y <= 200)) { xSpeed = -GameScreen.GHOST_SPEED; ySpeed = 0; } } rect.X += xSpeed; rect.Y += ySpeed; }
public void MonsterMove() { int count = 2; for (int i = 0; i < count; i++) { if (ThePoint.PointCount < 200 && count != 3) { count++; } Monsters[i].Move(Map); if (Monsters[i].GetCoordMonster() == PacMan.GetCoordMonster()) { if (Monsters[i].SuperMonster == true) { Eaten(this, EventArgs.Empty); } else if (Monsters[i].SuperMonster == false) { Eat(this, EventArgs.Empty); } } } }
private void Reset() { map = new Map(this); movers[0] = new PacMan(this, 10, 5, tempTexture);
// this method changes the direction of the ghost when he collides with a wall // the direction that is choosen is based on the behavior public void changeDirection(PacMan player, int tempX, int tempY) { if (behavior == "aggressive") { // the player is below if (player.rect.Y > rect.Y) { if (randGen.Next(0, 10) > 5) { xSpeed = GameScreen.GHOST_SPEED; ySpeed = 0; // set position back to when the ghost isn't colliding setPosition(tempX, tempY); } else { if (ySpeed == 0) { // change direction xSpeed = 0; ySpeed = GameScreen.GHOST_SPEED; } else { ySpeed = -ySpeed; } // set position back to when the ghost isn't colliding setPosition(tempX, tempY); } } // the player is above the ghost else if (player.rect.Y <= rect.Y) { if (randGen.Next(0, 10) > 5) { ySpeed = -ySpeed; xSpeed = 0; // set position back to when the ghost isn't colliding setPosition(tempX, tempY); } else if (randGen.Next(0, 10) > 8) { xSpeed = -xSpeed; ySpeed = 0; // set position back to when the ghost isn't colliding setPosition(tempX, tempY); } else { // pac-man is to the left if (player.rect.X < rect.X) { ySpeed = 0; xSpeed = -GameScreen.GHOST_SPEED; } else { ySpeed = 0; xSpeed = GameScreen.GHOST_SPEED; } // set position back to when the ghost isn't colliding setPosition(tempX, tempY); } } } else if (behavior == "sneaky") { } if (behavior == "patrol") { xSpeed = GameScreen.GHOST_SPEED; ySpeed = 0; } else { xSpeed = -xSpeed; } }
public void Draw(SpriteBatch spriteBatch, GameTime gameTime) { DrawBoard(spriteBatch); // Draw items for (int y = 0; y < TilesHigh; y++) { for (int x = 0; x < TilesWide; x++) { if (_tileItems[x, y] != null) { _tileItems[x, y].Draw(spriteBatch, gameTime); } } } #if DEBUG if (!HideBlinky) { DrawGhostDirection(spriteBatch, Blinky); } if (!HidePinky) { DrawGhostDirection(spriteBatch, Pinky); } if (!HideInky) { DrawGhostDirection(spriteBatch, Inky); } if (!HideClyde) { DrawGhostDirection(spriteBatch, Clyde); } #endif PacMan.Draw(spriteBatch, gameTime); if (!HideBlinky) { Blinky.Draw(spriteBatch, gameTime); } if (!HidePinky) { Pinky.Draw(spriteBatch, gameTime); } if (!HideInky) { Inky.Draw(spriteBatch, gameTime); } if (!HideClyde) { Clyde.Draw(spriteBatch, gameTime); } // Fruit if (Fruit != null) { Fruit.Draw(spriteBatch, gameTime); } // Effects for (int i = 0; i < Effects.Count; i++) { Effects[i].Draw(spriteBatch, gameTime); } // HUD DrawHud(spriteBatch); }
public void Update(GameTime gameTime) { // Next level? if (DotsLeft + EnergizersLeft == 0) { NextLevel(); } PacMan.Update(gameTime); if (!HideBlinky) { Blinky.Update(gameTime); } if (!HidePinky) { Pinky.Update(gameTime); } if (!HideInky) { Inky.Update(gameTime); } if (!HideClyde) { Clyde.Update(gameTime); } if (Fruit != null) { Fruit.Update(gameTime); if (!Fruit.IsFlashing && Fruit.Duration < 5) { Fruit.Flash(4, 8); } if (Fruit.Duration < 0) { Fruit = null; } } if (_ghostModeDuration > 0) { _ghostModeDuration -= gameTime.ElapsedGameTime.TotalSeconds; } if (_ghostModeDuration <= 0) { GhostMode = GhostMode.Chase; } // Frightened mode if (GhostMode == GhostMode.Frightened && !Inky.IsFlashing && _ghostModeDuration <= _ghostModeBeginFlashing) { Blinky.Flash(_ghostModeBeginFlashing, _ghostModeFlashes); Pinky.Flash(_ghostModeBeginFlashing, _ghostModeFlashes); Inky.Flash(_ghostModeBeginFlashing, _ghostModeFlashes); Clyde.Flash(_ghostModeBeginFlashing, _ghostModeFlashes); } // Effects for (int i = 0; i < Effects.Count; i++) { Effects[i].Update(gameTime); } }