/// <summary> /// Initializes a new instance of the /// <see cref="T:Projeto_LP2e.Render"/> class. /// Constructor that recives the GameSetup and the World variables. /// </summary> /// <param name="gs">GameSetup.</param> /// <param name="w">World.</param> public Render(GameSetup gs, World w) { this.gs = gs; this.w = w; }
/// <summary> /// Initializes a new instance of the /// <see cref="T:Projeto_LP2e.World"/> class. /// Constructor that puts the agent in the grid. /// </summary> /// <param name="gs">Gs.</param> public World(GameSetup gs) { //Creates a new grid. grid = new IGameObject[gs.Row, gs.Col]; //Creates the total agents. agents = new Agent[gs.NZombies + gs.NHumans]; //Calls the function to populate the grid. PopulateGrid(); //Row and column variables. int row, col; //Variable that count the playable agents. int playableCount = 0; //Go trough all the human agents. for (int i = 0; i < gs.NHumans; i++) { //while the founded position is an agent, keep searching for an //empty position. do { row = rand.Next(0, gs.Row - 1); col = rand.Next(0, gs.Col - 1); }while (grid[row, col] is Agent); //Creates AI agents of the Human type if (playableCount >= gs.NPlayHumans) { grid[row, col] = new Agent_AI(Type.Human, row, col, i); } //Creates playable agents of human type and increments the //playableCount variable by one for each agent created. else { grid[row, col] = new Agent_Play(Type.Human, row, col, i); playableCount++; } } //Sets the playableCount to 0. playableCount = 0; //Go through all the Zombie agents. for (int i = gs.NHumans; i < gs.NHumans + gs.NZombies; i++) { //while the founded position is an agent, keep searching for an //empty position. do { row = rand.Next(0, gs.Row - 1); col = rand.Next(0, gs.Col - 1); }while (grid[row, col] is Agent); //Creates AI agents of the Zombie type if (playableCount >= gs.NPlayZombies) { grid[row, col] = new Agent_AI(Type.Zombie, row, col, i); } //Creates playable agents of zombie type and increments the //playableCount variable by one for each agent created. else { grid[row, col] = new Agent_Play(Type.Zombie, row, col, i); playableCount++; } } //Call the method to populate array to shuffle. PopulateArrayToShuffle(); }