Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Map_Generation
- {
- class Program
- {
- static void Main(string[] args)
- {
- int width = 6;
- int height = 6;
- int[,,,] land = new int[width,height, 1, 1];
- int amountOfLand;
- int[] assignedLand = new int[width];
- int number;
- Random randNumGen = new Random();
- amountOfLand = (((width * height) / 36) * 25);
- //Runs a for loop to place land, only places land if there is 4 or less pieces of land in the current row
- while (amountOfLand > 0)
- {
- for (int i = 0; i < width; i++)
- {
- for(int j = 0; j < height; j++)
- {
- if (land[i, j, 0, 0] == 0 && amountOfLand > 0 && assignedLand[i] <= 4)
- {
- number = randNumGen.Next(1, 5);
- if (number <= 3)
- {
- land[i, j, 0, 0] = 1;
- amountOfLand--;
- assignedLand[i]++;
- }
- else
- {
- land[i, j, 0, 0] = 0;
- }
- }
- }
- }
- }
- //Code to check for any land isolated from all other land
- for (int i = 0; i < width; i++)
- {
- for (int j = 0; j < height; j++)
- {
- if (land[i, j, 0, 0] == 1)
- {
- int numberOfNeighbours = 0;
- if ((i - 1) > 0)
- {
- if (land[(i - 1), j, 0, 0] == 1)
- {
- numberOfNeighbours++;
- }
- }
- if ((i - 1) > 0 && (j + 1) < width)
- {
- if (land[(i - 1), (j + 1), 0, 0] == 1)
- {
- numberOfNeighbours++;
- }
- }
- if ((j + 1) < width)
- {
- if (land[i, (j + 1), 0, 0] == 1)
- {
- numberOfNeighbours++;
- }
- }
- if ((i + 1) < height && (j + 1) < width)
- {
- if (land[(i + 1), (j + 1), 0, 0] == 1)
- {
- numberOfNeighbours++;
- }
- }
- if ((i + 1) < height)
- {
- if (land[(i + 1), j, 0, 0] == 1)
- {
- numberOfNeighbours++;
- }
- }
- if ((i + 1) < height && (j - 1) > 0)
- {
- if (land[(i + 1), (j - 1), 0, 0] == 1)
- {
- numberOfNeighbours++;
- }
- }
- if ((j - 1) > 0)
- {
- if (land[i, (j - 1), 0, 0] == 1)
- {
- numberOfNeighbours++;
- }
- }
- if ((i - 1) > 0 && (j - 1) > 0)
- {
- if (land[(i - 1), (j - 1), 0, 0] == 1)
- {
- numberOfNeighbours++;
- }
- }
- if (numberOfNeighbours == 0)
- {
- Console.WriteLine("There are no neighbours at " + i + " " + j);
- }
- }
- }
- }
- for (int i = 0; i < width; i++)
- {
- for (int j = 0; j < height; j++)
- {
- if (land[i, j, 0, 0] == 0)
- {
- Console.Write("0 ");
- }
- else
- {
- Console.Write("1 ");
- }
- }
- Console.WriteLine();
- }
- Console.WriteLine(amountOfLand);
- }
- }
- }
Add Comment
Please, Sign In to add comment