Esempio n. 1
0
        // shows units once they are clicked
        public void Unit_Click(object sender, EventArgs e)
        {
            int    x, y;
            Button b = (Button)sender;

            x = b.Location.X / 20;
            y = b.Location.Y / 20;
            foreach (Unit u in units)
            {
                if (u is RangedUnit)
                {
                    RangedUnit ru = (RangedUnit)u;
                    if (ru.XPos == x && ru.YPos == y)
                    {
                        txtInfo.Text = "";
                        txtInfo.Text = ru.ToString();
                    }
                }
                else if (u is WizardUnit)
                {
                    WizardUnit wu = (WizardUnit)u;
                    if (wu.XPos == x && wu.YPos == y)
                    {
                        txtInfo.Text = "";
                        txtInfo.Text = wu.ToString();
                    }
                    else if (u is MeleeUnit)
                    {
                        MeleeUnit mu = (MeleeUnit)u;
                        if (mu.XPos == x && mu.YPos == y)
                        {
                            txtInfo.Text = "";
                            txtInfo.Text = mu.ToString();
                        }
                    }
                }
                foreach (Building bu in building)
                {
                    if (bu is ResourceBuilding)
                    {
                        ResourceBuilding ru = (ResourceBuilding)bu;
                        if (ru.XPos == x && ru.YPos == y)
                        {
                            txtInfo.Text = "";
                            txtInfo.Text = ru.ToString();
                        }
                    }
                    else if (bu is FactoryBuilding)
                    {
                        FactoryBuilding mu = (FactoryBuilding)bu;
                        if (mu.XPos == x && mu.YPos == y)
                        {
                            txtInfo.Text = "";
                            txtInfo.Text = mu.ToString();
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        //Code given by Declan Porter
        public void DeclanFunctionalApproachToTheSaveFunction()
        {
            StreamWriter writer   = new StreamWriter("Local_Save.txt");
            string       Faction0 = "";
            string       Faction1 = "";

            writer.WriteLine("START OF SAVE");
            foreach (Unit u in map.Units)
            {
                if (u is MeleeUnit)
                {
                    MeleeUnit uu = (MeleeUnit)u;
                    if (uu.Faction == 0)
                    {
                        Faction0 += uu.ToString() + "\n";
                    }
                    else
                    {
                        Faction1 += uu.ToString() + "\n";
                    }
                }
                else if (u is RangedUnit)
                {
                    RangedUnit uu = (RangedUnit)u;
                    if (uu.Faction == 0)
                    {
                        Faction0 += uu.ToString() + "\n";
                    }
                    else
                    {
                        Faction1 += uu.ToString() + "\n";
                    }
                }
            }
            writer.WriteLine("UNITS -- FACTION 0");
            writer.WriteLine(Faction0);
            writer.WriteLine("UNITS -- FACTION 1");
            writer.WriteLine(Faction1);
            Faction0 = "";
            Faction1 = "";
            foreach (Building u in map.Buildings)
            {
                if (u is ResourceBuilding)
                {
                    ResourceBuilding uu = (ResourceBuilding)u;
                    if (uu.Faction == 0)
                    {
                        Faction0 += uu.ToString() + "\n";
                    }
                    else
                    {
                        Faction1 += uu.ToString() + "\n";
                    }
                }
                else if (u is FactoryBuilding)
                {
                    FactoryBuilding uu = (FactoryBuilding)u;
                    if (uu.Faction == 0)
                    {
                        Faction0 += uu.ToString() + "\n";
                    }
                    else
                    {
                        Faction1 += uu.ToString() + "\n";
                    }
                }
            }

            writer.WriteLine("BUILDINGS-- FACTION 0");
            writer.WriteLine(Faction0);
            writer.WriteLine("BUILDINGS-- FACTION 1");
            writer.WriteLine(Faction1);
            writer.WriteLine("END OF SAVE");
        }