コード例 #1
0
        public void RemoveItem(ICollectableItem itemToRemove)
        {
            if (itemToRemove == null)
            {
                throw new CollectableException("Cannot remove a null item");
            }
            if (_items.Count == 0)
            {
                throw new CollectableException("List is empty - Cannot remove item from list");
            }
            Type itemType = itemToRemove.CollectableType;

            if (itemType != this.CollectableType)
            {
                throw new CollectableException($"Invalid type {itemType}, expected type {this.CollectableType}");
            }
            try
            {
                int count = _items.Count;
                _items.Remove(itemToRemove);
                if (count == _items.Count)
                {
                    throw new CollectableException("Item was not removed from list");
                }
            }
            catch (Exception ex)
            {
                throw new CollectableException("Unable to remove item", ex);
            }
        }
コード例 #2
0
        internal static ICollectableItem GetCollectableItemFromJson(string jsonItem, Type collectionType)
        {
            ICollectableItem item = null;

            try
            {
                switch (collectionType.Name)
                {
                case "BookBase":
                    item = JsonConvert.DeserializeObject <BookItem>(jsonItem);
                    break;

                case "StampBase":
                    item = JsonConvert.DeserializeObject <StampItem>(jsonItem);
                    break;

                default:
                    throw new CollectableItemInstanceParseException($"Unable to parse Json.  Unsupported collection type={collectionType.Name}");
                }
            }
            catch (Exception ex)
            {
                throw new CollectableItemInstanceParseException($"Unable to parse Json into a collectable item.  Type={collectionType.Name}, Json={jsonItem}", ex);
            }
            return(item);
        }
コード例 #3
0
        private ICollectionBase GetTestCollection(string collectionName, Type collectableType, int numberOfCollectables, int numberOfItemsPerCollectable = 0)
        {
            ICollectableBase collectable    = null;
            ICollectableItem item           = null;
            Type             collectionType = collectableType;
            ICollectionBase  testCollection = new HomeCollection(collectionName, collectionType);

            for (int i = 0; i < numberOfCollectables; i++)
            {
                if (collectionType == CollectableBaseFactory.BookType)
                {
                    collectable = GetTestBookBase(i);
                }
                else if (collectionType == CollectableBaseFactory.StampType)
                {
                    collectable = GetTestStampBase(i);
                }
                testCollection.AddToCollection(collectable);

                for (int j = 0; j < numberOfItemsPerCollectable; j++)
                {
                    if (collectionType == CollectableBaseFactory.BookType)
                    {
                        item = GetTestBookItem(i);
                    }
                    else if (collectionType == CollectableBaseFactory.StampType)
                    {
                        item = GetTestStampItem(i);
                    }
                    collectable.AddItem(item);
                }
            }
            return(testCollection);
        }
コード例 #4
0
ファイル: Session.cs プロジェクト: stevemanderson/azureacres
        public static void AddInventory(ICollectableItem item)
        {
            bool topInventoryFull = true;
            for (int i = 0; i < TopInventory.Length; ++i)
            {
                if (TopInventory[i] == null)
                {
                    TopInventory[i] = item;
                    topInventoryFull = false;
                    break;
                }
            }

            if(topInventoryFull)
            {
                for (int i = 0; i < Inventory.Length; ++i)
                {
                    if (Inventory[i] == null)
                    {
                        Inventory[i] = item;
                        break;
                    }
                }
            }
        }
