Esempio n. 1
0
        private void UpdateItem(T item)
        {
            var comparer      = ItemComparer.CreateItemsComparer <T>(item);
            var itemFormStore = this.items.FirstOrDefault(comparer.IsMatch);

            this.ReplaceItemInList(itemFormStore);
        }
Esempio n. 2
0
    /// <summary>
    /// Start method for Room8
    /// </summary>
    private void Start()
    {
        itemComparer = FindObjectOfType <ItemComparer>();

        wallLampsParent.LampsAligned += Victory;
        prize.SetActive(false);
    }
Esempio n. 3
0
 /// <summary>
 /// Awake method for InteractionNPCNeighbor
 /// </summary>
 private void Awake()
 {
     dialog          = GetComponent <DialogText>();
     input           = FindObjectOfType <PlayerInput>();
     playerInventory = FindObjectOfType <Inventory>();
     itemComparer    = FindObjectOfType <ItemComparer>();
 }
Esempio n. 4
0
        public void DefaultComparer()
        {
            ItemComparer comparer         = new ItemComparer();
            int          comparisonResult = comparer.Compare(item1, item2);

            Assert.Less(0, comparisonResult, "The first item should have been greater than the second due to sort order.");
        }
Esempio n. 5
0
        public void CompareTitleDesc2()
        {
            ItemComparer comparer         = new ItemComparer("Title", true);
            int          comparisonResult = comparer.Compare(item1, item2);

            Assert.Less(0, comparisonResult);
        }
Esempio n. 6
0
        public void CompareTitle2()
        {
            ItemComparer comparer         = new ItemComparer("Title", false);
            int          comparisonResult = comparer.Compare(item1, item2);

            Assert.Greater(0, comparisonResult);
        }
Esempio n. 7
0
        // Sort on this column.

        private void listView1_ColumnClick_1(object sender, ColumnClickEventArgs e)
        {
            ItemComparer sorter = listView1.ListViewItemSorter as ItemComparer;

            if (sorter == null)
            {
                sorter       = new ItemComparer(e.Column);
                sorter.Order = SortOrder.Ascending;
                listView1.ListViewItemSorter = sorter;
            }
            // if clicked column is already the column that is being sorted
            if (e.Column == sorter.Column)
            {
                // Reverse the current sort direction
                if (sorter.Order == SortOrder.Ascending)
                {
                    sorter.Order = SortOrder.Descending;
                }
                else
                {
                    sorter.Order = SortOrder.Ascending;
                }
            }
            else
            {
                // Set the column number that is to be sorted; default to ascending.
                sorter.Column = e.Column;
                sorter.Order  = SortOrder.Ascending;
            }
            listView1.Sort();
        }
Esempio n. 8
0
            public int Compare(SelectionCellRangeWithItemsWrapper item)
            {
                if (m_target == item)
                {
                    return(0);
                }

                var xri = m_target.Value;
                var yri = item.Value;

                int compare;

                compare = ItemComparer.Compare(xri.ItemRange, yri.ItemRange);
                if (compare != 0)
                {
                    Debug.Assert(((compare < 0) && ItemRangeComparer.Compare(xri.ItemRange, item) <= 0) ||
                                 ((compare > 0) && ItemRangeComparer.Compare(xri.ItemRange, item) >= 0));

                    return(compare);
                }

                Debug.Assert(ItemRangeComparer.Compare(xri.ItemRange, item) == 0);

                compare = ItemComparer.Compare(xri.CellRange.ColumnRange, yri.CellRange.ColumnRange);
                if (compare != 0)
                {
                    return(compare);
                }

                Debug.Assert(xri.CellRange == yri.CellRange);

                return(m_target.Index - item.Index);
            }
Esempio n. 9
0
            private static int Compare(SelectionRange xr, SelectionRange yr)
            {
                int xs, xe, ys, ye;

                ItemComparer.GetBounds(xr, out xs, out xe);
                ItemComparer.GetBounds(yr, out ys, out ye);

                if (xs < ys)
                {
                    return(-1);
                }
                else if (xs > ys)
                {
                    return(1);
                }

                Debug.Assert(!xr.Intersect(yr).IsEmpty);

                if (xe < ye)
                {
                    return(-1);
                }
                else if (xe > ye)
                {
                    return(1);
                }

                Debug.Assert(xr == yr);
                return(0);
            }
