示例#1
0
文件: Stack.cs 项目: gmoller/Phoenix
        public Stack(int stackId)
        {
            _gameConfigCache = CallContext <GameConfigCache> .GetData("GameConfigCache");

            _gameDataRepository = CallContext <GameDataRepository> .GetData("GameDataRepository");

            _stackRecord = _gameDataRepository.GetStackById(stackId);
            var unitRecords = _gameDataRepository.GetUnitsByStackId(stackId);

            Units = new Units();
            foreach (var unitRecord in unitRecords)
            {
                Units.Add(new Unit(unitRecord.Id));
            }

            _gameDataRepository.StackUpdated += StackUpdated;
        }
示例#2
0
        public void Unit_tests()
        {
            var unitRecord = new UnitRecord(0, 1);

            _repo.Add(unitRecord);
            var id = unitRecord.Id;

            unitRecord = _repo.GetUnitById(id);
            var units = _repo.GetUnitsByStackId(1);

            Assert.AreEqual(id, unitRecord.Id);
            Assert.AreEqual(1, unitRecord.StackId.Value);
            Assert.AreEqual(0, unitRecord.UnitTypeId.Value);
            Assert.AreEqual(1.0f, unitRecord.MovementPoints.Value);
            Assert.AreEqual(1, units.Count);
            Assert.AreEqual(1, units[0].Id);

            units = _repo.GetUnitsByFactionId(1);
            Assert.AreEqual(1, units.Count);
            Assert.AreEqual(1, units[0].Id);

            var updatedUnit = new UnitRecord(unitRecord, new StackId(2), new MovementPoints(1.0f));

            _repo.Update(updatedUnit);
            unitRecord = _repo.GetUnitById(id);
            Assert.AreEqual(2, unitRecord.StackId.Value);
            Assert.AreEqual(0, unitRecord.UnitTypeId.Value);
            Assert.AreEqual(1.0f, unitRecord.MovementPoints.Value);

            updatedUnit = new UnitRecord(unitRecord, new StackId(1));
            _repo.Update(updatedUnit);
            unitRecord = _repo.GetUnitById(id);
            Assert.AreEqual(1, unitRecord.StackId.Value);
            Assert.AreEqual(0, unitRecord.UnitTypeId.Value);
            Assert.AreEqual(1.0f, unitRecord.MovementPoints.Value);

            updatedUnit = new UnitRecord(unitRecord, new MovementPoints(3.0f));
            _repo.Update(updatedUnit);
            unitRecord = _repo.GetUnitById(id);
            Assert.AreEqual(1, unitRecord.StackId.Value);
            Assert.AreEqual(0, unitRecord.UnitTypeId.Value);
            Assert.AreEqual(3.0f, unitRecord.MovementPoints.Value);
        }