示例#1
0
        /// <summary>
        /// Initialize necessary components
        /// </summary>
        private void initialize()
        {
            game = new XnaUITestGame();
            ZRTSController controller = new ZRTSController(game);

            game.Components.Add(controller);

            model = new GameModel();
            ScenarioComponent scenario = new ScenarioComponent(50, 50);

            player1      = new PlayerComponent();
            player2      = new PlayerComponent();
            player1.Name = "Nate";
            player2.Name = "Smith";


            // Add sand cells at each cell.
            ZRTSModel.Map map = scenario.GetGameWorld().GetMap();
            for (int i = 0; i < map.GetWidth(); i++)
            {
                for (int j = 0; j < map.GetHeight(); j++)
                {
                    CellComponent cell = new CellComponent();
                    cell.AddChild(new Sand());
                    cell.X = i;
                    cell.Y = j;
                    map.AddChild(cell);
                }
            }
            model.AddChild(scenario);
            game.Model = model;
            game.Model.PlayerInContext = player1;   // Set a main Player

            //Create two players and set them to be enemies.
            game.Model.GetScenario().GetGameWorld().GetPlayerList().AddChild(player1);
            game.Model.GetScenario().GetGameWorld().GetPlayerList().AddChild(player2);

            // Set target enemy
            player1.EnemyList.Add(player2);
            player2.EnemyList.Add(player1);

            game.Controller = controller;

            // Add worker to player
            unitList = new List <ModelComponent>();
            unitList.Add(new UnitComponent());
            ((UnitComponent)unitList[0]).CanBuild      = true;
            ((UnitComponent)unitList[0]).Type          = "worker";
            ((UnitComponent)unitList[0]).PointLocation = new PointF(20, 20);


            //(1) Get Player#1
            currentPlayer1 = (PlayerComponent)((XnaUITestGame)game).Model.GetScenario().GetGameWorld().GetPlayerList().GetChildren()[0];

            // check if fetch the correct player
            Assert.AreEqual("Nate", currentPlayer1.Name);

            // (2) Add the actual player's unit list
            currentPlayer1.GetUnitList().AddChild(unitList[0]);
        }
        private void setupModel()
        {
            model = new GameModel();
            ScenarioComponent scenario = new ScenarioComponent(20, 20);             // 20 x 20 Gameworld.

            // Add grass cells at each cell.
            ZRTSModel.Map map = scenario.GetGameWorld().GetMap();
            for (int i = 0; i < map.GetWidth(); i++)
            {
                for (int j = 0; j < map.GetHeight(); j++)
                {
                    CellComponent cell = new CellComponent();
                    cell.AddChild(new Sand());
                    cell.X = i;
                    cell.Y = j;
                    map.AddChild(cell);
                }
            }
            model.AddChild(scenario);

            //Create two players and set them to be enemies.
            model.GetScenario().GetGameWorld().GetPlayerList().AddChild(new PlayerComponent());
            model.GetScenario().GetGameWorld().GetPlayerList().AddChild(new PlayerComponent());
            PlayerComponent player1 = (PlayerComponent)model.GetScenario().GetGameWorld().GetPlayerList().GetChildren()[0];
            PlayerComponent player2 = (PlayerComponent)model.GetScenario().GetGameWorld().GetPlayerList().GetChildren()[1];

            player1.EnemyList.Add(player2);
            player2.EnemyList.Add(player1);
        }
