示例#1
0
 //For moves-before-bording only
 public QueuedCommand(Ship s, Hex3D h, int offset)
 {
     agent = s;
     targetHex = h;
     order = Command.Action.Move;
     shiptype = null;
     priority = 50 + offset;
 }
示例#2
0
        public void Command_Default(Command.Action action)
        {
            Command command = new Command(action);

            Assert.AreEqual(action, command.action);
            Assert.IsNull(command.moveTo);
            // Testing for a specific sting value is to strong, since  these may change at any time.
            // We only care if the string exits and is not empty.
            Assert.IsNotNull(command.ToString());
            Assert.IsTrue(command.ToString().Length > 0);
        }
示例#3
0
 public QueuedCommand(Command C, Galaxy g, int offset)
 {
     agent = (Unit)g.GetHex(C.start).GetGameObject();
     try
     {
         targetHex = g.GetHex(C.target);
     }
     catch (NullReferenceException) {
         targetHex = null;
     }
     order = C.action;
     shiptype = C.shiptype;
     priority = 10*(int)order+offset;
 }
示例#4
0
        public Gameplay(String filepath)
        {
            String[] gameplayInput = System.IO.File.ReadAllLines(filepath);

            // First line is meta data of game in this order: seed, difficultyLevel, nodeCapcityMultiplier and numberOfMonsters.
            // Separated by a space.
            String[] meta = gameplayInput[0].Split(' ');
            seed                  = int.Parse(meta[0]);
            difficultyLevel       = uint.Parse(meta[1]);
            nodeCapcityMultiplier = uint.Parse(meta[2]);
            numberOfMonsters      = uint.Parse(meta[3]);

            // List of parsed commands.
            commands = new List <Command>();

            // Start at first turn.
            turn = 0;

            // The rest of the lines are player commands.
            // Start  at 1 because first line is meta data.
            for (int i = 1; i < gameplayInput.Length; i++)
            {
                // The command is separated with a space from the parameters (if exists).
                String[] data = gameplayInput[i].Split(' ');
                // Convert the command string to enum.
                Command.Action action = (Command.Action)Enum.Parse(typeof(Command.Action), data[0]);

                // If the command is move it will have a node ID as second parameter.
                if (action == Command.Action.Move)
                {
                    // We do not have the  actual node so we use a dummy node instead.
                    Node dummyNode = new Node(data[1]);
                    commands.Add(new Command(dummyNode));
                }
                // If not it is just the command.
                else
                {
                    commands.Add(new Command(action));
                }
            }

            // Start play through.
            Reset();
        }
示例#5
0
 void UpgradeClick(Object o, EventArgs e)
 {
     clickedaction = Command.Action.Upgrade; middleman.AddCommand(new Command(selectedhex, selectedhex, clickedaction)); clickedaction = Command.Action.None;
 }
