public void TestSpendMoney(SpendMoneyTestCase testCase) { var economySimulation = new EconomySimulation( initialMoney: testCase.InitialMoney, getIncome: null, getUpkeepCosts: null ); TestDelegate spendMoney = () => { economySimulation.SpendMoney(testCase.SpendAmount); }; if (testCase.ExpectedException == null) { spendMoney(); } else { Assert.Throws( Is.InstanceOf(testCase.ExpectedException.GetType()) .And.Message.EqualTo( testCase.ExpectedException.Message ) .And.Property("Data").EqualTo( testCase.ExpectedException.Data ), spendMoney ); } Assert.That( economySimulation.AvailableMoney, Is.EqualTo(testCase.ExpectedAvailableMoney) ); }
public void TestCanAfford(CanAffordTestCase testCase) { var economySimulation = new EconomySimulation( initialMoney: testCase.InitialMoney, getIncome: null, getUpkeepCosts: null ); if (testCase.ExpectedException == null) { Assert.That( economySimulation.CanAfford(testCase.Amount), Is.EqualTo(testCase.ExpectedCanAfford) ); } else { Assert.Throws( Is.InstanceOf(testCase.ExpectedException.GetType()) .And.Message.EqualTo( testCase.ExpectedException.Message ) .And.Property("Data").EqualTo( testCase.ExpectedException.Data ), () => { economySimulation.CanAfford(testCase.Amount); } ); } }
public void TickMoney(TickTestCase testCase) { var economySimulation = new EconomySimulation( initialMoney: testCase.InitialMoney, getIncome: testCase.GetIncome, getUpkeepCosts: testCase.GetUpkeepCosts ); TestDelegate tick = () => { economySimulation.Tick(); }; if (testCase.ExpectedException == null) { tick(); } else { Assert.Throws( Is.InstanceOf(testCase.ExpectedException.GetType()) .And.Message.EqualTo( testCase.ExpectedException.Message ) .And.Property("Data").EqualTo( testCase.ExpectedException.Data ), tick ); } Assert.That( economySimulation.AvailableMoney, Is.EqualTo(testCase.ExpectedAvailableMoney) ); }
// Setup game. // initialMoney: The initially available money. // economyTickInterval: // The number of game ticks that elapse between economy ticks. // incomePerEconomyTick: // Amount of Money that is added for each economy tick. public Game( IMapGenerator mapGenerator, MapTileSpawner spawnMapTile, IMapToWorldMapper mapToWorldMapper, int initialMoney, int incomePerEconomyTick, int economyTickInterval ) { this.Map = SpawnMap( mapGenerator: mapGenerator, spawnMapTile: spawnMapTile, mapToWorldMapper: mapToWorldMapper ); this.MapToWorldMapper = mapToWorldMapper; WorldSize = mapToWorldMapper.GetWorldSize( mapWidth: this.Map.Width, mapHeight: this.Map.Height ); Economy = new EconomySimulation( initialMoney: initialMoney, getIncome: () => incomePerEconomyTick, getUpkeepCosts: GetUpkeepCosts ); EconomyTickInterval = economyTickInterval; TicksUntilEconomyTick = economyTickInterval; this.Warehouse = new Warehouse(); //Debug.Log(Map.getNeighboursOfTile(0, 0)[1]); }