示例#3
0
        /// <summary>
        /// Loads a scenario from disc by deserializing.  Generates empty observer lists for each model component.
        /// </summary>
        public void loadScenario()
        {
            if (model.GetScenario() != null)
            {
                // TODO: Ask if the user wants to discard the current scenario.
            }

            // Displays an OpenFileDialog so the user can select a Map.
            OpenFileDialog openMapDialog = new OpenFileDialog();

            openMapDialog.InitialDirectory = Application.StartupPath + "\\Maps\\";
            openMapDialog.Filter           = "Map Files|*.map";
            openMapDialog.Title            = "Select a Map File";

            if (openMapDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Stream            mapFile  = openMapDialog.OpenFile();
                ScenarioXMLReader reader   = new ScenarioXMLReader(mapFile);
                ScenarioComponent scenario = reader.GenerateScenarioFromXML();
                mapFile.Close();
                model.AddChild(scenario);

                // Clear the stack because we now have a new scenario in context.
                model.GetCommandStack().EmptyStacks();
                // TODO: Update the SaveInfo state.
            }
        }
        public void loadScenario()
        {
            if (improvedModel.GetScenario() != null)
            {
                // TODO: Ask if the user wants to discard the current scenario.
            }

            // Displays an OpenFileDialog so the user can select a Map.
            OpenFileDialog openMapDialog = new OpenFileDialog();

            openMapDialog.InitialDirectory = Application.StartupPath + "\\Maps\\";
            openMapDialog.Filter           = "Map Files|*.map";
            openMapDialog.Title            = "Select a Map File";

            if (openMapDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                // Deserialize the file and load it into the model.
                BinaryFormatter           bin      = new BinaryFormatter();
                ScenarioComponent         scenario = (ScenarioComponent)bin.Deserialize(openMapDialog.OpenFile());
                CreateObserverListVisitor visitor  = new CreateObserverListVisitor();
                scenario.Accept(visitor);
                scenario.GetGameWorld().GetMap().SetCellsToBeContainedInMap();
                improvedModel.AddChild(scenario);

                // Invalidate the Scenario view.
                scenario.GetGameWorld().NotifyAll();

                // TODO: Update the SaveInfo state.
            }
        }
示例#5
0
        public LoseWhenAllPlayersUnitsAreDead(PlayerComponent player, ScenarioComponent scenario)
        {
            condition     = new ConditionAllPlayerUnitsDead(this, player);
            this.scenario = scenario;

            action = new PlayerLoseAction(this, scenario);
        }
示例#6
0
    public ScenarioComponent SimpleSearch(int id) //no list
    {
        Debug.Log("SEARCHAADAA DO CLICK: " + id);
        MySqlCommand      command = GameManager.instance.Con.CreateCommand();
        MySqlDataReader   data;
        ScenarioComponent comp = null;
        string            sql  = @"select * from component as comp where component_id = " + id;

        command.CommandText = sql;
        data = command.ExecuteReader();

        if (data.Read())
        {
            comp = new ScenarioComponent(
                Convert.ToInt32(data["component_id"]),
                data["component_name"].ToString(),
                data["component_description"].ToString(),
                Convert.ToInt32(data["component_status"]),
                new VirtualObject(
                    Convert.ToInt32(data["objComp_id"])
                    )
                );
        }
        data.Close();
        return(comp);
    }
示例#7
0
    public void TableLoad()
    {
        List <ScenarioComponent> comps;
        Button newRow;

        if (rowsClone != null)
        {
            var clones = new Transform[rows.transform.childCount];
            for (var i = 1; i < clones.Length; i++)
            {
                clones[i] = rows.transform.GetChild(i);
                Destroy(clones[i].gameObject);
            }
            row.gameObject.SetActive(true);
        }

        List <Button> btns = new List <Button>();

        comps = new ScenarioComponent().SearchAll(inputFieldSearch.text, toggleStatusSearch.isOn);
        for (int i = 0; i < comps.Count; i++)
        {
            textIDB.text          = comps[i].Id.ToString();
            textNameB.text        = comps[i].Name;
            textDescriptionB.text = comps[i].Description;
            textStatusB.text      = comps[i].Status == 1 ? "Ativo" : "Desativado";
            newRow = Instantiate(row) as Button;
            newRow.transform.SetParent(row.transform.parent, false);
            btns.Add(newRow);
        }

        rowsClone = rows;
        row.gameObject.SetActive(false);
        AddListener(btns);
    }