Esempio n. 10
0
        private void DeleteItem(T item)
        {
            var itemComparer = ItemComparer.CreateItemsComparer <T>(item);
            var itemToRemove = this.items.First(itemComparer.IsMatch);

            this.items.Remove(itemToRemove);
        }
Esempio n. 11
0
 public CollectionComparer(IEnumerable <T> newList, IEnumerable <T> oldList, bool addRemoveWithZeroID, ItemComparer itemComparer)
 {
     this.itemComparer = itemComparer;
     addedItems        = getAddedReferences(newList, oldList, addRemoveWithZeroID);
     removedItems      = getRemovedReferences(newList, oldList, addRemoveWithZeroID);
     notChangedItems   = getUnchangedReferences(newList, oldList, addRemoveWithZeroID);
 }
Esempio n. 12
0
    public void ReadBook(Progress progress)
    {
        string xmlpath = BookDirectory() + m_bookName + ".xml";

        XmlDocument doc = new XmlDocument();

        doc.Load(xmlpath);
        XmlNodeList headerList = doc.DocumentElement.GetElementsByTagName(m_headerTag);
        IEnumerator headerEnum = headerList.GetEnumerator();

        if (headerEnum.MoveNext())
        {
            XmlNode headerNode = (XmlNode)headerEnum.Current;
            var     typeAttr   = headerNode.Attributes[m_typeTag];
            if (typeAttr != null)
            {
                m_type = typeAttr.Value;
            }
            m_answerType = AnswerType.Default;
            var answerAttr = headerNode.Attributes[m_answerTag];
            if (answerAttr != null)
            {
                m_answerType = (AnswerType)Enum.Parse(typeof(AnswerType), answerAttr.Value);
            }

            var timeAttr = headerNode.Attributes[m_timeTag];
            if (timeAttr != null)
            {
                m_timer = Convert.ToInt32(timeAttr.Value);
            }
        }

        XmlNodeList contentList = doc.DocumentElement.GetElementsByTagName(m_contentTag);
        IEnumerator contentEnum = contentList.GetEnumerator();

        while (contentEnum.MoveNext())
        {
            XmlNode     contentNode = (XmlNode)contentEnum.Current;
            XmlNodeList itemList    = contentNode.SelectNodes(m_itemTag);
            IEnumerator itemEnum    = itemList.GetEnumerator();
            while (itemEnum.MoveNext())
            {
                XmlNode itemNode = (XmlNode)itemEnum.Current;
                string  word     = itemNode.Attributes[m_idTag].Value;
                if (!m_wordSet.Contains(word))
                {
                    m_wordSet.Add(word);
                    m_bookWords.Add(word);
                    BookItem item = new BookItem(word, this);
                    item.ReadItem(itemNode);
                    progress.AddWord(item);
                    m_bookItems.Add(item);
                }
            }
        }
        ItemComparer comparer = new ItemComparer();

        m_bookItems.Sort(comparer);
    }
Esempio n. 13
0
 /// <summary>
 /// Start method for Room6.
 /// </summary>
 private void Start()
 {
     prizePicked  = false;
     itemComparer = FindObjectOfType <ItemComparer>();
     if (player.PuzzlesDone.HasFlag(myPuzzle))
     {
         this.Victory();
     }
 }
Esempio n. 14
0
        private void bindItemData()
        {
            CustomGenericList <Item> items = (CustomGenericList <Item>)Session["Items"];
            ItemComparer             comp  = new ItemComparer((ItemComparer.CompareEnum)_sortColumn, _sortOrder);

            items.Sort(comp);
            itemList.DataSource = items;
            itemList.DataBind();
        }
