示例#1
0
        public override void Save(Building[] building)
        {
            FileStream      outFile = new FileStream(FILE_NAME, FileMode.Create, FileAccess.Write);
            StreamWriter    writer  = new StreamWriter(outFile);
            FactoryBuilding fCheck  = new FactoryBuilding();

            for (int r = 0; r < building.Length; r++)
            {
                if (building[r].GetType() == fCheck.GetType())
                {
                    fCheck = (FactoryBuilding)building[r];
                    writer.WriteLine("" + fCheck.x + DELIMITER + fCheck.y + DELIMITER + fCheck.health + DELIMITER + fCheck.maxHealth + DELIMITER + fCheck.faction + DELIMITER + fCheck.symbol + DELIMITER + fCheck.unitType + DELIMITER + fCheck.productionSpeed + DELIMITER + fCheck.spawnX + DELIMITER + fCheck.spawnY);
                }
            }
            writer.Close();
            outFile.Close();
        }
示例#2
0
文件: Map.cs 项目: Dylads/POE-Task-3
        // 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
                }
            }
        }