public void Setup_Tests() { _dataContext = IoC.Resolve<IDataContext>(); var world = new World(); using (var tran = _dataContext.WorldRepository.Session.BeginTransaction()) { world.Height = 5; world.Width = 5; world.Name = "unit_test_world"; for (var y = 1; y <= world.Width; y++) { for (var x = 1; x <= world.Height; x++) { world.AddHex(new Hex { World = world, HexType = HexType.Plain , X = x, Y = y }); } } _dataContext.WorldRepository.Save(world); tran.Commit(); } _worldId = world.Id; }
public void Create_World_And_Hexes() { var race = new Race { Name = "Default Race" }; var nation = new Nation { Name = "Default Nation", Race = race }; var user = new User { Email = "*****@*****.**", FirstName = "Jamie", LastName = "Fraser", OpenId = "http://jamief00.myopenid.com/" }; var world = new World { Height = 100, Width = 100, Name = "Default World" }; var game = new Game { Name = "Default Game", Started = DateTime.Now, GameWorld = world}; var gameSession = new GameSession { EnteredGame = DateTime.Now, Nation = nation, Game = game, User = user }; using (var tran = _dataContext.WorldRepository.Session.BeginTransaction()) { _dataContext.RaceRepository.Save(race); _dataContext.NationRepository.Save(nation); _dataContext.UserRepository.Save(user); _dataContext.GameRepository.Save(game); _dataContext.WorldRepository.Save(world); _dataContext.GameSessionRepository.Save(gameSession); for (var y = 1; y <= world.Width; y++) { for (var x = 1; x <= world.Height; x++) { var hex = new Hex { World = world, HexType = HexType.Grass, X = x, Y = y }; _dataContext.HexRepository.Save(hex); } } tran.Commit(); } }
private static string GetCountForType(HexType hexType, World w) { const string stats = "Total {0} : {1} ({2}%)"; var totalHexesOfType = w.TotalHexesOfType(hexType); var percentage = totalHexesOfType/(double)w.TotalHexes * 100; return string.Format(stats, hexType, totalHexesOfType, percentage); }
//TODO: inject repository / datacontext //TODO: use service locator public static World Create(int height, int width) { var world = new World { Height = height, Width = width, Name = "TestWorld" }; for (var y = 1; y <= world.Width; y++) { for (var x = 1; x <= world.Height; x++) { world.AddHex(new Hex { World = world, HexType = HexType.Grass, X = x, Y = y }); } } // should persist? return world; }
public static GameSession CreateSession(User user, Race race) { var nation = new Nation { Name = "Default Nation", Race = race }; var world = new World { Height = 100, Width = 100, Name = "Default World" }; var game = new Game { Name = "Default Game", Started = DateTime.Now, GameWorld = world }; var gameSession = new GameSession { EnteredGame = DateTime.Now, Nation = nation, Game = game, User = user }; for (var y = 1; y <= world.Width; y++) { for (var x = 1; x <= world.Height; x++) { world.AddHex(new Hex { World = world, HexType = HexType.Grass, X = x, Y = y }); } } nation.AddUnit(new Unit()); nation.AddUnit(new Unit()); nation.AddUnit(new Unit()); nation.AddUnit(new Unit()); return gameSession; }
public static GameSession CreateGameSession() { var race = new Race { Name = "Default Race", Description = "Test Race not used in the actual game."}; var nation = new Nation { Name = "Default Nation", Race = race }; var user = new User { Email = "*****@*****.**", FirstName = "Jamie", LastName = "Fraser", OpenId = "http://jamief00.mytestopenid.com/" }; var world = new World { Height = 100, Width = 100, Name = "Default World" }; var game = new Game { Name = "Default Game", Started = DateTime.Now, GameWorld = world}; var gameSession = new GameSession { EnteredGame = DateTime.Now, Nation = nation, Game = game, User = user }; for (var y = 1; y <= world.Width; y++) { for (var x = 1; x <= world.Height; x++) { world.AddHex(new Hex { World = world, HexType = HexType.Grass, X = x, Y = y }); } } nation.AddUnit(new Unit()); nation.AddUnit(new Unit()); nation.AddUnit(new Unit()); nation.AddUnit(new Unit()); return gameSession; }
public static Game Create(World world) { return new Game {GameWorld = world, Name = "default_new_game", Started = DateTime.Now}; }
public void World_Delete() { var world = new World(); using (var tran = _dataContext.WorldRepository.Session.BeginTransaction()) { world.Height = 1000; world.Width = 1000; world.Name = "unit_test_world"; _dataContext.WorldRepository.Save(world); _dataContext.WorldRepository.Delete(world); tran.Commit(); } Assert.IsNull(_dataContext.WorldRepository.Get(world.Id)); }
private static void Run() { Console.Write("Please enter width in pixels : "); var width = int.Parse(Console.ReadLine()); Console.Write("Please enter height in pixels : "); var height = int.Parse(Console.ReadLine()); Console.Write("Press 1 to use Perlin, 2 to use Improved Perlin : "); if(int.Parse(Console.ReadLine()) == 1) _noiseGenerator = new Perlin(); else _noiseGenerator = new PerlinImproved(); //Console.Write("Please enter Frequency (0.01) : "); //_noiseGenerator.Frequency = float.Parse(Console.ReadLine()); //Console.Write("Please enter Amplitude (4.8) : "); //_noiseGenerator.Amplitude = float.Parse(Console.ReadLine()); //Console.Write("Please enter Persistence (0.9) : "); //_noiseGenerator.Persistence = float.Parse(Console.ReadLine()); //Console.Write("Please enter Octaves (2) : "); //_noiseGenerator.Octaves = int.Parse(Console.ReadLine()); var terrain = new double[width * height]; var normalisedTerrain = new double[width*height]; var counter = 0; for(var y=0; y<height; y++) { for(var x=0; x<width; x++) { terrain[counter++] = _noiseGenerator.Compute(x, y); } } var normalisedValues = Normalisation.CalculateInitialValues(terrain, 0, 255); var count = 0; var imageX = 0; var imageY = 0; var outputImage = new Bitmap(width, height); foreach (var value in terrain) { var normalisedValue = (int)Normalisation.Normalise(normalisedValues, value); normalisedTerrain[count++] = normalisedValue; outputImage.SetPixel(imageX++, imageY, Color.FromArgb(normalisedValue, normalisedValue, normalisedValue)); if (imageX != outputImage.Width) continue; imageY++; imageX = 0; } double row = 0; const int gridSize = 1; var w = new World() {Name = "Default", Id = Guid.NewGuid()}; for (var y = 0; y < height; y++) { row = (row + 2) % 2 == 0 ? 1 : 0; for (var x = 0; x < width; x++) { var xx = ((x + 1) * (gridSize * 2)); if ((y + 2) % 2 != 0) { xx = ((x + 1) * (gridSize * 2)) - gridSize; } var yy = (int)((y * gridSize) * 0.5); w.AddHex(new Hex() { HexType = GetHexType(GetHeight(normalisedTerrain, xx, yy, width)), Id = Guid.NewGuid(), X = xx, Y = yy }); row += 2; } } Console.WriteLine("Total Hexes : " + w.TotalHexes); Console.WriteLine(GetCountForType(HexType.Ocean, w)); Console.WriteLine(GetCountForType(HexType.Sea, w)); Console.WriteLine(GetCountForType(HexType.Beach, w)); Console.WriteLine(GetCountForType(HexType.Plain, w)); Console.WriteLine(GetCountForType(HexType.Grass, w)); Console.WriteLine(GetCountForType(HexType.Trees, w)); Console.WriteLine(GetCountForType(HexType.Jungle, w)); Console.WriteLine(GetCountForType(HexType.Hill, w)); Console.WriteLine(GetCountForType(HexType.Mountain, w)); outputImage.Save(@"c:\temp\map.jpg"); Process.Start(@"c:\temp\map.jpg"); Console.ReadKey(); }