Esempio n. 15
0
 static Util()
 {
     int[] numArray = new int[4];
     numArray[0]            = 2;
     numArray[2]            = 0xc627;
     clrVersion2            = numArray;
     platforms              = new string[] { "AnyCPU", "x86", "x64", "Itanium" };
     processorArchitectures = new string[] { "msil", "x86", "amd64", "ia64" };
     itemComparer           = new ItemComparer();
 }
 static Util()
 {
     int[] numArray = new int[4];
     numArray[0] = 2;
     numArray[2] = 0xc627;
     clrVersion2 = numArray;
     platforms = new string[] { "AnyCPU", "x86", "x64", "Itanium" };
     processorArchitectures = new string[] { "msil", "x86", "amd64", "ia64" };
     itemComparer = new ItemComparer();
 }
Esempio n. 17
0
    /// <summary>
    /// Awake method for InteractionPianoKey.
    /// </summary>
    private void Awake()
    {
        inventory    = FindObjectOfType <Inventory>();
        itemComparer = FindObjectOfType <ItemComparer>();

        if (inventory.Bag.Contains(itemComparer.NotRewoundAudioTape))
        {
            gameObject.GetComponent <BoxCollider>().enabled = false;
        }
    }
        public int CompareTo(KeyedEnumerator <T> other)
        {
            var result = ItemComparer.Compare(Current, other.Current);

            if (result == 0)
            {
                result = SecondaryKey.CompareTo(other.SecondaryKey);
            }

            return(result);
        }
Esempio n. 19
0
        /// <summary>
        /// Creates a new object.
        /// </summary>
        /// <param name="listView"></param>
        public ListViewSortHelper(ListView listView)
        {
            ListView   = listView;
            SortColumn = ListView.Sorting == SortOrder.None ? -1 : 0;
            SortOrder  = ListView.Sorting;

            _ItemComparer = new ItemComparer(this);

            ListView.Sorting            = SortOrder.None;
            ListView.ListViewItemSorter = _ItemComparer;
            ListView.ColumnClick       += ListView_ColumnClick;
        }
Esempio n. 20
0
    public UnityWorldRenerer(SpriteRenderer entityObjectPrefab, Transform worldTransform, Dictionary <string, Sprite> spriteRegistry, int positionUnitsPerUnityUnit, HealthbarManager hpMan, ItemComparer itemComp)
    {
        this.entityObjectPrefab        = entityObjectPrefab;
        this.worldTransform            = worldTransform;
        this.spriteRegistry            = spriteRegistry;
        this.positionUnitsPerUnityUnit = positionUnitsPerUnityUnit;
        this.hpMan           = hpMan;
        this.itemComp        = itemComp;
        currentlyUsedObjects = new Dictionary <int, SpriteRenderer>();

        unusedObjects = new Stack <SpriteRenderer>();
    }
Esempio n. 21
0
            /// <summary>
            /// Sorts the tool strip items.
            /// </summary>
            protected void SortToolStripItems()
            {
                SortedList <Int32, SortedList <Control> > sltItems = new SortedList <Int32, SortedList <Control> >();

                Int32        intIndex    = -1;
                Control      ctlControl  = null;
                ItemComparer icpComparer = new ItemComparer(m_lstOrderAdded);

                for (Int32 i = Controls.Count - 1; i >= 0; i--)
                {
                    ctlControl = Controls[i];

                    intIndex = ((PanelToolStripItem)ctlControl.Tag).Index;
                    if (!sltItems.ContainsKey(intIndex))
                    {
                        sltItems[intIndex] = new SortedList <Control>(icpComparer);
                    }
                    sltItems[intIndex].Add(ctlControl);
                }

                SortedList <Control> lstButtons = null;

                //the lower the index, the higher up/further to the left
                // so index 0 is at the top/left
                // (top or left depending on orientation)
                intIndex = 0;
                Control ctlButton = null;

                for (Int32 i = sltItems.Values.Count - 1; i >= 0; i--)
                //for (Int32 i = 0; i < sltItems.Values.Count; i++)
                {
                    lstButtons = sltItems.Values[i];
                    for (Int32 j = lstButtons.Count - 1; j >= 0; j--)
                    {
                        ctlButton = lstButtons[j];
                        this.Controls.SetChildIndex(ctlButton, intIndex++);

                        if ((i == sltItems.Values.Count - 1) && (j == lstButtons.Count - 1))
                        {
                            if (m_otnDirection == Orientation.Vertical)
                            {
                                m_booNeedScroll       = (m_booNeedScroll || (ctlButton.Bounds.Bottom > this.Height));
                                m_booEnableDownScroll = m_booNeedScroll;
                            }
                            else
                            {
                                m_booNeedScroll     = (m_booNeedScroll || (ctlButton.Bounds.Right > this.Width));
                                m_booEnableUpScroll = m_booNeedScroll;
                            }
                        }
                    }
                }
            }
            public int[] RelativeSortArray(int[] arr1, int[] arr2)
            {
                orderArr1 = arr1;
                orderArr2 = arr2;

                List <Item>  results = arr1.Select(a => new Item(a)).ToList();
                ItemComparer c       = new ItemComparer();

                results.Sort(c);

                return(results.Select(r => r.Value).ToArray());
            }
