public void Initialize() { //Initialize game if started for the first time if (this.IsInicialize == false) { this.IsInicialize = true; this.InitializeMatrix(); this.InicializeFruits(); this.DrawContent(); this.InicializeLeftScores(); this.TaskRenderingPacMan = new Task(this.RenderPacMan); this.TaskRenderingGhost = new Task(this.RenderGhost); this.PacMan = new PacMan(0, 0, this.GraphicsPacMan); for (int i = 0; i < Global.GhostElements; i++) { Ghosts.Add(new Ghost(PacMan.PositionQuadrantX, PacMan.PositionQuadrantY, this.GraphicsGhost)); } this.TaskRenderingPacMan.Start(); this.TaskRenderingGhost.Start(); Control.CheckForIllegalCrossThreadCalls = false; } else { this.DrawContent(); } }
public void LoadLevel(Level level) { State = GameState.Initialising; Level = level; Ghosts.Clear(); foreach (var ghost in level.Ghosts) { Ghosts.Add(new Ghost(ghost.X, ghost.Y, ghost.Logic)); } ResetCharacters(); FillPellets(); HasWon = false; }
/// <summary> /// Initialize the instance. This method MUST BE called before using this class. /// </summary> /// <param name="maze">The current maze</param> /// <param name="pac">The pac the user is playing</param> /// <param name="leader">The leader of the ghost (often, it is Blinky, the red ghost)</param> /// <param name="others">Array containing the others ghosts (all ghosts except the leader)</param> public void Initialize(Maze maze, Pac pac, Ghost leader, Ghost[] others) { PlayBeginning = -1; if (Ghosts == null) { Ghosts = new List <Ghost>(4); } else { Ghosts.Clear(); } Map = maze; Pac = pac; Ghosts.Add(leader); Ghosts.AddRange(others); // Search startup points for every ghosts List <Cell> list = Map.SearchTile(TileType.BLINKY_STARTUP); if (list != null && list.Count > 0) { Vector3 result = list[0].Dimension.Min; Ghosts[0].StartingPoint = Entrance = new Vector2(result.X, result.Y); // Now, the program must find the start area for the other ghosts list = Map.SearchTile(TileType.GHOSTS_STARTUP); if (list != null && list.Count >= (Ghosts.Count - 1)) { for (int i = 1, maxi = Ghosts.Count; i < maxi; i++) { // 1 <= i <= Ghosts.Count, but Ghosts.Count-1 <= list.Count. Therefore, list[i-1] will not throw an ArrayOutOfBoundException result = list[i - 1].Dimension.Min; Ghosts[i].StartingPoint = new Vector2(result.X, result.Y); } } else { throw new InvalidOperationException("No start point for the ghosts in the maze"); } } else { throw new InvalidOperationException("No start point for Blinky in the maze"); } IsInitialized = true; }