Exemplo n.º 1
0
        public void ManageBuildings()
        {
            for (int l = 0; l < map.buildings.Length; l++)
            {
                int amount = 0;

                if (map.buildings[l].Destroyed == false)
                {
                    if (map.buildings[l].GetType() == factoryCheck.GetType())
                    {
                        factoryCheck = (FactoryBuilding)map.buildings[l];

                        if (factoryCheck.Faction == 0)
                        {
                            if (rounds % factoryCheck.ProductionSpeed == 0 && teamResources0 >= 10)
                            {
                                Array.Resize(ref map.units, map.units.Length + 1);
                                map.units[map.units.Length - 1] = factoryCheck.SpawnUnit();
                                teamResources0 -= 10;
                            }
                        }
                        else
                        {
                            if (rounds % factoryCheck.ProductionSpeed == 0 && teamResources1 >= 10)
                            {
                                Array.Resize(ref map.units, map.units.Length + 1);
                                map.units[map.units.Length - 1] = factoryCheck.SpawnUnit();
                                teamResources1 -= 10;
                            }
                        }
                    }
                    else if (map.buildings[l].GetType() == resourceCheck.GetType())
                    {
                        resourceCheck    = (ResourceBuilding)map.buildings[l];
                        amount           = resourceCheck.Collect();
                        map.buildings[l] = resourceCheck;

                        if (resourceCheck.Faction == 0)
                        {
                            teamResources0 += amount;
                        }
                        else
                        {
                            teamResources1 += amount;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public override void Save(Building[] building)
        {
            FileStream       outFile = new FileStream(FILE_NAME, FileMode.Create, FileAccess.Write);
            StreamWriter     writer  = new StreamWriter(outFile);
            ResourceBuilding rCheck  = new ResourceBuilding();

            for (int r = 0; r < building.Length; r++)
            {
                if (building[r].GetType() == rCheck.GetType())
                {
                    rCheck = (ResourceBuilding)building[r];
                    writer.WriteLine("" + rCheck.x + DELIMITER + rCheck.y + DELIMITER + rCheck.health + DELIMITER + rCheck.maxHealth + DELIMITER + rCheck.faction + DELIMITER + rCheck.symbol + DELIMITER + rCheck.resourceType + DELIMITER + rCheck.resourcesGenerated + DELIMITER + rCheck.generation + DELIMITER + rCheck.remaining);
                }
            }
            writer.Close();
            outFile.Close();
        }
Exemplo n.º 3
0
        // intialize all units & Buildings with their values
        private void GenerateBattlefield()
        {
            for (int l = 0; l < units.Length; l++) // loop through unit array length
            {
                switch (rnd.Next(0, 3))
                {
                case 0:
                    MeleeUnit mUnit = new MeleeUnit();
                    mUnit.X = rnd.Next(0, WIDTH);
                    mUnit.Y = rnd.Next(0, HEIGHT);

                    if (rnd.Next(0, 2) == 0)
                    {
                        mUnit.Faction = 0;
                    }
                    else
                    {
                        mUnit.Faction = 1;
                    }

                    units[l] = mUnit;
                    break;

                case 1:
                    RangedUnit rUnit = new RangedUnit(); // temp rangedunit
                    rUnit.X = rnd.Next(0, WIDTH);        // random x, y
                    rUnit.Y = rnd.Next(0, HEIGHT);

                    if (rnd.Next(0, 2) == 0) // if 0 then faction 0
                    {
                        rUnit.Faction = 0;
                    }
                    else // else faction 1
                    {
                        rUnit.Faction = 1;
                    }

                    units[l] = rUnit; // assign temp to unit array
                    break;

                case 2:
                    WizardUnit wUnit = new WizardUnit(); // temp rangedunit
                    wUnit.X = rnd.Next(0, WIDTH);        // random x, y
                    wUnit.Y = rnd.Next(0, HEIGHT);

                    units[l] = wUnit;     // assign temp to unit array
                    break;
                }
            }

            for (int l = 0; l < buildings.Length; l++)
            {
                if (rnd.Next(0, 2) == 0)                              // if 0 then create resource building
                {
                    ResourceBuilding rBuild = new ResourceBuilding(); // temp resource buliding
                    rBuild.X = rnd.Next(0, WIDTH);                    // random x, y
                    rBuild.Y = rnd.Next(0, HEIGHT);

                    switch (rnd.Next(0, 3))
                    {
                    case 0:
                        rBuild.ResourceType = "Ores";
                        rBuild.Generation   = 1;
                        rBuild.Remaining    = 45;
                        break;

                    case 1:
                        rBuild.ResourceType = "Lumber";
                        rBuild.Generation   = 2;
                        rBuild.Remaining    = 120;
                        break;

                    case 2:
                        rBuild.ResourceType = "Wheat";
                        rBuild.Generation   = 3;
                        rBuild.Remaining    = 30;
                        break;
                    }

                    if (rnd.Next(0, 2) == 0) // if 0 then faction 0
                    {
                        rBuild.Faction = 0;
                    }
                    else // else faction 1
                    {
                        rBuild.Faction = 1;
                    }

                    buildings[l] = rBuild; // assign temp to buildings array
                }
                else // else create factory building
                {
                    FactoryBuilding fBuild = new FactoryBuilding(); // temp factory building
                    fBuild.X = rnd.Next(0, WIDTH);                  // random x, y
                    fBuild.Y = rnd.Next(0, HEIGHT);

                    if (fBuild.Y == HEIGHT - 1)
                    {
                        fBuild.SpawnX = fBuild.X;
                        fBuild.SpawnY = fBuild.Y - 1;
                    }
                    else
                    {
                        fBuild.SpawnX = fBuild.X;
                        fBuild.SpawnY = fBuild.Y + 1;
                    }

                    if (rnd.Next(0, 2) == 0)
                    {
                        fBuild.UnitType        = "MeleeUnit";
                        fBuild.ProductionSpeed = 7;
                    }
                    else
                    {
                        fBuild.UnitType        = "RangedUnit";
                        fBuild.ProductionSpeed = 9;
                    }

                    if (rnd.Next(0, 2) == 0) // if 0 then faction 0
                    {
                        fBuild.Faction = 0;
                    }
                    else // else faction 1
                    {
                        fBuild.Faction = 1;
                    }

                    buildings[l] = fBuild; // assign temp to building array
                }
            }
        }