Esempio n. 23
0
        public SongsControl(bool sortItems = true)
        {
            InitializeComponent();

            _songs = new List<Song>();

            if (sortItems)
            {
                _comparer = new ItemComparer();
                SongsListView.ColumnClick += SongsListViewColumnClick;
            }
        }
Esempio n. 24
0
        /// <summary>
        /// 以前のソート状態で再ソートする。
        /// 実際にソートされるとTRUEが返る。
        /// </summary>
        public bool SortByMultiHeader(IList itemList0)
        {
            if (IsExistSortParams == false)
            {
                return(false);
            }

            List <object> srcList = itemList0.OfType <object>().ToList();

            if (srcList.Count <= 1)
            {
                return(false);
            }

            //リフレクション+毎回プロパティ読み出しがかなり重いので、キャッシュを使用する
            var gvCache1 = new gvCache(srcList);

            //前処理(キャッシュからDictionaryを排除するため)
            List <int> idxData = Enumerable.Range(0, srcList.Count).ToList();

            string prevPath = "";
            // Item1:first index, Item2: last index
            List <Tuple <int, int> > sortGroupList1 = null;

            for (int i1 = 0; i1 < this._multiHeaderSortDict.Count; i1++)
            {
                GridViewColumnHeader columnHeader1 = this._multiHeaderSortDict.ElementAt(i1).Key;
                string path = getHeaderString(columnHeader1);
                if (string.IsNullOrEmpty(path) == true)
                {
                    continue;
                }

                ListSortDirection sortDirection1 = this._multiHeaderSortDict.ElementAt(i1).Value;
                var comparer = new ItemComparer(path, sortDirection1, gvCache1);

                sortGroupList1 = CreateSortedItemGroupList(prevPath, sortGroupList1, idxData, gvCache1);
                sortGroupList1.ForEach(kvp1 => idxData.Sort(kvp1.Item1, kvp1.Item2 - kvp1.Item1 + 1, comparer));
                prevPath = path;
            }

            //後処理
            itemList0.Clear();
            foreach (var idx in idxData)
            {
                itemList0.Add(srcList[idx]);
            }

            return(true);
        }
        static void Main(string[] args)
        {
            int       numItems = 0, repet = 20000;
            Stopwatch sw01 = new Stopwatch();
            // results are collected in a dictionary:
            // key: list length
            // value: tuple with times taken by ILNumerics and List.Sort()
            var results = new Dictionary <int, Tuple <float, float> >();
            // the comparer used for List.Sort() see below
            ItemComparer comparer = new ItemComparer();

            // run test for copy-sort-copy back via ILNumerics
            for (numItems = 500; numItems < 50000; numItems = (int)(numItems * 1.3))
            {
                Console.Write("\r measuring: {0}", numItems);
                long        ms = 0;
                List <Item> a  = makeData(numItems);
                for (int i = 0; i < repet; i++)
                {
                    sw01.Restart();
                    List <Item> b1 = fastSort(a);
                    sw01.Stop();
                    ms += sw01.ElapsedMilliseconds;
                }
                results.Add(numItems, new Tuple <float, float>((float)ms / repet, 0f));
            }
            // run test using the straightforward approach, List.Sort(IComparer)
            for (numItems = 500; numItems < 50000; numItems = (int)(numItems * 1.3))
            {
                Console.Write("\r measuring: {0}", numItems);
                List <Item> a  = makeData(numItems);
                long        ms = 0;
                for (int i = 0; i < repet; i++)
                {
                    List <Item> copyList = new List <Item>(a);
                    sw01.Restart();
                    copyList.Sort(comparer);
                    sw01.Stop();
                    ms += sw01.ElapsedMilliseconds;
                }
                results[numItems] = new Tuple <float, float>(results[numItems].Item1, (float)ms / repet);
            }
            // Print results
            Console.Clear();
            foreach (var v in results)
            {
                Console.WriteLine("Length: {0} | ILNumerics/CLR: {1} / {2} ms", v.Key, v.Value.Item1, v.Value.Item2);
            }
            Console.ReadKey();
        }
