Example #1
0
        private void RestoreData()
        {
            // set the storage and load the building list
            const string storageColumns = "Date,Army Spr,Army Swrd,Army Axe,Army Scout,Army LC,Army HC,Army Ram,Army Cat,Army Kngt,Army Nbl,Location X,Location Y";

            _storage = new StoreData("Farming", storageColumns);
            var items = _storage.ReadLines();

            for (var i = 1; i < items.Length; i++) // do not add the column names to list
            {
                //get all the field information from line
                var fields = items[i].Split(',');

                // Create the date information
                var date = Convert.ToDateTime(fields[0]);

                // Create the army information
                var armyInfo = new int[10];
                for (var j = 1; j < 11; j++)
                {
                    armyInfo[j - 1] = int.Parse(fields[j]);
                }
                var army = new ArmyBuilder(armyInfo);

                // Create the location information
                var location = new Village(int.Parse(fields[11]), int.Parse(fields[12]));

                //Finally create the AttackScheduler item from the information above
                var item = new AttackScheduler(location, army, date);

                // Add the created item into the list
                ScheduleList.Items.Add(item);
            }
        }
Example #2
0
        private void btnPickDate_Click(object sender, EventArgs e)
        {
            if (ArmyList.SelectedIndex == -1 || FarmingList.SelectedIndex == -1)
            {
                return;
            }

            if (_isOn)
            {
                MessageBox.Show("To add new events, first turn off the scheduler.");
                return;
            }

            var scheduleItem = new AttackScheduler((Village)FarmingList.SelectedItem, (ArmyBuilder)ArmyList.SelectedItem, dateTimePicker.Value);

            if (ScheduleList.SelectedIndex == -1)
            {
                ScheduleList.Items.Add(scheduleItem);
            }
            else
            {
                ScheduleList.Items.RemoveAt(ScheduleList.SelectedIndex);
                ScheduleList.Items.Add(scheduleItem);
            }
        }
Example #3
0
        private void UpdateList(AttackScheduler item)
        {
            if (ScheduleList.InvokeRequired)
            {
                // We're not in the UI thread, so we need to call BeginInvoke
                BeginInvoke(new RemoveItemDelegate(UpdateList), item);
                return;
            }

            // Must be on the UI thread if we've got this far
            // Update the item on the list
            ScheduleList.Items.RemoveAt(0);
            ScheduleList.Items.Add(item);
        }
Example #4
0
        private string RegisterItem(AttackScheduler item)
        {
            var line = "";

            line += item.Date + ",";

            for (var i = 0; i < item.Army.Army.Length; i++)
            {
                line += item.Army.Army[i] + ",";
            }

            line += item.Location.X + "," + item.Location.Y;

            return(line);
        }