spaceconquest.SlaveDriver.Execute C# (CSharp) Method

Execute() public method

public Execute ( ) : void
return void
        public void Execute()
        {
            foreach (Command C in commands) {
                if (C.action != Command.Action.Move)
                {
                    qcs.Add(new QueuedCommand(C, galaxy, 0));
                }
                else if (C.action == Command.Action.Move)
                {
                    qcs.AddRange(QueuedCommand.QueuedCommandList(C, galaxy));
                }
                /*else {
                    Ship agent = (Ship)((galaxy.GetHex(C.start)).GetGameObject());
                    int speed = agent.getSpeed();
                    int i = 0;
                    for (; i < speed; i++) {
                        qcs.Add(new QueuedCommand(agent, galaxy.GetHex(C.target), i));
                    }
                    qcs.Add(new QueuedCommand(C, galaxy, i));
                }*/

            }

            qcs.Sort(Sorter);

            Console.WriteLine("Executing " + qcs.Count + " Commands");
            foreach (QueuedCommand qc in qcs)
            {
                ExecuteCommand(qc);
            }
            commands.Clear();
            qcs.Clear();
            Console.WriteLine("Done executing");
            Boolean iLost = true;
            Boolean iWon = true;
            Player p1 = map.GetInstancePlayer();
            foreach (Player p in map.players)
            {
                Console.WriteLine("Player " + p.id);
                List<Unit> newlist = new List<Unit>();
                newlist.AddRange(p.army);

                foreach (Unit u in newlist)
                {
                    Console.WriteLine("Unit " + u.hex);
                    if (!(u is Asteroid)) {
                        if (iLost && p == p1)
                        {
                            iLost = false;
                        }
                        else if (iWon && p != p1) {
                            iWon = false;
                        }
                    }
                    u.upkeep();
                }

            }
            if (iLost)
            {
                Console.WriteLine("I LOST THE GAME " + map.players.Count);
                //Lose screen
                MenuManager.screen = new WinScreen(false);
                gamescreen.middleman.Close();
                gamescreen.middleman.AttendClose();
            }
            if (iWon)
            {
                Console.WriteLine("I WON THE GAME " + map.players.Count);
                //Win screen
                MenuManager.screen = new WinScreen(true);
                gamescreen.middleman.Close();
                gamescreen.middleman.AttendClose();
            }
        }