コード例 #5
0
ファイル: L7.cs プロジェクト: DittoDog12/GMTB-v3
        public override void Initialise(IServiceLocator _sl)
        {
            base.Initialise(_sl);
            mBackgroundManager.BlankBackgrounds();
            mBackgroundManager.ChangeBackground("Levels/Boardroom");
            mBackgroundManager.ChangePosition(0, 2000);


            if (firstRun == true)
            {
                // Create Player
                // <Entity Type>("Texture", needs input?)
                createdEntity = mEntityManager.newEntity <Characters.Player.InfirmaryPlayer>("Characters/Player/standR", true);
                // X, Y coordinates
                mSceneManager.newEntity(createdEntity, 20, 2260);
                mLevelEntities.Add(createdEntity.UID, createdEntity);

                // Exit Door
                createdEntity = mEntityManager.newEntity <Door>("blank");
                var asInterface = createdEntity as IDoor;
                asInterface.Initialize("L6", true);
                // X, Y coordinates
                mSceneManager.newEntity(createdEntity, 20, 2260); //Change coordinates
                mLevelEntities.Add(createdEntity.UID, createdEntity);

                //Collectable Object
                createdEntity = mEntityManager.newEntity <CollectableItem>("Objects/key");
                ICollectableItem _item = createdEntity as ICollectableItem;
                foreach (KeyValuePair <int, IEntity> _keyPair in mEntityManager.AllEntities)
                {
                    ILockedDoor _door = _keyPair.Value as ILockedDoor;
                    if (_door != null)
                    {
                        _item.SetTarget(_door);
                        break;
                    }
                }
                // X, Y coordinates
                mSceneManager.newEntity(createdEntity, 700, 2360); //Change coordinates
                mLevelEntities.Add(createdEntity.UID, createdEntity);

                // Floor
                createdEntity = mEntityManager.newEntity <StaticObject>("floor");
                mSceneManager.newEntity(createdEntity, -40, 2400); //Change coordinates
                mLevelEntities.Add(createdEntity.UID, createdEntity);

                //Background sound
                createdEntity = mEntityManager.newEntity <SoundEntity>("Audio/rain-and-thunder-heart-beat", 0f, true, true, 0.1f);
                mSceneManager.newEntity(createdEntity, 0, 0);
                mLevelEntities.Add(createdEntity.UID, createdEntity);

                //Footsteps
                createdEntity = mEntityManager.newEntity <SoundEntity>("Audio/footsteps", 3f, true, false, 1f);
                mSceneManager.newEntity(createdEntity, 0, 0);
                mLevelEntities.Add(createdEntity.UID, createdEntity);

                firstRun = false;
            }
        }
コード例 #6
0
        public void createcollectableitem_valid_type_returns_new_instance_with_type()
        {
            foreach (Type collectableType in CollectableBaseFactory.CollectableTypes)
            {
                ICollectableItem newItem = CollectableBaseFactory.CreateCollectableItem(collectableType);

                Assert.AreEqual(collectableType, newItem.CollectableType);
            }
        }
コード例 #7
0
        public void createcollectableitem_valid_type_returns_new_instance()
        {
            foreach (Type collectableType in CollectableBaseFactory.CollectableTypes)
            {
                ICollectableItem newItem = CollectableBaseFactory.CreateCollectableItem(collectableType);

                Assert.IsNotNull(newItem);
            }
        }
コード例 #8
0
        /// <summary>
        /// aggiunge l'item alla lista
        /// </summary>
        /// <param name="itemToAdd">Item to add.</param>
        public void AddItem(ICollectableItem itemToAdd)
        {
            Items.Add(itemToAdd);
            ///casting = ItemToAdd è nell'interfaccia e non deriva da MonoBehaviour,il compilatore non sapendolo,foziamo ad utilizzarlo come MonoBehaviour.
            MonoBehaviour goItem = (MonoBehaviour)itemToAdd as MonoBehaviour;

            goItem.transform.position = this.transform.position;
            goItem.transform.SetParent(this.transform);
        }
コード例 #9
0
        public void createandaddcollectableitem_valid_type_returns_new_item_with_type_set()
        {
            foreach (Type collectableType in CollectableBaseFactory.CollectableTypes)
            {
                ICollectableBase collectable = CollectableBaseFactory.CreateCollectableBase(collectableType);
                ICollectableItem newItem     = CollectableBaseFactory.CreateAndAddCollectableItem(collectable);

                Assert.AreEqual(collectableType, newItem.CollectableType);
            }
        }
コード例 #10
0
        public static ICollectableItem CreateAndAddCollectableItem(ICollectableBase collectable)
        {
            if (collectable == null)
            {
                throw new CollectableException("Collectable cannot be null when adding an instance of it");
            }
            ICollectableItem newItem = CreateCollectableItem(collectable.CollectableType);

            collectable.AddItem(newItem);
            return(newItem);
        }
コード例 #11
0
        public void createandaddcollectableitem_valid_type_adds_new_item_to_collectable()
        {
            foreach (Type collectableType in CollectableBaseFactory.CollectableTypes)
            {
                ICollectableBase collectable     = CollectableBaseFactory.CreateCollectableBase(collectableType);
                ICollectableItem newItem         = CollectableBaseFactory.CreateAndAddCollectableItem(collectable);
                ICollectableItem fromCollectable = collectable.ItemInstances[0];

                Assert.AreEqual(newItem, fromCollectable);
            }
        }