Esempio n. 26
0
    /// <summary>
    /// Start method of Room2
    /// </summary>
    private void Start()
    {
        FinishedPuzzle = false;
        itemComparer   = FindObjectOfType <ItemComparer>();

        // If player has puzzle done and no prize on inventory, plays victory
        // This happens for example if the player leaves the room without
        // picking the prize, and then returns to the room
        if (player.PuzzlesDone.HasFlag(myPuzzle) &&
            inventory.Bag.Contains(itemComparer.PianoKey1) == false)
        {
            Victory();
        }
    }
Esempio n. 27
0
        public void Enumerable_NotEquivalentComparer()
        {
            var comparer = new ItemComparer();

            Assert.ThrowsAny <Exception>(() => TestHelper.AssertNotEquivalent(new List <Item>(), new List <Item>(), comparer));
            Assert.ThrowsAny <Exception>(() => TestHelper.AssertNotEquivalent(new List <Item>()
            {
                new Item("0")
            }, new List <Item>()
            {
                new Item("0")
            }, comparer));
            Assert.ThrowsAny <Exception>(() => TestHelper.AssertNotEquivalent(new List <Item>()
            {
                new Item("0"), new Item("1")
            }, new List <Item>()
            {
                new Item("0"), new Item("1")
            }, comparer));
            Assert.ThrowsAny <Exception>(() => TestHelper.AssertNotEquivalent(new List <Item>()
            {
                new Item("0"), new Item("1")
            }, new List <Item>()
            {
                new Item("1"), new Item("0")
            }, comparer));

            TestHelper.AssertNotEquivalent(new List <Item>(), new List <Item>()
            {
                new Item("0")
            }, comparer);
            TestHelper.AssertNotEquivalent(new List <Item>()
            {
                new Item("0")
            }, new List <Item>(), comparer);
            TestHelper.AssertNotEquivalent(new List <Item>()
            {
                new Item("0")
            }, new List <Item>()
            {
                new Item("1")
            }, comparer);
            TestHelper.AssertNotEquivalent(new List <Item>()
            {
                new Item("0")
            }, new List <Item>()
            {
                new Item("0"), new Item("1")
            }, comparer);
        }
Esempio n. 28
0
    /// <summary>
    /// Start method of GetPlayOrder
    /// </summary>
    void Start()
    {
        playCounter      = 0;
        PianoPlayerInput = new CustomVector3(0, 0, 0);
        room4            = FindObjectOfType <Room4>();
        inventory        = FindObjectOfType <Inventory>();
        itemComparer     = FindObjectOfType <ItemComparer>();

        if (inventory.Bag.Contains(itemComparer.PianoKey1) &&
            inventory.Bag.Contains(itemComparer.PianoKey2) &&
            inventory.Bag.Contains(itemComparer.PianoKey3))
        {
            roomDoor.enabled = true;
        }
    }