示例#8
0
    public void ConfirmScenarioClick()
    {
        ClearComponentTable();

        currentScenario = new Scenario().Search(selectedScenarioId);
        panelScenario2.gameObject.SetActive(false);
        panelScenario1.gameObject.SetActive(false);
        panelSelectScenario.gameObject.SetActive(false);
        inputFieldScenario.text = currentScenario.Name;
        selectedScenarioId      = 0;

        //VE SE TEM E TA NO DROPDOWN
        if (dropdownComponent.options.Count > 0 && dropdownComponent.value > -1)
        {
            int comp_id = arrayAllComponents[dropdownComponent.value].Key;
            int sce_id  = currentScenario.Id;
            int max     = new ScenarioComponent().GetMaxQuantityScenarioComponent(comp_id, sce_id);
            if (max > 1) // varios
            {
                sliderQuantity.interactable = true;
                sliderQuantity.minValue     = 1;
                sliderQuantity.maxValue     = max;
            }
            else
            {
                sliderQuantity.interactable = false;
            }
            sliderQuantity.value = 1;
        }
    }
        public void createNewScenario()
        {
            /********************
             * // TODO Extract this logic with loadscenario.
             * if (model.scenario != null)
             * {
             *  // TODO: Ask if the user wants to discard the current scenario.
             * }
             * model.scenario = new ZRTSModel.Scenario.Scenario(20, 20);
             *
             * // Since this is a new scenario, it has not been saved and does not have a filename
             * model.filename = null;
             * model.saved = false;
             *
             * //The model has changed, so notify all views of the change.
             * model.notifyAll();
             *************/

            if (improvedModel.GetScenario() != null)
            {
                // TODO: Ask if the user wants to discard the current scenario or save it.
            }
            ScenarioComponent scenario = new ScenarioComponent(20, 20);

            // TODO: Update SaveInfo model to change filename and UpToDate flag.

            // Automatically discards old scenario, by overloaded AddChild function.
            improvedModel.AddChild(scenario);
        }
示例#10
0
    public void RowClick(Button br)
    {
        state = 2;
        ScenarioComponent comp = new ScenarioComponent().Search(Convert.ToInt32(br.gameObject.GetComponentInChildren <Text>(textIDB).text));

        buttonDelete.gameObject.SetActive(true);

        textComponentID.text       = comp.Id.ToString();
        inputFieldName.text        = comp.Name;
        inputFieldDescription.text = comp.Description;

        toggleStatus.isOn = comp.Status == 1;

        textTitle.text = "Gerenciar Componente - Alterar";
        panelTableComponent.SetActive(true);
        panelVirtualObj.SetActive(true);
        LoadDropdown();

        int i = 0;

        while (i < dropdownSelectObject.options.Count &&
               arrayAllVirtualObj[i].Key != comp.ObjComponent.Id)
        {
            i++;
        }
        dropdownSelectObject.value = i;

        listScenario = comp.ListScenarios;
        foreach (KeyValuePair <int, string> par in listScenario)
        {
            AddRowTableScenario(par);
        }
    }
        public void Init(MapEditorController controller, MapEditorFullModel model)
        {
            this.controller = controller;

            context = model.GetScenario();
            model.ScenarioChangedEvent += this.ChangeScenario;
        }
        public void saveScenario()
        {
            if (improvedModel.GetScenario() != null)
            {
                Stream         saveStream;
                SaveFileDialog saveMapDialog = new SaveFileDialog();
                saveMapDialog.InitialDirectory = Application.StartupPath + "\\Maps\\";
                saveMapDialog.Filter           = "Map files (*.map)| *.map";

                if (saveMapDialog.ShowDialog() == DialogResult.OK)
                {
                    if ((saveStream = saveMapDialog.OpenFile()) != null)
                    {
                        BinaryFormatter bin = new BinaryFormatter();

                        ScenarioComponent scenario = improvedModel.GetScenario();
                        scenario.SetContainer(null);
                        bin.Serialize(saveStream, scenario);
                        saveStream.Close();
                        improvedModel.AddChild(scenario);
                        // TODO: Change so that the SaveInfo model is updated.
                    }
                }
            }
        }
        private void saveAsMenuItem_Click(object sender, EventArgs e)
        {
            // Save currently-selected scenario as a new hsx assembly
            TreeNode          selected = mainTreeView.SelectedNode;
            ScenarioComponent scenario = getScenarioFromNode(selected);

            // Clear file target for this scenario form to force save dialog
            TreeNode scenarioNode = null;

            foreach (TreeNode node in mainTreeView.Nodes)
            {
                if (((ScenarioForm)node.Tag).Scenario == scenario)
                {
                    scenarioNode = node;
                    break;
                }
            }
            if (scenarioNode == null)
            {
                // No top-level node exists with this scenario as a tag
                ReportError("No top-level node exists with this scenario as a tag");
                return;
            }
            ((ScenarioForm)scenarioNode.Tag).FileTarget = "";
            saveScenario(scenario);
        }
 private void ChangeScenario(object sender, EventArgs e)
 {
     if (sender is MapEditorFullModel) // sanity check
     {
         context = ((MapEditorFullModel)sender).GetScenario();
     }
 }
        private void contextCloseMenuItem_Click(object sender, EventArgs e)
        {
            // Closes the currently selected scenario
            TreeNode          selected = mainTreeView.SelectedNode;
            ScenarioComponent scenario = getScenarioFromNode(selected);

            closeScenario(scenario);
        }
        private void saveMenuItem_Click(object sender, EventArgs e)
        {
            // Save currently selected scenario
            TreeNode          selected = mainTreeView.SelectedNode;
            ScenarioComponent scenario = getScenarioFromNode(selected);

            saveScenario(scenario);
        }
