// Check where the player can build commertial facility // no accupied tile. public override bool[,] BuildCheck(Building[,] map) { //Array for available build locations bool[,] availableLocationC = new bool[map.GetLength(0), map.GetLength(1)]; //Variable to define if there's a residential facility present bool residentialFacilitiesPresent = false; for (int row = 0; row < map.GetLength(0); row++) { // Loops throught the columns of the map. for (int column = 0; column < map.GetLength(1); column++) { // if the lacation is not taken then the location is available. if (map[column, row] == null) { // y axis for the commertil building. for (int yAxis = row - 6; yAxis <= row + 6; yAxis++) { // Calculates the direction on x axis. int xAxisDirection = 6 - Math.Abs(row - yAxis); //Loop for the x axis for (int xAxis = column + xAxisDirection; xAxis >= column - xAxisDirection; xAxis--) { // x and y Axis can not be a be a negative number. if (xAxis >= 0 && xAxis < map.GetLength(0) && yAxis >= 0 && yAxis < map.GetLength(1)) { //If there is a residential facility within 6 spaces if (map[xAxis, yAxis] is Residential_Facilities && Math.Abs(xAxis - column) <= 6 && Math.Abs(yAxis - row) <= 6) { residentialFacilitiesPresent = true; } } } } // defines there is a commercial facility. if (residentialFacilitiesPresent == true && SimSpace.IsThereARoadAdjacent(map, column, row) == true) { //Set the build location to true availableLocationC[column, row] = true; } //Set residentialfacilities present back to false residentialFacilitiesPresent = false; } } } return(availableLocationC); }
/// <summary> /// Virtual subprogram to check the map onto where the player can build /// </summary> /// <param name="map">the current state of the map</param> /// <returns>a boolean array reflecting where the player</returns> public virtual bool[,] BuildCheck(Building[,] map) { //Create a boolean array of map length and height to store where buildings can be built bool[,] availableBuildLocations = new bool[map.GetLength(0), map.GetLength(1)]; //Scan the whole map for areas with no building on it, and set those areas to true for (int row = 0; row < map.GetLength(0); row++) { for (int col = 0; col < map.GetLength(1); col++) { //If there is no building in the current location and there is a road beside the current location if (map[row, col] == null && SimSpace.IsThereARoadAdjacent(map, row, col) == true) { //Flag it as true availableBuildLocations[row, col] = true; } } } //Return the availableBuildLocations return(availableBuildLocations); }
/// <summary> /// Checks if the industrial faclity can be placed at a specific area. Checks to see is if the industrial facility is within the designated range of residential facilities. /// </summary> /// <param name="map">The grid.</param> /// <returns>availableLocationI</returns> public override bool[,] BuildCheck(Building[,] map) { // sets the available loacation for the industrial facility on the map(25 X 25). bool[,] availableLocationI = new bool[map.GetLength(0), map.GetLength(1)]; // Sets the bool if that location is taken by a factory or resicential facility. bool powerPlantPresent = false; bool isThereResidentialFacilities = false; // Loops throught the rows of the map. for (int row = 0; row < map.GetLength(0); row++) { // Loops throught the columns of the map. for (int column = 0; column < map.GetLength(1); column++) { // if the lacation is not taken then the location is available. if (map[column, row] == null) { // y axis for the industrial building. for (int yAxis = row - 6; yAxis <= row + 6; yAxis++) { // Calculates the direction on x axis. int xAxisDirection = 6 - Math.Abs(row - yAxis); //for (int xAxis = column + xAxisDirection; xAxis >= column - xAxisDirection; xAxis--) for (int xAxis = column + xAxisDirection; xAxis >= column - xAxisDirection; xAxis--) { // x and y Axis can not be a be a negative number. if (xAxis >= 0 && xAxis < map.GetLength(0) && yAxis >= 0 && yAxis < map.GetLength(1)) { // checks if there is a residential facility. if (map[xAxis, yAxis] is Residential_Facilities && Math.Abs(xAxis - column) <= 6 && Math.Abs(yAxis - row) <= 6) { // true, there is a recidential facility. isThereResidentialFacilities = true; } else if (map[xAxis, yAxis] is PowerPlant) { powerPlantPresent = true; } } } } // defines there is a industria facility. if (powerPlantPresent == true && isThereResidentialFacilities == false && SimSpace.IsThereARoadAdjacent(map, column, row)) { //Set the location to true availableLocationI[column, row] = true; } powerPlantPresent = false; isThereResidentialFacilities = false; } } } // returns the location of the industirial facility. return(availableLocationI); }
/// <summary> /// Check if tile is available for building a Residential Facility, must be within 8 tile range of all 5 different essential services, and 6 tiles away from industrial facilities /// </summary> /// <param name="map"></param> /// <returns>available tile</returns> public override bool[,] BuildCheck(Building[,] map) { bool[,] availableTile = new bool[map.GetLength(0), map.GetLength(1)]; bool isThereSchool = false; bool isThereMedical = false; bool isThereGovernment = false; bool isThereIndustrial = false; bool isTherePowerPlant = false; bool isThereEmergencyServices = false; for (int row = 0; row < map.GetLength(0); row++) { for (int column = 0; column < map.GetLength(1); column++) { if (map[column, row] == null) { for (int y = row - 8; y <= row + 8; y++) { int xdistance = 8 - Math.Abs(row - y); for (int x = column + xdistance; x >= column - xdistance; x--) { if (x >= 0 && x < map.GetLength(0) && y >= 0 && y < map.GetLength(1)) { if (map[x, y] is School) { isThereSchool = true; } else if (map[x, y] is Medical) { isThereMedical = true; } else if (map[x, y] is PowerPlant) { isTherePowerPlant = true; } else if (map[x, y] is Government) { isThereGovernment = true; } else if (map[x, y] is EmergencyServices) { isThereEmergencyServices = true; } else if (map[x, y] is Industrial && Math.Abs(x - column) <= 6 && Math.Abs(y - row) <= 6) { isThereIndustrial = true; } } } } if (isThereSchool == true && isThereMedical == true && isThereGovernment == true && isTherePowerPlant == true && isThereEmergencyServices == true && isThereIndustrial == false && SimSpace.IsThereARoadAdjacent(map, column, row) == true) { availableTile[column, row] = true; } isThereSchool = false; isThereMedical = false; isThereGovernment = false; isTherePowerPlant = false; isThereIndustrial = false; isThereEmergencyServices = false; } } } return(availableTile); }
//Setup subprogram for when the form starts private void Setup() { //Set the form width and height this.Width = 1100; this.Height = 1050; DoubleBuffered = true; //Set the location of the labels lblPlayer.Location = new Point(850, this.Height / 15); lblBuilding.Location = new Point(850, this.Height / 7 * 3); //Set the width height and location of the picture boxes picEnviromental.Width = 80; picEnviromental.Height = 80; picEnviromental.Location = new Point(this.Width / 20, 32 * 22 - 10); picEssentialServices.Width = 80; picEssentialServices.Height = 80; picEssentialServices.Location = new Point(this.Width / 20 * 4, 32 * 22 - 10); picIndustrial.Width = 80; picIndustrial.Height = 80; picIndustrial.Location = new Point(this.Width / 20 * 7, 32 * 22 - 10); picResidential.Width = 80; picResidential.Height = 80; picResidential.Location = new Point(this.Width / 20 * 10 + 10, 32 * 22 - 10); picCommerical.Width = 80; picCommerical.Height = 80; picCommerical.Location = new Point(this.Width / 20 * 14 - 15, 32 * 22 - 10); picRoad.Width = 80; picRoad.Height = 80; picRoad.Location = new Point(this.Width / 20 * 17 - 5, 32 * 22 - 10); picPark.Width = 80; picPark.Height = 80; picPark.Location = new Point(this.Width / 20, 32 * 32 - 10); picEnviromentalFacility.Width = 80; picEnviromentalFacility.Height = 80; picEnviromentalFacility.Location = new Point(this.Width / 20 * 4, 32 * 22 - 10); picSchool.Width = 80; picSchool.Height = 80; picSchool.Location = new Point(this.Width / 20, 32 * 22 - 10); picMedical.Width = 80; picMedical.Height = 80; picMedical.Location = new Point(this.Width / 20 * 4, 32 * 22 - 10); picGovernment.Width = 80; picGovernment.Height = 80; picGovernment.Location = new Point(this.Width / 20 * 7, 32 * 22 - 10); picEmergencyService.Width = 80; picEmergencyService.Height = 80; picEmergencyService.Location = new Point(this.Width / 20 * 10 + 10, 32 * 22 - 10); picPowerPlant.Width = 80; picPowerPlant.Height = 80; picPowerPlant.Location = new Point(this.Width / 20 * 14 - 15, 32 * 22 - 10); picFactory.Width = 80; picFactory.Height = 80; picFactory.Location = new Point(this.Width / 20, 32 * 22 - 10); picRestaurant.Width = 80; picRestaurant.Height = 80; picRestaurant.Location = new Point(this.Width / 20, 32 * 22 - 10); picStore.Width = 80; picStore.Height = 80; picStore.Location = new Point(this.Width / 20 * 4, 32 * 22 - 10); picOffice.Width = 80; picOffice.Height = 80; picOffice.Location = new Point(this.Width / 20 * 7, 32 * 22 - 10); picAffordableHome.Width = 80; picAffordableHome.Height = 80; picAffordableHome.Location = new Point(this.Width / 20, 32 * 22 - 10); picComfortableHome.Width = 80; picComfortableHome.Height = 80; picComfortableHome.Location = new Point(this.Width / 20 * 4, 32 * 22 - 10); picLuxaryHome.Width = 80; picLuxaryHome.Height = 80; picLuxaryHome.Location = new Point(this.Width / 20 * 7, 32 * 22 - 10); picBack.Width = 80; picBack.Height = 80; picBack.Location = new Point(this.Width / 20 * 17 - 5, 32 * 22 - 10); //Hide picture boxes which are not on the inital menu picPark.Visible = false; picBack.Visible = false; picEnviromentalFacility.Visible = false; picSchool.Visible = false; picGovernment.Visible = false; picPowerPlant.Visible = false; picEmergencyService.Visible = false; picMedical.Visible = false; picFactory.Visible = false; picOffice.Visible = false; picRestaurant.Visible = false; picStore.Visible = false; picComfortableHome.Visible = false; picAffordableHome.Visible = false; picLuxaryHome.Visible = false; lblGameOver.Visible = false; //Create and store the map map = SimSpace.CreateMap(15, 15); //Set the game over text lblGameOver.Text = "Game over! Thanks for playing!"; }