Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
CommandForce1
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Hex { int height_index // location in map grid int width_index // location in map grid TerrainType terrain; // sea (default 0) or land (1) Hex[] myNeighbors = new Hex[6]; enum TileNeighbor {TOP_RIGHT, RIGHT, BOTTOM_RIGHT, BOTTOM_LEFT, LEFT, TOP_LEFT}; public Hex(int height_index, int width_index) this.height_index = height_index; this.width_index = width_index; // set all the neighbor tiles, 0 is the top-right tile, go clockwise (6 neighbors total) // check for TOP RIGHT neighbor if (height_index > 0) // not first row if (width_index / 2) // odd row if (width_index != mapWidth - 1) myNeighbors[HexNeighbor.TOP_RIGHT] = map_hexes[map_height - 1, map_width + 1]; else // even row myNeighbors[HexNeighbor.TOP_RIGHT] = map_hexes[map_height - 1, map_width]; // check RIGHT neighbor } public static void Main(string[] args) { //Your code goes here enum TerrainType {SEA, LAND}; // generate map int mapHeight = 20; int mapWidth = 30; Hex[ , ] map_hexes = new Hex[mapHeight, mapWidth]; // create all the tiles //Go across map, left to right, top to bottom public int INTERNAL_CHANCE = 95; // change this in testing until get good results int gradient = [get value from user, from 1 to 10]; // 5 is average, 10 more continental for (int height_index = 0; height_index<mapHeight; height_index++) { for (int width_index = 0; width_index<mapWidth; width_index++) { Hex hex = new Hex(height_index, width_index); hex.terrain = TerrainType.LAND; map_hexes[height_index][width_index] = hex; // Depending on gradient, have random chance of each hex being land. For low gradient=lower chance, high gradient=higher chance. int chance = Random.Range(1, 100) * gradient; if (chance >= INTERNAL_CHANCE) { //Change hex from SEA to LAND hex.terrain = TerrainType.LAND; } } } // After seeding island hexes throughout map grid, go to each land hex and generate neighboring land hexes based on random chance for each neighbor. As long as at least one neighbor generated (don't make a neighbor land if it is already land), keep going but chance to be land hex drops every time until chance reaches 0. Do this for each seeded land hex. List<Hex> neighborHexes = new List<Hex>(); // list of neighbors to go thru for (int height_index = 0; height_index<mapWidth; height_index++) { for (int width_index 0; width_index<mapHeight; width_index++) { if (hex.terrain == TerrainType.LAND) { // get all neighbors hexes here and add them to neighborHexes neighborHexes.clear(); GetNeighbors(hex); foreach (Hex neighbor_hex in neighborHexes) { // skip if already land if (Random.Range(1,2) == 1) { neighbor_hex.terrain = TerrainType.Land; } } } } } private void GetNeighbors(Hex hex) { hex.myNeighbors.Add( } } }
run
|
edit
|
history
|
help
0
Masking Credit Card Number
bc160400236
ASXs
Dungeon Game
CommandForce
extrefGenerate
Herencias
Everyone can sen ,only me can edi
Lottery
4. Inheritance