示例#17
0
    public void ConfirmClick()
    {
        string            id          = textComponentID.text;
        string            name        = inputFieldName.text;
        string            description = inputFieldDescription.text;
        int               objComp_id  = arrayAllVirtualObj[dropdownSelectObject.value].Key;
        bool              status      = toggleStatus.isOn;
        ScenarioComponent comp;

        if (name.Trim() == "")
        {
            LevelManager.Instance.AlterMessage("Nome inválido. Digite um nome válido!", Color.red);
        }
        else if (description.Trim() == "")
        {
            LevelManager.Instance.AlterMessage("Descrição inválida. Digite uma descrição válida!", Color.red);
        }
        else
        {
            comp = new ScenarioComponent(name, description, status ? 1 : 0, listScenario.Count > 0 ? listScenario : null,
                                         new VirtualObject(objComp_id));
            if (state == 1) //add
            {
                string returnMsg = comp.Insert();
                if (returnMsg.Equals("Ok"))
                {
                    LevelManager.Instance.AlterMessage("Componente inserido com sucesso!", Color.green);
                    Begin();
                    if (rowsClone != null)
                    {
                        ClearMainTable();
                    }
                }
                else
                {
                    LevelManager.Instance.AlterMessage(returnMsg, Color.red);
                }
            }
            else if (state == 2)//alter
            {
                string returnMsg = comp.Alter(Convert.ToInt32(id));
                if (returnMsg.Equals("Ok"))
                {
                    LevelManager.Instance.AlterMessage("Componente alterado com sucesso!", Color.green);
                    Begin();
                    if (rowsClone != null)
                    {
                        ClearMainTable();
                    }
                }
                else
                {
                    LevelManager.Instance.AlterMessage(returnMsg, Color.red);
                }
            }
        }
    }
示例#18
0
 public override void Visit(MapEditorFullModel model)
 {
     scenario = model.GetScenario();
     if (scenario != prevScenario)
     {
         scenarioChanged = true;
     }
     base.Visit(model);
 }
示例#19
0
        /// <summary>
        /// Loading game scenario object for process
        /// </summary>
        /// <param name="scene"></param>
        public void LoadScenario(ScenarioComponent scene)
        {
            // Need not to load this scenario into View
            // Basically just return a command corresponding to the clicked icon
            // i.e. click at attack icon, will return attack command and then process the game logic in the gameloop inside ZRTS update();



            this.scenario = scene;
        }
