public void Update(float time, Grid grid, Pacman pacman, GhostNames name) { totalTime += time; //Frightened if (grid.IsPelletActive) { if (iPos == pacman.iPos && jPos == pacman.jPos) { switch (name) { case GhostNames.blinky: iPos = 11; jPos = 13; Score.EatGhost(); break; case GhostNames.clyde: iPos = 13; jPos = 11; Score.EatGhost(); break; case GhostNames.inky: iPos = 13; jPos = 13; Score.EatGhost(); break; case GhostNames.pinky: iPos = 15; jPos = 13; Score.EatGhost(); break; } } ChangeToFrightenedMode(); distances = PathFinding.InitMoves(distances, iPos, jPos); PathFinding.CalculateMoves(grid, iPos, jPos, pacman.iPos, pacman.jPos, ref distances); nextMove = PathFinding.FindFirstMove(distances, pacman.iPos, pacman.jPos, pacman.iPos, pacman.jPos, nextMove); } //chase else { Score.ResetMultipler(); switch (name) { case GhostNames.blinky: body.FillColor = Color.Red; break; case GhostNames.clyde: body.FillColor = Color.Green; break; case GhostNames.inky: body.FillColor = Color.Cyan; break; case GhostNames.pinky: body.FillColor = Color.Magenta; break; } distances = PathFinding.InitMoves(distances, iPos, jPos); PathFinding.CalculateMoves(grid, iPos, jPos, pacman.iPos, pacman.jPos, ref distances); nextMove = PathFinding.FindFirstMove(distances, pacman.iPos, pacman.jPos, pacman.iPos, pacman.jPos, nextMove); if (iPos == pacman.iPos && jPos == pacman.jPos && !GotPacman) { GotPacman = true; pacman.Caught(); } } if (totalTime > 0.2f) { totalTime = 0; switch (nextMove) { case Direction.Down: jPos++; break; case Direction.Left: iPos--; break; case Direction.Right: iPos++; break; case Direction.Up: jPos--; break; } } }