Exemplo n.º 1
0
Arquivo: Player.cs Projeto: Corne/VOC
        public IRawMaterial[] TakeResources(params MaterialType[] resources)
        {
            if (resources == null)
                throw new ArgumentNullException(nameof(resources));

            lock (removeResourceLock)
            {
                if (!HasResources(resources))
                    throw new InvalidOperationException("Player doesn't have those resources");
                IRawMaterial[] result = new IRawMaterial[resources.Length];
                for (int i = 0; i < resources.Length; i++)
                {
                    var firstMatching = materials.First(m => m.Type == resources[i]);
                    materials.Remove(firstMatching);
                    result[i] = firstMatching;
                }

                logger.Info($"Removed resourced from player: {string.Join(", ", resources)}");

                return result;
            }
        }
Exemplo n.º 2
0
 public void CanAddNullResource()
 {
     var player = new Player("Abd");
     var materials = new IRawMaterial[] { null };
     Assert.Throws<ArgumentNullException>(() => player.AddResources(materials));
 }