示例#20
0
    private List <KeyValuePair <Vector3, Quaternion> > GetCarInitialPositions(int comp_id)
    {
        List <KeyValuePair <Vector3, Quaternion> > list = new List <KeyValuePair <Vector3, Quaternion> >();
        string text = new ScenarioComponent().GetComponentInitialPosition(comp_id, currentSession.Scenario.Id);

        string[] positions = text.Split('/');
        for (int i = 0; i < positions.Length; i++)
        {
            list.Add(GetPosition(positions[i]));
        }
        return(list);
    }
示例#21
0
    public void RowClickComp(Button br, int quant)
    {
        //mostra imagem com componente
        panelComponentInfo.gameObject.SetActive(true);
        ScenarioComponent component = new ScenarioComponent().SimpleSearch(Convert.ToInt32(br.gameObject.GetComponentInChildren <Text>(textIDBComponent).text));

        inputFieldComponentName.text        = component.Name;
        inputFieldComponentQuantity.text    = quant.ToString();
        inputFieldComponentDescription.text = component.Description;

        imgComponent.texture = Resources.Load(new VirtualObject().GetComponentImageByScenarioId(component.Id)) as Texture;
    }
 private TreeNode getNodeFromScenario(ScenarioComponent scenario)
 {
     // Returns the treenode that tags the given scenario's form
     foreach (TreeNode node in mainTreeView.Nodes)
     {
         if (((ScenarioForm)node.Tag).Scenario == scenario)
         {
             return(node);
         }
     }
     ReportError("No node found for the scenario " + scenario.ScenarioName);
     return(null);
 }
 public ScenarioForm(ScenarioComponent targetComponent, Form parentWindow)
 {
     // Creates a new scenario form based on the given scenario component
     InitializeComponent();
     MdiParent = parentWindow;
     Tag       = targetComponent;
     Scenario  = targetComponent;
     Text      = Scenario.ScenarioName + " (Scenario)";
     _mManager = new MementoManager((IMForm)parentWindow);
     RefreshValues();
     IsSaved    = true;
     FileTarget = "";
 }
 override public void AddChild(ModelComponent child)
 {
     // Allow only one scenario.
     if (child is ScenarioComponent)
     {
         ScenarioComponent scenario = GetScenario();
         if (scenario != null)
         {
             RemoveChild(scenario);
         }
     }
     base.AddChild(child);
 }
        private void openScenarioFromFile()
        {
            // Opens new scenario using open file dialog
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter = "Hsx file (.hsx)|*.hsx|All files|*.*";
            dialog.Title  = "Open Scenario";
            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            // Loads new scenario using components specified in given HSX file from dialog
            string           filename = dialog.FileName;
            XqlParser        myParser = new XqlParser(filename);
            List <Hashtable> result;

            // Determine paths
            result = myParser.Query("SELECT path FROM hsx"); string            rootPath = (string)result[0]["path"];
            result = myParser.Query("SELECT filename FROM scenario"); string   scenPath = (string)rootPath + result[0]["filename"];
            result = myParser.Query("SELECT filename FROM targetdeck"); string trgtPath = (string)rootPath + result[0]["filename"];
            result = myParser.Query("SELECT filename FROM model"); string      modlPath = (string)rootPath + result[0]["filename"];

            // Create new scenario component from file and attach to form
            ScenarioComponent newScenario = new ScenarioComponent();

            newScenario.FromFile(scenPath);
            ScenarioForm scenarioForm = new ScenarioForm(newScenario, this);

            scenarioForm.FileTarget = filename;
            _scenarios.Add(scenarioForm);

            // Form takes care of itself via node update?
            // Create new targetdeck from file and attach to scenario
            TargetdeckComponent newTargetdeck = new TargetdeckComponent();

            newTargetdeck.FromFile(trgtPath);
            newScenario.Targetdeck = newTargetdeck;

            // Create new model from file and attach to scenario
            ModelComponent newModel = new ModelComponent();

            newModel.FromFile(modlPath);
            newScenario.Model = newModel;

            // Update node tree and select scenario
            UpdateScenarioNode(scenarioForm);
            TreeNode node = getNodeFromForm(scenarioForm);

            mainTreeView.SelectedNode = node;
        }
        /// <summary>
        /// Load information from the map file
        /// </summary>
        /// <param name="filename"></param>
        protected void LoadModelFromFile(string filename)
        {
            // Create or load the model.
            model = new GameModel();
            ZRTSCompositeViewUIFactory.Initialize(this);

            FileStream        mapFile  = File.OpenRead(filename);     //tryit.map
            ScenarioXMLReader reader   = new ScenarioXMLReader(mapFile);
            ScenarioComponent scenario = reader.GenerateScenarioFromXML();

            model.AddChild(scenario);
            model.PlayerInContext = (PlayerComponent)model.GetScenario().GetGameWorld().GetPlayerList().GetChildren()[0];
            //model.PlayerInContext.EnemyList.Add((PlayerComponent)model.GetScenario().GetGameWorld().GetPlayerList().GetChildren()[1]);


            foreach (PlayerComponent p in scenario.GetGameWorld().GetPlayerList().GetChildren())
            {
                foreach (PlayerComponent po in scenario.GetGameWorld().GetPlayerList().GetChildren())
                {
                    if (p != po)
                    {
                        p.EnemyList.Add(po);
                    }
                }
            }

            Console.WriteLine(ZRTSModel.Factories.BuildingFactory.Instance.getBuildingTypes()[0]);

            // Create the controller, Remove the old one if it exists.
            if (this.controller != null)
            {
                Components.Remove(this.controller);
            }

            controller = new ZRTSController(this);
            Components.Add(controller);

            // Set the mouse visible
            this.IsMouseVisible = true;

            PlayerComponent player = model.PlayerInContext;

            foreach (PlayerComponent enemy in player.EnemyList)
            {
                WinWhenAllEnemyUnitsDead win = new WinWhenAllEnemyUnitsDead(enemy, scenario);
                scenario.triggers.Add(win);
            }
            LoseWhenAllPlayersUnitsAreDead lose = new LoseWhenAllPlayersUnitsAreDead(player, scenario);

            scenario.triggers.Add(lose);
        }
        public ScenarioComponent GetScenario()
        {
            ScenarioComponent scenario = null;

            foreach (ModelComponent component in GetChildren())
            {
                if (component is ScenarioComponent)
                {
                    scenario = (ScenarioComponent)component;
                    break;
                }
            }
            return(scenario);
        }
