コード例 #1
0
        public Unit spawnUnits()
        {
            Random rnd          = new Random();
            Unit   tmp          = null;
            bool   attackOption = (rnd.Next(1, 3) % 2 == 0 ? true : false);

            tmp = new NeutralCreep(spawnPointX, spawnPointY, 100, -1, attackOption, 1, faction, "W", "Wolf", spawnPointX - 3, spawnPointX + 3, spawnPointY - 3, spawnPointY + 3);
            return(tmp);
        }
コード例 #2
0
        public void readFile()
        {
            FileStream       inFile = null;
            StreamReader     reader = null;
            string           input;
            int              x;
            int              y;
            int              health;
            int              speed;
            bool             attack;
            int              range;
            string           faction;
            string           symbol;
            string           name;
            Unit             tmp       = null;
            FactoryBuilding  temp      = null;
            ResourceBuilding temporary = null;

            try
            {
                inFile = new FileStream(@"Files\Units.txt", FileMode.Open, FileAccess.Read);
                reader = new StreamReader(inFile);
                input  = reader.ReadLine();
                while (input != null)
                {
                    x       = Convert.ToInt32(input);
                    y       = Convert.ToInt32(reader.ReadLine());
                    health  = Convert.ToInt32(reader.ReadLine());
                    speed   = Convert.ToInt32(reader.ReadLine());
                    attack  = Convert.ToBoolean(reader.ReadLine());
                    range   = Convert.ToInt32(reader.ReadLine());
                    faction = reader.ReadLine();
                    symbol  = reader.ReadLine();
                    name    = reader.ReadLine();
                    if (symbol == "M")
                    {
                        tmp = new MeleeUnit(x, y, health, speed, attack, range, faction, symbol, name);
                    }
                    else if (symbol == "R")
                    {
                        tmp = new RangeUnit(x, y, health, speed, attack, range, faction, symbol, name);
                    }
                    unitsOnMap.Add(tmp);
                    map[x, y] = symbol;
                    input     = reader.ReadLine();
                }
                reader.Close();
                inFile.Close();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
            finally
            {
                if (inFile != null)
                {
                    reader.Close();
                    inFile.Close();
                }
            }
            int minXBoundary;
            int maxXBoundary;
            int minYBoundary;
            int maxYBoundary;

            try
            {
                inFile = new FileStream(@"Files\CreepUnits.txt", FileMode.Open, FileAccess.Read);
                reader = new StreamReader(inFile);
                input  = reader.ReadLine();
                while (input != null)
                {
                    x            = Convert.ToInt32(input);
                    y            = Convert.ToInt32(reader.ReadLine());
                    health       = Convert.ToInt32(reader.ReadLine());
                    speed        = Convert.ToInt32(reader.ReadLine());
                    attack       = Convert.ToBoolean(reader.ReadLine());
                    range        = Convert.ToInt32(reader.ReadLine());
                    faction      = reader.ReadLine();
                    symbol       = reader.ReadLine();
                    name         = reader.ReadLine();
                    minXBoundary = Convert.ToInt32(reader.ReadLine());
                    maxXBoundary = Convert.ToInt32(reader.ReadLine());
                    minYBoundary = Convert.ToInt32(reader.ReadLine());
                    maxYBoundary = Convert.ToInt32(reader.ReadLine());
                    tmp          = new NeutralCreep(x, y, health, speed, attack, range, faction, symbol, name, minXBoundary, maxXBoundary, minYBoundary, maxYBoundary);
                    unitsOnMap.Add(tmp);
                    map[x, y] = symbol;
                    input     = reader.ReadLine();
                }
                reader.Close();
                inFile.Close();
            }
            catch
            {
            }
            finally
            {
                if (inFile != null)
                {
                    reader.Close();
                    inFile.Close();
                }
            }
            int spawnPointX;
            int spawnPointY;
            int tickPerProduction;
            int unitsToProduce;

            try
            {
                inFile = new FileStream(@"Files\Structures.txt", FileMode.Open, FileAccess.Read);
                reader = new StreamReader(inFile);
                input  = reader.ReadLine();
                while (input != null)
                {
                    x                 = Convert.ToInt32(input);
                    y                 = Convert.ToInt32(reader.ReadLine());
                    health            = Convert.ToInt32(reader.ReadLine());
                    faction           = reader.ReadLine();
                    symbol            = reader.ReadLine();
                    spawnPointX       = Convert.ToInt32(reader.ReadLine());
                    spawnPointY       = Convert.ToInt32(reader.ReadLine());
                    tickPerProduction = Convert.ToInt32(reader.ReadLine());
                    unitsToProduce    = Convert.ToInt32(reader.ReadLine());
                    temp              = new FactoryBuilding(x, y, health, faction, symbol, spawnPointX, spawnPointY, tickPerProduction, unitsToProduce);
                    structuresOnMap.Add(temp);
                    map[x, y] = symbol;
                    input     = reader.ReadLine();
                }
                reader.Close();
                inFile.Close();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
            finally
            {
                if (inFile != null)
                {
                    reader.Close();
                    inFile.Close();
                }
            }
            string typeOfResource;
            int    resourcesPerTick;
            int    resourcesRemaining;

            try
            {
                inFile = new FileStream(@"Files\Resources.txt", FileMode.Open, FileAccess.Read);
                reader = new StreamReader(inFile);
                input  = reader.ReadLine();
                while (input != null)
                {
                    x                  = Convert.ToInt32(input);
                    y                  = Convert.ToInt32(reader.ReadLine());
                    health             = Convert.ToInt32(reader.ReadLine());
                    faction            = reader.ReadLine();
                    symbol             = reader.ReadLine();
                    typeOfResource     = reader.ReadLine();
                    resourcesPerTick   = Convert.ToInt32(reader.ReadLine());
                    resourcesRemaining = Convert.ToInt32(reader.ReadLine());
                    temporary          = new ResourceBuilding(x, y, health, faction, symbol, typeOfResource, resourcesPerTick, resourcesRemaining);
                    resourcesOnMap.Add(temporary);
                    map[x, y] = symbol;
                    input     = reader.ReadLine();
                }
                reader.Close();
                inFile.Close();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
            finally
            {
                if (inFile != null)
                {
                    reader.Close();
                    inFile.Close();
                }
            }
        }