Esempio n. 29
0
        private void Insert(ContentItem item, ContentItem parent, string sortExpression)
        {
            if (item.Parent.Children.Contains(item))
                item.Parent.Children.Remove(item);

            var comparer = new ItemComparer(sortExpression);
            for (int i = 0; i < parent.Children.Count; i++)
            {
                if (comparer.Compare(item, parent.Children[i]) < 0)
                {
                    parent.Children.Insert(i, item);
                    return;
                }
            }
            parent.Children.Add(item);
        }
Esempio n. 30
0
    /// <summary>
    /// Start method of Room4
    /// </summary>
    private void Start()
    {
        itemComparer   = FindObjectOfType <ItemComparer>();
        keyPlayOrder   = FindObjectOfType <GetPlayOrder>();
        FinishedPuzzle = false;
        displayText    = thoughtCanvas.GetComponentInChildren <Text>();
        waitForSeconds = new WaitForSeconds(3);
        ThisCoroutine  = null;

        // If player has puzzle done and no audiotape in inventory, plays victory
        if (player.PuzzlesDone.HasFlag(myPuzzle) &&
            inventory.Bag.Contains(itemComparer.NotRewoundAudioTape) == false)
        {
            Victory();
        }
    }
Esempio n. 31
0
        private void lvReviews_ColumnClick(object sender, ColumnClickEventArgs e)
        {
            ItemComparer sorter = lvReviews.ListViewItemSorter as ItemComparer;

            if (sorter == null)
            {
                sorter = new ItemComparer(e.Column);
                lvReviews.ListViewItemSorter = sorter;
            }
            else
            {
                sorter.SortOrder   = !sorter.SortOrder;
                sorter.ColumnIndex = e.Column;
            }
            lvReviews.Sort();
        }
Esempio n. 32
0
        public void Update <T>(ColumnData <T> columnStore, BitVector validDocumentsBitmap, int count)
        {
            if (columnStore == null)
            {
                throw new ArgumentNullException("columnStore");
            }

            // construct proper comparer
            ItemComparer <T> comparer;
            var type = typeof(T);

            if (type.IsValueType)
            {
                comparer = new ItemComparer <T>(columnStore.NotNulls, columnStore.DataArray, Comparer <T> .Default);
            }
            else if (ReferenceEquals(type, typeof(string)))
            {
                comparer = new ItemComparer <T>(columnStore.NotNulls, columnStore.DataArray, (IComparer <T>)StringComparer.OrdinalIgnoreCase);
            }
            else if (ReferenceEquals(type, typeof(SizableArrayOfByte)))
            {
                comparer = new ItemComparer <T>(columnStore.NotNulls, columnStore.DataArray, (IComparer <T>)SizableArrayOfByte.DefaultComparer.Instance);
            }
            else
            {
                throw new Exception("Sort indexes are not supported for this type: " + type.FullName);
            }

            // reinitialize index with sequential documentIDs (initial order does not matter)
            // only use those document indexes that are not marked as deleted
            ArrayUtils.EnsureCapacity(ref m_orderData, count);
            m_validDocCount = 0;
            for (var i = 0; i < m_orderData.Length; i++)
            {
                if (validDocumentsBitmap.SafeGet(i))
                {
                    OrderData[m_validDocCount] = i;
                    m_validDocCount++;
                }
            }

            // now reorder those integers based on data values they point to
            Array.Sort(OrderData, 0, m_validDocCount, comparer);

            IsValid = true;
        }
Esempio n. 33
0
        private void Insert(ContentItem item, ContentItem parent, string sortExpression)
        {
            if (item.Parent.Children.Contains(item))
            {
                item.Parent.Children.Remove(item);
            }

            var comparer = new ItemComparer(sortExpression);

            for (int i = 0; i < parent.Children.Count; i++)
            {
                if (comparer.Compare(item, parent.Children[i]) < 0)
                {
                    parent.Children.Insert(i, item);
                    return;
                }
            }
            parent.Children.Add(item);
        }
