Skip to content

Instantly share code, notes, and snippets.

@0x1mason
Last active December 26, 2017 03:15
Show Gist options
  • Save 0x1mason/ba1e44cc8853f7635abb1906184da1fd to your computer and use it in GitHub Desktop.
Save 0x1mason/ba1e44cc8853f7635abb1906184da1fd to your computer and use it in GitHub Desktop.
ground
using System.Collections.Generic;
namespace Andrey
{
public enum Terrain
{
Forest,
MountainForest,
Marsh,
Desert,
Arable,
Pasture,
Unused
}
public enum Relief
{
Mountains,
Hills,
Plains
}
public class Ground
{
public Dictionary<Relief, double> ReliefByPercent { get; set; }
public Dictionary<Terrain, double> TerrainByPercent { get; set; }
public int VolumeDrinkingWater { get; set; }
public int Fertility { get; set; }
public Ground (int volWater, int fertility)
{
this.VolumeDrinkingWater = volWater;
this.Fertility = fertility;
this.ReliefByPercent = new Dictionary<Relief, double>();
this.TerrainByPercent = new Dictionary<Terrain, double>();
}
}
class Program
{
static void Main (string[] args)
{
Ground ground = new Ground(1, 1);
// SET
ground.ReliefByPercent.Add(Relief.Plains, .50);
ground.ReliefByPercent.Add(Relief.Mountains, .50);
ground.TerrainByPercent.Add(Terrain.Arable, .33);
ground.TerrainByPercent.Add(Terrain.Marsh, .33);
ground.TerrainByPercent.Add(Terrain.Forest, .33);
// GET
double plainsPercent = ground.ReliefByPercent[Relief.Plains];
double arablePercent = ground.TerrainByPercent[Terrain.Arable];
// ITERATE
foreach (KeyValuePair<Terrain, double> keyValue in ground.TerrainByPercent)
{
double percentage = keyValue.Value;
if (keyValue.Key == Terrain.Arable)
{
// ...
}
else if (keyValue.Key == Terrain.Pasture)
{
// ...
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment