コード例 #1
0
        public static void Main(string[] args)
        {
            UnitTester tester = new UnitTester();
            Unit unit = new Unit(1000);

            tester.TestType(unit, "infantry", "infantry");
            tester.TestUnitSpecificProperty(unit, "hitPoints", new String('a', 'b'), new String('a', 'b'));
            tester.TestChangeProperty(unit, "hitPoints", new String('c', 'd'), new String('c', 'd'));
            tester.TestNonExistentProperty(unit, "strength");
        }
コード例 #2
0
        public void TestType(Unit unit, String type, String expectedOutputType)
        {
            Console.WriteLine("\nTesting setting/getting the property type.");
            unit.Type = type;

            string outputType = unit.Type;

            if (expectedOutputType.Equals(outputType))
                Console.WriteLine("Test passed");
            else
                Console.WriteLine("Test failed: " + outputType + " didn't match " + expectedOutputType);
        }
コード例 #3
0
        public void TestUnitSpecificProperty(Unit unit, String propertyName,
            Object inputValue, Object expectedOutputValue)
        {
            Console.WriteLine("\nTesting setting/getting a unit-specific property");
            unit.SetProperty(propertyName, inputValue);

            Object outputValue = unit.GetProperty(propertyName);

            if (expectedOutputValue.Equals(outputValue))
                Console.WriteLine("Test passed");
            else
                Console.WriteLine("Test failed: " + outputValue + " didn't match " + expectedOutputValue);
        }
コード例 #4
0
        public void TestChangeProperty(Unit unit, String propertyName,
            Object inputValue, Object expectedOutputValue)
        {
            Console.WriteLine("\nTesting changing an existing property's value");
            unit.SetProperty(propertyName, inputValue);

            Object outputValue = unit.GetProperty(propertyName);

            if (expectedOutputValue.Equals(outputValue))
                Console.WriteLine("Test passed");
            else
                Console.WriteLine("Test failed: " + outputValue + " didn't match " + expectedOutputValue);
        }
コード例 #5
0
 public void TestNonExistentProperty(Unit unit, String propertyName)
 {
     Console.WriteLine("\nTesting getting a non-existent property's value");
     Object outputValue;
     try
     {
         outputValue = unit.GetProperty(propertyName);
     }
     catch (SystemException e)
     {
         Console.WriteLine("Test passed");
         return;
     }
     Console.WriteLine("Test failed with value of " + outputValue);
 }
コード例 #6
0
 public void RemoveUnit(Unit unit)
 {
     units.Remove(unit.Id);
 }
コード例 #7
0
 public void AddUnit(Unit unit)
 {
     units.Add(unit.Id, unit);
 }
コード例 #8
0
 public void RemoveUnit(Unit unit, int x, int y)
 {
     Tile tile = GetTile(x, y);
     tile.RemoveUnit(unit);
 }
コード例 #9
0
 public void AddUnit(Unit unit, int x, int y)
 {
     Tile tile = GetTile(x, y);
     tile.AddUnit(unit);
 }