Esempio n. 34
0
    static void ItemItemStart()
    {
        FileReader fReader = new FileReader();
        Dictionary<int, UserPref> userList = fReader.GetData();
        Dictionary<string, float> fileMetaData = fReader.GetMetaData();

        FormulaFactory forFactory = new FormulaFactory();
        ItemComparer itemComparer = new ItemComparer(fReader.allProducts, userList);

        int targetUserID = 186;
        int targetProductID = 172;

        DateTime startTime = DateTime.Now;
        itemComparer.PredictRating(userList[targetUserID], targetProductID);
        // var x = itemComparer.PredictTopRatings(userList[targetUserID], 5);
        DateTime endTime = DateTime.Now;
        Console.WriteLine("Calculating the predicted rating took {0} ms",(endTime-startTime).Milliseconds);
        //itemComparer.AddNewRating(userList[3],105,4);
        //var y = itemComparer.PredictTopRatings(userList[targetUserID], 5);

        Console.Read();
    }
Esempio n. 35
0
		public void CompareTitleDesc2()
		{
			ItemComparer comparer = new ItemComparer("Title", true);
			int comparisonResult = comparer.Compare(item1, item2);
			Assert.Less(0, comparisonResult);
		}
Esempio n. 36
0
		public void CompareTitle2()
		{
			ItemComparer comparer = new ItemComparer("Title", false);
			int comparisonResult = comparer.Compare(item1, item2);
			Assert.Greater(0, comparisonResult);
		}
Esempio n. 37
0
		public void DefaultComparer()
		{
			ItemComparer comparer = new ItemComparer();
			int comparisonResult = comparer.Compare(item1, item2);
			Assert.Less(0, comparisonResult, "The first item should have been greater than the second due to sort order.");
		}
Esempio n. 38
0
	void FindPathTo(GameObject dest) {
		ArrayList open_list = new ArrayList ();
		ArrayList closed_list = new ArrayList ();
		IComparer compare = new ItemComparer ();
		open_list.Add (new AStarItem (standingFloor, FloorFunc (standingFloor.transform.position), 0, 0, Vector3.zero));

		Vector3 dest_floor = FloorFunc (dest.transform.position);
		AStarItem dest_item = null;

		while (open_list.Count > 0) {
			open_list.Sort(compare);
			AStarItem item = (AStarItem) open_list[0];
			open_list.RemoveAt(0);
			closed_list.Add (item);

			if (item.Obj == dest) {
				dest_item = item;
				break;
			}

			AStarItem[] near_items = FindNearFloors(item.Obj);
			for (int i = 0; i < near_items.Length; i++) {
				if (near_items[i] == null) continue;
				AStarItem near_item = near_items[i];
				bool ok = true;
				foreach (AStarItem it in closed_list) {
					if (it.Obj == near_item.Obj) {
						ok = false;
						break;
					}
				}
				if (!ok) continue;

				near_item.G = item.G + 1;
				near_item.H = (int) (Mathf.Abs(dest_floor.x - near_item.FloorValue.x) + Mathf.Abs(dest_floor.y - near_item.FloorValue.y));
				near_item.parent = item;

				for (int j = 0; j < open_list.Count; j++) {
					AStarItem it = (AStarItem) open_list[j];
					if (it.Obj == near_item.Obj) {
						ok = false;
						it.G = Mathf.Max (it.G, near_item.G);
						break;
					}
				}
				if (!ok) continue;

				open_list.Add(near_item);
			}
		}

		if (dest_item != null) {
			ArrayList move_list = new ArrayList();
			AStarItem item = dest_item;
			while (item.Weight > 0) {
				move_list.Add (new MoveData(item.dir, item.Obj));
				item = item.parent;
			}
			move_list.Reverse();

			if (moving > 0){
				StopMoving ();
				RecalcPlayerPos ();
			}

			moveList = new MoveData[move_list.Count];
			for (int i = 0; i < move_list.Count; i++) {
				moveList[i] = (MoveData)move_list[i];
			}

			MoveTo(moveList[0].destFloor, moveList[0].dir);
		}
	}