コード例 #12
0
        public void AddItem(ICollectableItem itemToAdd)
        {
            if (itemToAdd == null)
            {
                throw new CollectableException("Cannot add a null item");
            }
            Type itemType = itemToAdd.CollectableType;

            if (itemType != this.CollectableType)
            {
                throw new CollectableException($"Invalid type {itemType}, expected type {this.CollectableType}");
            }
            _items.Add(itemToAdd);
        }
コード例 #13
0
        public void removeitem_from_existing_list_success()
        {
            int N = 3;

            foreach (Type collectableType in CollectableBaseFactory.CollectableTypes)
            {
                ICollectableBase collectable = GetTestBase(collectableType, N);
                ICollectableItem mockItem    = collectable.ItemInstances[N - 1];

                collectable.RemoveItem(mockItem);

                IList <ICollectableItem> list = collectable.ItemInstances;
                Assert.AreEqual(N - 1, list.Count);
            }
        }
コード例 #14
0
        public void getcollectableitemfromjson_deserialize_bad_format_throws_exception()
        {
            string jsonItem = "invalid JSON";

            foreach (Type collectableType in CollectableBaseFactory.CollectableTypes)
            {
                bool fail = false;
                try
                {
                    ICollectableItem newItem = HomeCollectionRepository.GetCollectableItemFromJson(jsonItem, collectableType);
                }
                catch (CollectableItemInstanceParseException)
                {
                    fail = true;
                    Assert.IsTrue(fail, "Expected exception to be thrown when JSON is invalid and cannot be parsed to an object");
                }
            }
        }
コード例 #15
0
        internal static ICollectableBase GetCollectableFromJson(string jsonCollectable, Type collectionType)
        {
            ICollectableBase newCollectable = null;

            try
            {
                dynamic collectable = JsonConvert.DeserializeObject(jsonCollectable);
                var     items       = collectable["ItemInstances"];
                collectable["ItemInstances"] = null;    // clear so we can parse it more easily
                switch (collectionType.Name)
                {
                case "BookBase":
                    ValidateBookCollectableFields(collectable);
                    newCollectable = JsonConvert.DeserializeObject <BookBase>(collectable.ToString());
                    break;

                case "StampBase":
                    ValidateStampCollectableFields(collectable);
                    newCollectable = JsonConvert.DeserializeObject <StampBase>(collectable.ToString());
                    break;

                default:
                    throw new CollectableParseException($"Unable to parse Json.  Unsupported collection type={collectionType.Name}");
                }
                if (items != null)
                {
                    foreach (var item in items)
                    {
                        // add custom try/catch??
                        ICollectableItem newItem = GetCollectableItemFromJson(item.ToString(), collectionType);
                        newCollectable.AddItem(newItem);
                    }
                }
                return(newCollectable);
            }
            catch (Exception ex)
            {
                throw new CollectableParseException($"Unable to parse Json into a collectable object.  Type={collectionType.Name}, Json={jsonCollectable}", ex);
            }
        }
コード例 #16
0
        public void removeitem_from_existing_list_fails_when_item_is_null()
        {
            int  N          = 3;
            bool threwError = false;

            foreach (Type collectableType in CollectableBaseFactory.CollectableTypes)
            {
                ICollectableBase collectable = GetTestBase(collectableType, N);
                ICollectableItem mockItem    = null;

                try
                {
                    collectable.RemoveItem(mockItem);
                }
                catch (CollectableException)
                {
                    threwError = true;
                }

                Assert.IsTrue(threwError);
            }
        }
コード例 #17
0
ファイル: Session.cs プロジェクト: stevemanderson/azureacres
 public static void RemoveInventory(ICollectableItem item)
 {
     for (int i = 0; i < TopInventory.Length; ++i)
         if (TopInventory[i] == item)
             TopInventory[i] = null;
 }
コード例 #18
0
 public void AddItem(ICollectableItem itemToAdd)
 {
     _collectableBase.AddItem(itemToAdd);
 }
コード例 #19
0
 public void RemoveItem(ICollectableItem itemToRemove)
 {
     _collectableBase.RemoveItem(itemToRemove);
 }
コード例 #20
0
 /// <summary>
 /// rimuove l'item dalla lista
 /// </summary>
 /// <param name="itemToRemove">Item to remove.</param>
 public void RemoveItem(ICollectableItem itemToRemove)
 {
     Items.Remove(itemToRemove);
 }