Example #1
0
        public ShakeItem Clone()
        {
            ShakeItem clonedItem = new ShakeItem();
            clonedItem.Name = this.Name;
            clonedItem.IsLocked = this.IsLocked;
            clonedItem.IsMarked = this.IsMarked;

            return clonedItem;
        }
Example #2
0
        internal static List<ShakeItem> GetItems(int listID)
        {
            List<ShakeItem> items = new List<ShakeItem>();

            string getItemsQuery = string.Format("SELECT * FROM {0} WHERE {1}={2} ORDER BY {3}", TABLE_NAME, LIST_ID, listID, INDEX);
            DataTable table = SQLiteLinker.GetDataTable(getItemsQuery);

            foreach (DataRow singleRow in table.Rows)
            {
                ShakeItem newItem = new ShakeItem();
                newItem.LoadData(singleRow);

                items.Add(newItem);
            }

            return items;
        }
Example #3
0
 public bool AddItem(ShakeItem newItem)
 {
     newItem.Index = _items.Count;
     _items.Add(newItem);
     return true;
 }
Example #4
0
        //An item can no be put in the same place (at least not too much items)
        //Maybe a max of 2 items
        public List<MoveLog> Reshuffle()
        {
            List<MoveLog> changesLog = new List<MoveLog>();

            ShakeItem[] newItems = new ShakeItem[_items.Count];
            List<int> unlockedIndexes = new List<int>();

            //Put the locked items in their places
            for (int i = 0; i < _items.Count; i++)
            {
                if (_items[i].IsLocked)
                    newItems[i] = _items[i];
                else
                    unlockedIndexes.Add(i);
            }

            //Put the un-locked items int new places
            for (int j = 0; j < _items.Count; j++)
            {
                if (newItems[j] == null)
                {
                    int randomIndex = RandomGenerator.GenerateInteger(0, unlockedIndexes.Count);
                    int newItemIndex = unlockedIndexes[randomIndex];
                    newItems[j] = _items[newItemIndex];

                    unlockedIndexes.RemoveAt(randomIndex);
                    changesLog.Add(new MoveLog(){ OriginalIndex = newItemIndex, ChangedIndex = j });
                }
                else
                {
                    //This is needed so the Locked Items go back to their places after all the moves
                    changesLog.Add(new MoveLog(){ OriginalIndex = j, ChangedIndex = j });
                }
            }

            _items.Clear();
            _items.AddRange(newItems);

            this.RefreshIndexes();

            return changesLog;
        }