Esempio n. 39
0
        static void Main(string[] args)
        {
            Console.WriteLine("Test Program for Library Application");
            Console.WriteLine();

            Library myLib = new Library();

            // check-out one book
            myLib.book1.issue(myLib.user1);

            // try to check-out the same book by another user
            myLib.book1.issue(myLib.user2);

            // return the book
            myLib.book1.returnIt();

            // hold a book
            myLib.ebook1.holdIt(myLib.user2);

            // try to check-out the same book by another user
            myLib.ebook1.issue(myLib.user1);

            // remove hold
            myLib.ebook1.removeHolds();
            Console.WriteLine();

            // check-out one music
            myLib.music1.issue(myLib.user1);

            // try to check-out the same music by another user
            myLib.music1.issue(myLib.user2);

            //check in one music
            myLib.music1.returnIt();

            // check-out one movie
            myLib.movie1.issue(myLib.user1);

            // try to check-out the same movie by another user
            myLib.movie1.issue(myLib.user2);

            //check in one movie
            myLib.movie1.returnIt();

            // check-out one Audiobook
            myLib.audioBook1.issue(myLib.user1);

            // try to check-out the same Audiobook by another user
            myLib.audioBook1.issue(myLib.user2);

            //check in one audiobook
            myLib.audioBook1.returnIt();

            // print authors
            Console.WriteLine(myLib.book1.printAuthors);
            Console.WriteLine(myLib.ebook1.printAuthors);

            // print music duration
            Console.WriteLine(myLib.music1.getHMS());
            Console.WriteLine(myLib.music2.getHMS());

            //print movie duration
            Console.WriteLine(myLib.movie1.getHMS());
            Console.WriteLine(myLib.movie2.getHMS());

            //print Audiobook duration
            Console.WriteLine(myLib.audioBook1.getHMS());
            Console.WriteLine(myLib.audioBook2.getHMS());

            // Print all (unsorted) elements of List<Item> using Iterator
            Console.WriteLine("\nPrint all (unsorted) elements of List<Item> using Iterator");
            foreach(Item i in Item.GetItems())
            {
                Console.WriteLine(i.ToString());
            }

            // Sort elements of List<Item> based on ‘year’
            ItemComparer itemComparer = new ItemComparer();
            Item.GetItems().Sort(itemComparer);

            // Print all (sorted) elements of List<Item> using Iterator
            Console.WriteLine("\nPrint all (sorted) elements of List<Item> using Iterator");
            foreach (Item i in Item.GetItems())
            {
                Console.WriteLine(i.ToString());
            }

            // Print all elements in dictionary collection using Indexer.
            Console.WriteLine("\nPrint all elements in dictionary collection using Indexer");
            ItemCollection myItems = new ItemCollection();
            myItems[myLib.book1.Year] = myLib.book1;
            myItems[myLib.book2.Year] = myLib.book2;
            myItems[myLib.movie1.Year] = myLib.movie1;
            myItems[myLib.movie2.Year] = myLib.movie2;
            myItems[myLib.music1.Year] = myLib.music1;
            myItems[myLib.music2.Year] = myLib.music2;

            Console.WriteLine(myItems[myLib.book1.Year]);
            Console.WriteLine(myItems[myLib.book2.Year]);
            Console.WriteLine(myItems[myLib.movie1.Year]);
            Console.WriteLine(myItems[myLib.movie2.Year]);
            Console.WriteLine(myItems[myLib.music1.Year]);
            Console.WriteLine(myItems[myLib.music2.Year]);

            // Get entries parsed from Text file.
            List<Item> parsedItems = myLib.ParseFileContents();

            // Add the parsed items to dictionary.
            // The items are also added to the List when they were initialized.
            foreach(Item i in parsedItems)
            {
                myItems[i.Year] = i;
            }

            // Call method to write the LibraryCatalog.txt
            Console.WriteLine("\nPrinted LibraryCatalog.txt in current directory");
            myLib.PrintLibraryCatalog(Item.GetItems());

            // Print Items from year 2005 using LINQ query
            Console.WriteLine("\nPrint Items from year 2005 using LINQ query");
            List<Item> result = myLib.GetItemsByYear(Item.GetItems(), 2005);
            foreach(Item i in result)
            {
                Console.WriteLine(i.ToString());
            }

            Console.Read();
        }