示例#28
0
    public void LoadComponentDropdown()
    {
        dropdownComponent.ClearOptions();
        List <ScenarioComponent> lista = new ScenarioComponent().GetComponentsByScenario(currentScenario.Id);

        arrayAllComponents = new KeyValuePair <int, string> [lista.Count];
        for (int i = 0; i < lista.Count; i++)
        {
            arrayAllComponents[i] = new KeyValuePair <int, string>(lista[i].Id, lista[i].Name);
            dropdownComponent.options.Add(new Dropdown.OptionData(lista[i].Name));
        }
        dropdownComponent.value = -1;
        dropdownComponent.value = 0;
    }
 public ScenarioForm(Form parentWindow)
 {
     // Creates a new scenario form with a new scenario component
     InitializeComponent();
     Scenario  = new ScenarioComponent();
     MdiParent = parentWindow;
     Tag       = Scenario;
     Text      = Scenario.ScenarioName + " (Scenario)";
     _mManager = new MementoManager((IMForm)parentWindow);
     RefreshValues();
     IsSaved    = true;
     Version    = 0.1;
     FileTarget = "";
 }
示例#30
0
        public void SetScenario(ScenarioComponent scenario)
        {
            if (gameworld != null)
            {
                gameworld.UnregisterObserver(this);
            }
            context = scenario;

            if (scenario != null)
            {
                gameworld = scenario.GetGameWorld();
                if (gameworld != null)
                {
                    gameworld.RegisterObserver(this);
                }
            }
        }
 public WinWhenAllEnemyUnitsDead(PlayerComponent enemy, ScenarioComponent scenario)
 {
     condition = new ConditionAllPlayerUnitsDead(this,enemy);
     this.scenario = scenario;
     action = new PlayerWinAction(this, scenario);
 }