Exemple #1
0
        private static void Attack(string token, string[] args)
        {
            var armyInfo = new int[10];

            var command = new FarmActions(token);

            var coordinates = new int[2];

            coordinates[X] = int.Parse(args[1]);
            coordinates[Y] = int.Parse(args[2]);

            for (var i = 3; i < args.Length; i++)
            {
                armyInfo[i - 3] = int.Parse(args[i]);
            }

            var army = new ArmyBuilder(armyInfo);

            command.Attack(coordinates[X], coordinates[Y], army);

            Console.WriteLine("Attack is made to " + coordinates[X] + "," + coordinates[Y]);
            Console.ReadKey();
        }
Exemple #2
0
        private void triggerItem_OnTrigger(object sender, TaskScheduler.OnTriggerEventArgs e)
        {
            //Parse the building name from the list-box
            var item = (AttackScheduler)ScheduleList.Items[0];

            // Create the line that is to be written in storage
            var line = RegisterItem(item);

            // Delete the item from the storage
            _storage.DeleteLine(line);

            // stop the schedule
            _taskScheduler.Enabled = false;
            _taskScheduler.TriggerItems.Clear();

            //calculate the wait time for the new attack
            var waitTime = 2 * _command.Attack(item.Location.X, item.Location.Y, item.Army);

            if (waitTime == -1)
            {
                // there is an error on an attacking command
                // either account disconected or lack of units
                Console.WriteLine("Error state! added 1 minute to the wait time.");

                waitTime = 1; // postponde 10 minutes to try again
            }

            item.Date = item.Date.AddMinutes(waitTime);

            //Update the item on the list
            UpdateList(item);

            //Add the next item to the scheduler
            _isOn = false;
            btnStart_Click(null, null);

            // update the storage file
            _storage.WriteLine(RegisterItem(item));
        }