示例#6
0
        public void UpdateSolar()
        {
            selectedhex.color = selectedcolor;
            ((SolarSystem3D)space).sun.color = ((SolarSystem3D)space).sun.defaultcolor;

            ////////mouse stuff////////
            if (oldmousehex != null && !oldmousehex.Equals(selectedhex)) oldmousehex.color = oldmousehex.defaultcolor;

            mousehex = ((SolarSystem3D)space).GetMouseOverHex();

            if ((mousestate.LeftButton == ButtonState.Pressed) && (oldmousestate.LeftButton == ButtonState.Released) && !shipmenu.Contains(mousestate.X, mousestate.Y) && !planetmenu.Contains(mousestate.X, mousestate.Y) && !galaxybutton.Contains(mousestate.X, mousestate.Y) && mousehex != null)
            {
                //selecting a hex
                if (clickedaction == Command.Action.None)
                {
                    selectedhex = mousehex;
                }

                //selecting a target of a action
                if (clickedaction != Command.Action.None && !waiting)
                {
                    Console.WriteLine("a command");
                    if (selectedhex.GetGameObject() is Ship && clickedaction == Command.Action.Move)
                    {
                        if (!((Ship)(selectedhex.GetGameObject())).GetReachable().Contains(mousehex)) { return; }
                        ((Ship)(selectedhex.GetGameObject())).SetGhost(mousehex);
                    }
                    if (selectedhex.GetGameObject() is Warship && clickedaction == Command.Action.Fire)
                    {
                        if (!((Warship)(selectedhex.GetGameObject())).GetShootable().Contains(mousehex)) { return; }
                        //((Ship)(selectedhex.GetGameObject())).SetGhost(mousehex);
                    }

                    if (selectedhex.GetGameObject() is Warship && clickedaction == Command.Action.Colonize)
                    {
                        if (!((Warship)(selectedhex.GetGameObject())).GetReachable().Contains(mousehex)) { return; }
                        //((Ship)(selectedhex.GetGameObject())).SetGhost(mousehex);
                    }

                    if (selectedhex.GetGameObject() is Ship && clickedaction == Command.Action.Jump)
                    {
                        if (!((SolarSystem3D)(space)).GetWarpable().Contains(mousehex)) {}
                        else if (!selectedhex.GetGameObject().hex.hexgrid.neighbors.Contains((SolarSystem3D)(space))) {}
                        else
                        {
                            ((Ship)(selectedhex.GetGameObject())).SetGhost(mousehex);
                        }
                        Boolean vis = true;
                        int thresh = 0;
                        foreach (Hex3D h1 in ((SolarSystem3D)space).getHexes()) {
                            if (!h1.visible) {
                                vis = false;
                                break;
                            }
                            thresh ++;
                            if (thresh >= 10) {
                                break;
                            }
                        }
                        if (!vis) {
                            space = galaxy;
                            Console.WriteLine("BUMP");
                        }
                    }

                    middleman.AddCommand(new Command(selectedhex, mousehex, clickedaction));

                    clickedaction = Command.Action.None;
                    selectedhex = nullhex;
                }
            }

            /////stuff to do if a ship is selected/////
            GameObject selectedobject = selectedhex.GetGameObject();

            if (selectedobject != null && selectedobject is Unit) { statusmenu.Update((Unit)selectedobject); statusmenu.Show(); }
            else { statusmenu.Hide(); }

            if (selectedhex.GetGameObject() is Ship && clickedaction == Command.Action.Jump)
            {
                foreach (Hex3D h in ((SolarSystem3D)space).GetWarpable())
                {
                    h.color = Color.Blue;
                }
            }

            if (selectedobject != null && selectedobject is Ship && ((Ship)selectedobject).getAffiliation().Equals(player)) { shipmenu.Show(); }
            else { shipmenu.Hide(); }

            if (selectedobject != null && selectedobject is Warship)
            {

                foreach (Hex3D h in ((Warship)selectedobject).GetShootable())
                {
                    h.color = Color.Red;
                }
            }
            if (selectedobject != null && selectedobject is Ship)
            {
                Ship tmpShip = (Ship)selectedobject;
                if (oldShip != null && oldShip != tmpShip)
                {
                    tmpShip.shiptype.PlaySelectSound();
                }
                oldShip = tmpShip;
                foreach (Hex3D h in ((Ship)selectedobject).GetReachable())
                {
                    h.color = movecolor;
                }
            }

            ////VERY REDUNDANT, handles cases where range is smaller than speed
            if (selectedobject != null && selectedobject is Warship && ((Warship)selectedobject).GetRange() < ((Warship)selectedobject).getSpeed())
            {
                foreach (Hex3D h in ((Warship)selectedobject).GetShootable())
                {
                    h.color = Color.Red;
                }
            }

            //planetmenu
            if (selectedobject != null && selectedobject is Planet && ((Planet)selectedobject).getAffiliation() != null && ((Planet)selectedobject).getAffiliation().Equals(player)) { planetmenu.Show(); }
            else { planetmenu.Hide(); }

            //Color the mousedover hex
            if (mousehex != null && !mousehex.Equals(selectedhex) && !shipmenu.Contains(mousestate.X, mousestate.Y)) { mousehex.color = mousecolor; }

            telescopemenu.Hide();
        }
示例#7
0
        public void UpdateGalaxy()
        {
            statusmenu.Hide();
            SolarSystem3D mousesystem = galaxy.GetMouseOverSystem();
            if (oldmousesystem != null) oldmousesystem.sun.color = oldmousesystem.sun.defaultcolor;
            if (mousesystem != null) { mousesystem.sun.color = Color.Green; telescopemenu.Show(); telescopemenu.Update(mousesystem); }
            else { telescopemenu.Hide(); }

            if ((mousestate.LeftButton == ButtonState.Pressed) && (oldmousestate.LeftButton == ButtonState.Released) && !shipmenu.Contains(mousestate.X, mousestate.Y) && mousesystem != null)
            {
                if (clickedaction == Command.Action.Jump)
                {
                    //commands.Add(new Command(selectedhex, mousesystem.getHex(-2, -2), Command.Action.Jump));
                    space = mousesystem;
                    Boolean occupied = false;
                    foreach (Hex3D h1 in mousesystem.getHexes()) {
                        GameObject o = h1.GetGameObject();
                        if (o != null && o is Unit && ((Unit)o).getAffiliation() == player) {
                            occupied = true;
                            break;
                        }
                    }
                    if (!occupied) {
                        foreach (Hex3D h1 in mousesystem.getHexes()) {
                        h1.visible = false;
                        h1.color = Color.Black;
                        }
                    }

                    //selectedhex = nullhex;
                    clickedaction = Command.Action.Jump;

                }
                else {
                    HashSet<SolarSystem3D> targetable = new HashSet<SolarSystem3D>();
                    foreach (Unit u in player.army) {
                        targetable.Add(u.hex.hexgrid);
                    }
                    if (targetable.Contains(mousesystem)) {
                        space = mousesystem;
                    }

                }
            }

            oldmousesystem = mousesystem;
        }