Exemple #1
0
        Random r   = new Random();//creating new random number

        public Map()
        {
            for (int i = 0; i < 10; i++)        //looping through each element
            {
                int newX       = r.Next(0, 20); //randomise x and y position
                int newY       = r.Next(0, 20);
                int team       = i % 2;
                int tempAttack = 0;
                switch (r.Next(0, 4)) //getting random number betweeen 0 and 3 included
                {
                case 0:               //if 0 then attack equal to 5
                    tempAttack = 5;
                    break;

                case 1:
                    tempAttack = 10;
                    break;

                case 2:
                    tempAttack = 15;
                    break;

                case 3:
                    tempAttack = 20;
                    break;
                }

                switch (r.Next(0, 2))                                                                //getting random number between 0 and 1 included
                {
                case 0:                                                                              //if its 0 then do meleeunit
                    units[i] = new MeleeUnit(newX, newY, 100, 1, tempAttack, 1, team, i.ToString()); //updates the unit based on its changing x and y cord
                    break;

                case 1:    //if its 1 then do rangeunit
                    units[i] = new RangeUnit(newX, newY, 100, 1, tempAttack, 4, team, i.ToString());
                    break;
                }

                switch (r.Next(0, 2))//depending on the team, it will be randomized
                {
                case 0:
                    int typeOfFactory = r.Next(0. 2);
                    fBuildings[fCount] = new FactoryBuilding(newX, newY, 150, team, typeOfFactory, 2);    //randomly chooses a building type and team and places it on the x an y pos
                    fCount++;
                    break;

                case 1:
                    int typeOfResource = r.Next(0, 2);
                    rBuildings[rCount] = new ResourceBuilding(newX, newY, 150, team, 0, 50, typeOfResource);
                    rCount++;
                    break;

                default:
                    break;
                }
            }
        }
Exemple #2
0
        public void generateUnit()//method that spawns a unit
        {
            int tempAttack = 0;

            unitAdd = new Unit[m.units.Length + 1];
            Random r    = new Random();
            Unit   unit = null;

            switch (r.Next(0, 4))
            {
            case 0:
                tempAttack = 40;
                break;

            case 1:
                tempAttack = 50;
                break;

            case 2:
                tempAttack = 60;
                break;

            case 3:
                tempAttack = 90;
                break;
            }

            if (unitType == "0" && team == 1)
            {
                unit = new MeleeUnit(spawnX, spawnY, 100, 2, tempAttack, 30, team, ("" + symbol));//building type that belongs to team 1 will spawn in meleeunit
            }
            else if (unitType == "0" && team == 2)
            {
                unit = new MeleeUnit(spawnX, spawnY, 100, 2, tempAttack, 30, team, ("" + symbol));
            }

            if (unitType == "1" && team == 1)
            {
                unit = new RangeUnit(spawnX, spawnY, 100, 1, tempAttack, 90, team, ("" + symbol));
            }
            else if (unitType == "1" && team == 2)
            {
                unit = new RangeUnit(spawnX, spawnY, 100, 1, tempAttack, 90, team, ("" + symbol));//building type that belongs to team 2 will spawn at rangeunit
            }

            for (int loop = 0; loop < unitAdd.Length - 1; loop++)
            {
                unitAdd[loop] = m.units[loop];
            }

            unitAdd[unitAdd.Length - 1] = unit;//adds the unit at end
            m.units = unitAdd;
        }
Exemple #3
0
        public Unit[] units = new Unit[10];//new array with 10 elements

        public Map()
        {
            Random r = new Random();            //creating new random number

            for (int i = 0; i < 10; i++)        //looping through each element
            {
                int newX       = r.Next(0, 20); //randomise x and y position
                int newY       = r.Next(0, 20);
                int team       = i % 2;
                int tempAttack = 0;
                switch (r.Next(0, 4)) //getting random number betweeen 0 and 3 included
                {
                case 0:               //if 0 then attack equal to 5
                    tempAttack = 5;
                    break;

                case 1:
                    tempAttack = 10;
                    break;

                case 2:
                    tempAttack = 15;
                    break;

                case 3:
                    tempAttack = 20;
                    break;
                }

                switch (r.Next(0, 2))                                                                //getting random number between 0 and 1 included
                {
                case 0:                                                                              //if its 0 then do meleeunit
                    units[i] = new MeleeUnit(newX, newY, 100, 1, tempAttack, 1, team, i.ToString()); //updates the unit based on its changing x and y cord
                    break;

                case 1:    //if its 1 then do rangeunit
                    units[i] = new RangeUnit(newX, newY, 100, 1, tempAttack, 4, team, i.ToString());
                    break;
                }
            }
        }
Exemple #4
0
        public void read(string docPath)//read method that reads the save files
        {
            string line;
            int    countFBuildings = 0;
            int    countRBuildings = 0;
            int    countUnits      = 0;

            try
            {
                StreamReader sr = new StreamReader("c:\\RangeUnit.txt"); //passes the txt file and file path to the streamreader constructor

                line = sr.ReadLine();                                    //reads the first line
                int[] stats = line.Split(',').Select(p => int.Parse(p)).ToArray();
                units[countUnits] = new RangeUnit(stats[0], stats[2], stats[3], stats[4], stats[5], stats[6], countUnits.ToString());
                countUnits++;


                while (line != null)//continues reading
                {
                    line              = sr.ReadLine();
                    stats             = line.Split(',').Select(p => int.Parse(p)).ToArray();
                    units[countUnits] = new RangeUnit(stats[0], stats[2], stats[3], stats[4], stats[5], stats[6], countUnits.ToString());
                    countUnits++;
                }

                sr.Close();//closes the file
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }
            finally
            {
                Console.WriteLine("Executing block");
            }

            //Factory buildings
            try
            {
                StreamReader sr = new StreamReader("c:\\FactoryBuilding.txt");//reads the txt file

                line = sr.ReadLine();
                int[] stats = line.Split(',').Select(p => int.Parse(p)).ToArray();
                units[countFBuildings] = new FactoryBuilding(stats[0], stats[1], stats[2], stats[3], stats[4], stats[5], stats[6], countUnits.ToString());
                countFBuildings++;


                while (line != null)
                {
                    line  = sr.ReadLine();
                    stats = line.Split(',').Select(p => int.Parse(p)).ToArray();
                    fBuildings[countFBuildings] = new FactoryBuilding(stats[0], stats[2], stats[3], stats[4], stats[5], stats[6], countUnits.ToString());
                    countFBuildings++;
                }

                sr.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }
            finally
            {
                Console.WriteLine("Executing block");
            }

            //Resource Building
            try
            {
                StreamReader sr = new StreamReader("c:\\FactoryBuilding.txt");//reads the txt file

                line = sr.ReadLine();
                int[] stats = line.Split(',').Select(p => int.Parse(p)).ToArray();
                rBuildings[countRBuildings] = new ResourceBuilding(stats[0], stats[2], stats[3], stats[4], stats[5], stats[6], countUnits.ToString());
                countRBuildings++;


                while (line != null)
                {
                    line  = sr.ReadLine();
                    stats = line.Split(',').Select(p => int.Parse(p)).ToArray();
                    rBuildings[countRBuildings] = new ResourceBuilding(stats[0], stats[2], stats[3], stats[4], stats[5], stats[6], countUnits.ToString());
                    countRBuildings++;
                }

                sr.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }
            finally
            {
                Console.WriteLine("Executing block");
            }
        }