Ejemplo n.º 1
0
        public FactoryUpgrades(FactoryBuilding factoryBuilding, bool isContinueClicker)
        {
            this.isContinueClicker = isContinueClicker;
            this.factoryBuilding   = factoryBuilding;

            InitializeUpgrades();

            allUpgrades = new List <Upgrade>();

            allUpgrades.Add(fiveFactoriesUpgrade);
            allUpgrades.Add(fifteenFactoriesUpgrade);
            allUpgrades.Add(twentyFiveFactoriesUpgrade);
            allUpgrades.Add(fiftyFactoriesUpgrade);
            allUpgrades.Add(seventyFiveFactoriesUpgrade);
            allUpgrades.Add(oneHundredFactoriesUpgrade);
            allUpgrades.Add(oneHundredFiftyFactoriesUpgrade);
        }
Ejemplo n.º 2
0
    //finds and returns the closest enemy building
    public Building ClosestEnemyBuilding()
    {
        int      xDis = 0, yDis = 0;
        double   distance = 1000;
        double   temp     = 1000;
        Building target   = null;


        foreach (Building u in buildings)
        {
            if (u is FactoryBuilding)
            {
                FactoryBuilding b = (FactoryBuilding)u;

                if (FactionType != b.FactionType)
                {
                    xDis = Mathf.Abs((PosX - b.PosX) * (PosX - b.PosX));
                    yDis = Mathf.Abs((PosY - b.PosY) * (PosY - b.PosY));

                    distance = Mathf.Round(Mathf.Sqrt(xDis + yDis));
                }
            }
            else if (u is ResourceBuilding)
            {
                ResourceBuilding b = (ResourceBuilding)u;

                if (FactionType != b.FactionType)
                {
                    xDis = Mathf.Abs((PosX - b.PosX) * (PosX - b.PosX));
                    yDis = Mathf.Abs((PosY - b.PosY) * (PosY - b.PosY));

                    distance = Mathf.Round(Mathf.Sqrt(xDis + yDis));
                }
            }


            if (distance < temp)
            {
                temp   = distance;
                target = u;
            }
        }

        return(target);
    }
Ejemplo n.º 3
0
    //this method adds buildings to the map
    public void BuildPlacing()
    {
        int i = 0;
        int Team;

        string placeTeam   = "";
        string placeSymbol = "";

        //assigned factory buildings to the first to teams
        fact[i] = new FactoryBuilding(1, 1, "Rogue Team", "p");
        mapArray[fact[i].YPosition, fact[i].XPosition] = fact[i].Symbol;
        i++;
        fact[i] = new FactoryBuilding(19, 19, "Rogue team", "p");
        mapArray[fact[i].YPosition, fact[i].XPosition] = fact[i].Symbol;

        //resource buiidings assigned to secong two teams
        for (int g = 2; g < res.Length; g++)
        {
            Team = r.Next(1, 3);
            int x = r.Next(0, 20);
            int y = r.Next(0, 20);

            switch (Team)
            {
            case 1:
                placeTeam   = "Viking team";
                placeSymbol = "V";
                break;

            case 2:
                placeTeam   = "Viking team";
                placeSymbol = "v";
                break;
            }

            res[g] = new ResourceBuilding(x, y, placeTeam, placeSymbol);
            mapArray[res[g].YPosition, res[g].XPosition] = res[g].Symbol;
        }
    }
Ejemplo n.º 4
0
    public void BuildingSpawner()
    {
        int j = 0;
        int factionAllocte;

        string faction = "";
        string symbol  = "";

        buildings[j] = new FactoryBuilding(1, 1, "Q", "Hammerhead");
        GameMap[buildings[j].YPos, buildings[j].XPos] = buildings[j].Symbol;
        j++;
        buildings[j] = new FactoryBuilding(18, 18, "q", "Raggertooth");
        GameMap[buildings[j].YPos, buildings[j].XPos] = buildings[j].Symbol;

        for (int l = 2; l < buildings.Length; l++)      //gen of resource buildings
        {
            factionAllocte = rand.Next(1, 3);
            int x = rand.Next(1, 20);
            int y = rand.Next(1, 20);

            switch (factionAllocte)
            {
            case 1:
                faction = "Hammerhead";
                symbol  = "D";
                break;

            case 2:
                faction = "Raggertooth";
                symbol  = "d";
                break;
            }

            buildings[l] = new ResourceBuilding(x, y, faction, symbol);
            GameMap[buildings[l].YPos, buildings[l].XPos] = buildings[l].Symbol;    //populating the building in the array
        }
    }
Ejemplo n.º 5
0
    //Displays the units onto the form
    public void Display()
    {
        for (int k = 0; k < 20; k++)
        {
            for (int l = 0; l < 20; l++)
            {
                Instantiate(floor, new Vector3(k, 0, l), Quaternion.identity);
            }
        }
        //Clears map
        GameObject[] tiles = GameObject.FindGameObjectsWithTag("floor");

        foreach (GameObject u in tiles)
        {
            GameObject.Destroy(u);
        }

        //Adding Units
        foreach (Unit u in map.units)
        {
            GameObject gb = new GameObject();
            if (u is MeleeUnit)
            {
                MeleeUnit mu = (MeleeUnit)u;
                if (mu.FactionType == 0)
                {
                    GameObject GO = Instantiate(redMelee, new Vector3(mu.PosX, 0, mu.PosY), Quaternion.identity);
                    unitCo = GO.GetComponent <UnitController>();

                    unitCo.DisplayHealth(mu.Health);
                }
                else
                {
                    GameObject GO = Instantiate(blueMelee, new Vector3(mu.PosX, 0, mu.PosY), Quaternion.identity);
                    unitCo = GO.GetComponent <UnitController>();

                    unitCo.DisplayHealth(mu.Health);
                }
            }
            else if (u is RangedUnit)
            {
                RangedUnit ru = (RangedUnit)u;
                if (ru.FactionType == 0)
                {
                    GameObject GO = Instantiate(redRanged, new Vector3(ru.PosX, 0, ru.PosY), Quaternion.identity);
                    unitCo = GO.GetComponent <UnitController>();

                    unitCo.DisplayHealth(ru.Health);
                }
                else
                {
                    GameObject GO = Instantiate(blueRanged, new Vector3(ru.PosX, 0, ru.PosY), Quaternion.identity);
                    unitCo = GO.GetComponent <UnitController>();

                    unitCo.DisplayHealth(ru.Health);
                }
            }
            else
            {
                WizardUnit wu = (WizardUnit)u;
                GameObject GO = Instantiate(wizard, new Vector3(wu.PosX, 0, wu.PosY), Quaternion.identity);
                unitCo = GO.GetComponent <UnitController>();

                unitCo.DisplayHealth(wu.Health);
            }
        }

        //Adding Buildings
        foreach (Building bud in map.buildings)
        {
            GameObject gb = new GameObject();

            if (bud is ResourceBuilding)
            {
                ResourceBuilding rb = (ResourceBuilding)bud;

                if (rb.FactionType == 0)
                {
                    GameObject GO = Instantiate(redResourceFactory, new Vector3(rb.PosX, 0, rb.PosY), Quaternion.identity);
                    unitCo = GO.GetComponent <UnitController>();

                    unitCo.DisplayHealth(rb.Health);
                }
                else
                {
                    GameObject GO = Instantiate(blueResourceFactory, new Vector3(rb.PosX, 0, rb.PosY), Quaternion.identity);
                    unitCo = GO.GetComponent <UnitController>();

                    unitCo.DisplayHealth(rb.Health);
                }
            }
            else
            {
                FactoryBuilding fb = (FactoryBuilding)bud;

                if (fb.FactionType == 0)
                {
                    GameObject GO = Instantiate(redUnitFactory, new Vector3(fb.PosX, 0, fb.PosY), Quaternion.identity);
                    unitCo = GO.GetComponent <UnitController>();

                    unitCo.DisplayHealth(fb.Health);
                }
                else
                {
                    GameObject GO = Instantiate(blueUnitFactory, new Vector3(fb.PosX, 0, fb.PosY), Quaternion.identity);
                    unitCo = GO.GetComponent <UnitController>();

                    unitCo.DisplayHealth(fb.Health);
                }
            }
        }
    }
Ejemplo n.º 6
0
    private void DisplayMap()
    {
        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(MeeleeUnit))
            {
                MeeleeUnit m = (MeeleeUnit)u;

                if (m.faction == 1)
                {
                    GameObject clone = Instantiate(blueMeelee, new Vector2(m.PosX, m.PosY), Quaternion.identity);
                    clone.transform.parent = transform;
                }
                else if (m.faction == 0)
                {
                    GameObject clone = Instantiate(redMeelee, new Vector2(m.PosX, m.PosY), Quaternion.identity);
                    clone.transform.parent = transform;
                }
                else
                {
                    GameObject clone = Instantiate(ground, new Vector2(m.PosX, m.PosY), Quaternion.identity);
                    clone.transform.parent = transform;
                }
                if (m.isDead())
                {
                    GameObject clone = Instantiate(body, new Vector2(m.PosX, m.PosY), Quaternion.identity);
                    clone.transform.parent = transform;
                }
            }
        }
        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(RangedUnit))
            {
                RangedUnit m = (RangedUnit)u;

                if (m.faction == 1)
                {
                    GameObject clone = Instantiate(redRanged, new Vector2(m.PosX, m.PosY), Quaternion.identity);
                    clone.transform.parent = transform;
                }
                else if (m.faction == 0)
                {
                    GameObject clone = Instantiate(blueRanged, new Vector2(m.PosX, m.PosY), Quaternion.identity);
                    clone.transform.parent = transform;
                }
                else
                {
                    GameObject clone = Instantiate(ground, new Vector2(m.PosX, m.PosY), Quaternion.identity);
                    clone.transform.parent = transform;
                }
                if (m.isDead())
                {
                    GameObject clone = Instantiate(body, new Vector2(m.PosX, m.PosY), Quaternion.identity);
                    clone.transform.parent = transform;
                }
            }
        }

        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(WarlockUnit))
            {
                WarlockUnit w = (WarlockUnit)u;

                if (w.faction == 1)
                {
                    GameObject clone = Instantiate(redWarlock, new Vector2(m.PosX, m.PosY), Quaternion.identity);
                    clone.transform.parent = transform;
                }
                else
                {
                    GameObject clone = Instantiate(blueWarlock, new Vector2(m.PosX, m.PosY), Quaternion.identity);
                    clone.transform.parent = transform;
                }
                if (w.isDead())
                {
                    GameObject clone = Instantiate(body, new Vector2(m.PosX, m.PosY), Quaternion.identity);
                    clone.transform.parent = transform;
                }
            }
        }

        foreach (Building b in map.Buildings)
        {
            if (b.GetType() == typeof(FactoryBuilding))
            {
                FactoryBuilding m = (FactoryBuilding)b;

                if (m.faction == 1)
                {
                    GameObject clone = Instantiate(redFactory, new Vector2(m.PosX, m.PosY), Quaternion.identity);
                    clone.transform.parent = transform;
                }
                else
                {
                    GameObject clone = Instantiate(blueFactory, new Vector2(m.PosX, m.PosY), Quaternion.identity);
                    clone.transform.parent = transform;
                }
                if (m.isDead())
                {
                    GameObject clone = Instantiate(body, new Vector2(m.PosX, m.PosY), Quaternion.identity);
                    clone.transform.parent = transform;
                }
            }
        }

        foreach (Building b in map.Buildings)
        {
            if (b.GetType() == typeof(ResourceBuilding))
            {
                ResourceBuilding m = (ResourceBuilding)b;

                if (m.faction == 1)
                {
                    GameObject clone = Instantiate(redBuilding, new Vector2(m.PosX, m.PosY), Quaternion.identity);
                    clone.transform.parent = transform;
                }
                else
                {
                    GameObject clone = Instantiate(blueBuilding, new Vector2(m.PosX, m.PosY), Quaternion.identity);
                    clone.transform.parent = transform;
                }
                if (m.isDead())
                {
                    GameObject clone = Instantiate(body, new Vector2(m.PosX, m.PosY), Quaternion.identity);
                    clone.transform.parent = transform;
                }
            }
        }
    }
Ejemplo n.º 7
0
    private void UpdateMap()
    {
        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(MeeleeUnit))
            {
                MeeleeUnit m = (MeeleeUnit)u;
                if (m.health > 1)
                {
                    if (m.health < 25)
                    {
                        switch (r.Next(0, 4))
                        {
                        case 0: ((MeeleeUnit)u).NewPos(Direction.North); break;

                        case 1: ((MeeleeUnit)u).NewPos(Direction.East); break;

                        case 2: ((MeeleeUnit)u).NewPos(Direction.South); break;

                        case 3: ((MeeleeUnit)u).NewPos(Direction.West); break;
                        }
                    }
                    else if (m.health < 10)
                    {
                        int teamChange = r.Next(0, 2);
                        if (teamChange == 0)
                        {
                            if (m.faction == 1)
                            {
                                m.faction = 0;
                                m.health  = m.health + 5;
                            }
                            else
                            {
                                m.faction = 1;
                                m.health  = m.health + 5;
                            }
                        }
                    }
                    else
                    {
                        bool inCombat = false;
                        foreach (Unit e in map.Units)
                        {
                            if (u.withinRange(e))
                            {
                                u.combat(e);
                                inCombat = true;
                            }
                        }
                        if (!inCombat)
                        {
                            Unit c = u.distance(map.Units);
                            m.NewPos(m.Directionto(c));
                        }
                    }
                }
                else
                {
                    m.symbol = body;
                }
            }
        }
        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(RangedUnit))
            {
                RangedUnit m = (RangedUnit)u;
                if (m.health > 1)
                {
                    if (m.health < 25)
                    {
                        switch (r.Next(0, 4))
                        {
                        case 0: ((RangedUnit)u).NewPos(Direction.North); break;

                        case 1: ((RangedUnit)u).NewPos(Direction.East); break;

                        case 2: ((RangedUnit)u).NewPos(Direction.South); break;

                        case 3: ((RangedUnit)u).NewPos(Direction.West); break;
                        }
                    }
                    else if (m.health < 10)
                    {
                        int teamChange = r.Next(0, 2);
                        if (teamChange == 0)
                        {
                            if (m.faction == 1)
                            {
                                m.faction = 0;
                                m.health  = m.health + 5;
                            }
                            else
                            {
                                m.faction = 1;
                                m.health  = m.health + 5;
                            }
                        }
                    }
                    else
                    {
                        bool inCombat = false;
                        foreach (Unit e in map.Units)
                        {
                            if (u.withinRange(e))
                            {
                                u.combat(e);
                                inCombat = true;
                            }
                        }
                        if (!inCombat)
                        {
                            Unit c = u.distance(map.Units);
                            m.NewPos(m.Directionto(c));
                        }
                    }
                }
                else
                {
                    m.symbol = body;
                }
            }
        }

        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(WarlockUnit))
            {
                WarlockUnit w = (WarlockUnit)u;
                if (w.health > 1)
                {
                    if (w.health < 25)
                    {
                        switch (r.Next(0, 4))
                        {
                        case 0: ((WarlockUnit)u).NewPos(Direction.North); break;

                        case 1: ((WarlockUnit)u).NewPos(Direction.East); break;

                        case 2: ((WarlockUnit)u).NewPos(Direction.South); break;

                        case 3: ((WarlockUnit)u).NewPos(Direction.West); break;
                        }
                    }

                    else
                    {
                        bool inCombat = false;
                        foreach (Unit e in map.Units)
                        {
                            if (u.withinRange(e))
                            {
                                u.combat(e);
                                inCombat = true;
                            }
                        }
                        if (!inCombat)
                        {
                            Unit c = u.distance(map.Units);
                            w.NewPos(w.Directionto(c));
                        }
                    }
                }
                else
                {
                    w.symbol = body;
                }
            }
        }

        foreach (Building b in map.Buildings)
        {
            if (b.GetType() == typeof(ResourceBuilding))
            {
                ResourceBuilding rb = (ResourceBuilding)b;
                rb.ResourceGenerate();
            }
        }

        foreach (Building b in map.Buildings)
        {
            if (b.GetType() == typeof(FactoryBuilding))
            {
                FactoryBuilding fb = (FactoryBuilding)b;
            }
        }

        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(MeeleeUnit))
            {
                MeeleeUnit mu = (MeeleeUnit)u;
                if (mu.symbol == body)
                {
                    int             faction = mu.faction;
                    int             rand    = r.Next(0, 5);
                    FactoryBuilding fb      = (FactoryBuilding)map.Buildings[rand];
                    fb.Spawner(20, 20, faction);
                }
            }
        }

        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(RangedUnit))
            {
                RangedUnit mu = (RangedUnit)u;
                if (mu.symbol == body)
                {
                    int             faction = mu.faction;
                    int             rand    = r.Next(0, 5);
                    FactoryBuilding fb      = (FactoryBuilding)map.Buildings[rand];
                    fb.Spawner(20, 20, faction);
                }
            }
        }
    }
Ejemplo n.º 8
0
Archivo: Map.cs Proyecto: AJMuller/POE
    public Map(int maxX, int maxY, int numUnits, int numBuildings)
    {
        units = new Unit[numUnits];
        int count = 0;

        for (int i = 0; i < numUnits / 5; i++)     // creates
        {
            Melee_Unit m = new Melee_Unit("knight", r.Next(0, maxX),
                                          r.Next(0, maxY),
                                          100,
                                          r.Next(5, 10),
                                          1,
                                          1,
                                          i % 2,
                                          "M");
            units[count] = m;
            count++;

            Ranged_Unit ranged = new Ranged_Unit("knight", r.Next(0, maxX),
                                                 r.Next(0, maxY),
                                                 100,
                                                 r.Next(5, 10),
                                                 1,
                                                 1,
                                                 i % 2,
                                                 "R");
            units[count] = ranged;
            count++;

            Tank t = new Tank("Cruiser", r.Next(0, maxX),
                              r.Next(0, maxY),
                              100,
                              r.Next(10, 20),
                              1,
                              1,
                              i % 2,
                              "T");
            units[count] = t;
            count++;

            Helicopter h = new Helicopter("Boeing", r.Next(0, maxX),
                                          r.Next(0, maxY),
                                          100,
                                          r.Next(10, 20),
                                          1,
                                          1,
                                          i % 2,
                                          "H");
            units[count] = h;
            count++;

            Fighter_Jets f = new Fighter_Jets("Boeing", r.Next(0, maxX),
                                              r.Next(0, maxY),
                                              100,
                                              r.Next(10, 20),
                                              1,
                                              1,
                                              i % 2,
                                              "J");
            units[count] = f;
            count++;
        }    //end for

        count     = 0;
        buildings = new Building[numBuildings];
        for (int i = 0; i < numBuildings / 4; i++)
        {
            FactoryBuilding fb = new FactoryBuilding
                                     (100, r.Next(0, maxX), r.Next(0, maxY), i % 2, "F");

            buildings[count] = fb;
            count++;

            ResourceBuilding rb = new ResourceBuilding
                                      (100, r.Next(0, maxX), r.Next(0, maxY), i % 2, "S");

            buildings[count] = rb;
            count++;

            Field_Hospital fh = new Field_Hospital
                                    (100, r.Next(0, maxX), r.Next(0, maxY), i % 2, "+");

            buildings[count] = fh;
            count++;

            Weapon_Upgrade wu = new Weapon_Upgrade
                                    (100, r.Next(0, maxX), r.Next(0, maxY), i % 2, "^^");

            buildings[count] = wu;
            count++;
        } //end for
    }     //makes objects and generates values for these objects
Ejemplo n.º 9
0
    void InitiatUnit()
    {
        for (int i = 0; i < 10; i++)
        {
            int factionRnd = UnityEngine.Random.Range(1, 3);//random for both factions betteween 1 and 2
            int rndX       = UnityEngine.Random.Range(0, 20);
            int rndY       = UnityEngine.Random.Range(0, 20);
            if (factionRnd == 1)
            {
                int typeRnd = UnityEngine.Random.Range(1, 3); //random for class type
                if (typeRnd == 1)
                {
                    int classRnd = UnityEngine.Random.Range(1, 3);
                    if (classRnd == 1)
                    {
                        units[i]       = new RangeUnit(10, 10, 1, 2, 2, rndX, rndY, faction: "Hero", unitType: "Sniper", symbol: 'R');
                        units[i].MaxHp = 10;
                    }
                    else
                    {
                        units[i]       = new RangeUnit(10, 10, 1, 2, 2, rndX, rndY, faction: "Hero", unitType: "Archer", symbol: 'R');
                        units[i].MaxHp = 10;
                    }
                }
                else
                {
                    int classRnd = UnityEngine.Random.Range(1, 3);
                    if (classRnd == 1)
                    {
                        units[i]       = new MeeleUnit(20, 20, 2, 1, 1, rndX, rndY, faction: "Hero", unitType: "Tank", symbol: 'M');
                        units[i].MaxHp = 20;
                    }
                    else
                    {
                        units[i]       = new MeeleUnit(20, 20, 2, 1, 1, rndX, rndY, faction: "Hero", unitType: "Slayer", symbol: 'M');
                        units[i].MaxHp = 20;
                    }
                }
            }
            else
            {
                int typeRnd = UnityEngine.Random.Range(1, 3); //random for class type
                if (typeRnd == 1)
                {
                    int classRnd = UnityEngine.Random.Range(1, 3);
                    if (classRnd == 1)
                    {
                        units[i]       = new RangeUnit(10, 10, 1, 2, 2, rndX, rndY, faction: "Enemy", unitType: "Sniper", symbol: 'T');
                        units[i].MaxHp = 10;
                    }
                    else
                    {
                        units[i]       = new RangeUnit(10, 10, 1, 2, 2, rndX, rndY, faction: "Enemy", unitType: "Archer", symbol: 'T');
                        units[i].MaxHp = 10;
                    }
                }
                else
                {
                    int classRnd = UnityEngine.Random.Range(1, 3);
                    if (classRnd == 1)
                    {
                        units[i]       = new MeeleUnit(20, 20, 2, 1, 1, rndX, rndY, faction: "Enemy", unitType: "Tank", symbol: 'W');
                        units[i].MaxHp = 20;
                    }
                    else
                    {
                        units[i]       = new MeeleUnit(20, 20, 2, 1, 1, rndX, rndY, faction: "Enemy", unitType: "Slayer", symbol: 'W');
                        units[i].MaxHp = 20;
                    }
                }
            }
        }

        int xRnd = UnityEngine.Random.Range(0, 19);

        int yRnd = UnityEngine.Random.Range(0, 19);

        buildings[0]       = new ResourceBuilding(40, xRnd, yRnd, "Hero", 'Y');
        buildings[0].YPos  = yRnd;
        buildings[0].MaxHp = 40;


        xRnd = UnityEngine.Random.Range(0, 20);
        yRnd = UnityEngine.Random.Range(0, 20);

        buildings[1]       = new ResourceBuilding(40, xRnd, yRnd, "Enemy", 'A');
        buildings[1].YPos  = yRnd;
        buildings[1].MaxHp = 40;


        xRnd = UnityEngine.Random.Range(0, 20);

        yRnd = UnityEngine.Random.Range(0, 20);

        buildings[2]       = new FactoryBuilding(40, xRnd, yRnd, "Hero", 'X');
        buildings[2].YPos  = yRnd;
        buildings[2].MaxHp = 40;
        int rndSpn = UnityEngine.Random.Range(1, 3);

        // if (rndSpn == 1)
        //   {
        //      fBuildings[0].UnitSpn = "Meele";
        //       fBuildings[0].SpnTic = 5;
        //       fBuildings[0].SpnPtCalc();
        //    }
        //   else
        //   {
        //       fBuildings[0].UnitSpn = "Range";
        //       fBuildings[0].SpnTic = 5;
        //       fBuildings[0].SpnPtCalc();
        //   }

        xRnd = UnityEngine.Random.Range(0, 20);

        yRnd = UnityEngine.Random.Range(0, 20);

        buildings[3]       = new FactoryBuilding(40, xRnd, yRnd, "Enemy", 'B');
        buildings[3].YPos  = yRnd;
        buildings[3].MaxHp = 40;
        rndSpn             = UnityEngine.Random.Range(1, 3);
        //   if (rndSpn == 1)
        //   {
        //       fBuildings[1].UnitSpn = "Meele";
        //       fBuildings[1].SpnTic = 5;
        //        fBuildings[1].SpnPtCalc();
        //   }
        //   else
        //   {
        //       fBuildings[1].UnitSpn = "Range";
        //      fBuildings[1].SpnTic = 5;
        //      fBuildings[1].SpnPtCalc();
        //  }
    }
Ejemplo n.º 10
0
    public void SaveAll()
    {
        StreamWriter rstrm = File.CreateText("RangedUnit.txt");

        rstrm.Flush();
        rstrm.Close();
        StreamWriter mstrm = File.CreateText("MeleeUnit.txt");

        mstrm.Flush();
        mstrm.Close();
        StreamWriter ttrm = File.CreateText("Tank.txt");

        ttrm.Flush();
        ttrm.Close();
        StreamWriter htrm = File.CreateText("Helicopter.txt");

        htrm.Flush();
        htrm.Close();
        StreamWriter fjrm = File.CreateText("Fighter_Jets.txt");

        fjrm.Flush();
        fjrm.Close();
        StreamWriter fbstrm = File.CreateText("FactoryBuilding.txt");

        fbstrm.Flush();
        fbstrm.Close();
        StreamWriter rbstrm = File.CreateText("ResourceBuilding.txt");

        rbstrm.Flush();
        rbstrm.Close();
        StreamWriter fhstrm = File.CreateText("Field_Hospital.txt");

        fhstrm.Flush();
        fhstrm.Close();
        StreamWriter wustrm = File.CreateText("Weapon_Upgrade.txt");

        wustrm.Flush();
        wustrm.Close();

        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(Melee_Unit))
            {
                Melee_Unit m = (Melee_Unit)u;

                m.Save();
            }//end if
            else if (u.GetType() == typeof(Ranged_Unit))
            {
                Ranged_Unit m = (Ranged_Unit)u;

                m.Save();
            }//end else
            else if (u.GetType() == typeof(Tank))
            {
                Tank m = (Tank)u;

                m.Save();
            }//end else
            else if (u.GetType() == typeof(Helicopter))
            {
                Helicopter m = (Helicopter)u;

                m.Save();
            }//end else
            else if (u.GetType() == typeof(Fighter_Jets))
            {
                Fighter_Jets m = (Fighter_Jets)u;

                m.Save();
            } //end else
        }     //end foreach
        foreach (Building b in map.Buildings)
        {
            if (b.GetType() == typeof(FactoryBuilding))
            {
                FactoryBuilding f = (FactoryBuilding)b;

                f.Save();
            }//end if
            else if (b.GetType() == typeof(ResourceBuilding))
            {
                ResourceBuilding r = (ResourceBuilding)b;

                r.Save();
            }//end else
            else if (b.GetType() == typeof(Field_Hospital))
            {
                Field_Hospital r = (Field_Hospital)b;

                r.Save();
            }//end else
            else if (b.GetType() == typeof(Weapon_Upgrade))
            {
                Weapon_Upgrade r = (Weapon_Upgrade)b;

                r.Save();
            } //end else
        }     //end foreach
    }
Ejemplo n.º 11
0
    }             // creates new buttons for every unit and building saved in the arrays. each button is made to match the type of unit or building it is by changing colours and letters displayed on it.

    private void UpdateMap()
    {
        int distancebuild;

        foreach (Building b in map.Buildings)
        {
            if (b.GetType() == typeof(ResourceBuilding))
            {
                ResourceBuilding rb = (ResourceBuilding)b;
                foreach (Unit e in map.Units)
                {
                    if (e.GetType() == typeof(Melee_Unit))
                    {
                        Melee_Unit m = (Melee_Unit)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Ranged_Unit))
                    {
                        Ranged_Unit m = (Ranged_Unit)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Fighter_Jets))
                    {
                        Fighter_Jets m = (Fighter_Jets)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Helicopter))
                    {
                        Helicopter m = (Helicopter)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Tank))
                    {
                        Tank m = (Tank)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                }
            }
            else if (b.GetType() == typeof(FactoryBuilding))
            {
                FactoryBuilding rb = (FactoryBuilding)b;
                foreach (Unit e in map.Units)
                {
                    if (e.GetType() == typeof(Melee_Unit))
                    {
                        Melee_Unit m = (Melee_Unit)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Ranged_Unit))
                    {
                        Ranged_Unit m = (Ranged_Unit)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Fighter_Jets))
                    {
                        Fighter_Jets m = (Fighter_Jets)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Helicopter))
                    {
                        Helicopter m = (Helicopter)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Tank))
                    {
                        Tank m = (Tank)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                }
            }
            if (b.GetType() == typeof(Field_Hospital))
            {
                Field_Hospital rb = (Field_Hospital)b;
                foreach (Unit e in map.Units)
                {
                    if (e.GetType() == typeof(Melee_Unit))
                    {
                        Melee_Unit m = (Melee_Unit)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Ranged_Unit))
                    {
                        Ranged_Unit m = (Ranged_Unit)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Fighter_Jets))
                    {
                        Fighter_Jets m = (Fighter_Jets)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Helicopter))
                    {
                        Helicopter m = (Helicopter)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Tank))
                    {
                        Tank m = (Tank)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                }
            }
            if (b.GetType() == typeof(Weapon_Upgrade))
            {
                Weapon_Upgrade rb = (Weapon_Upgrade)b;
                foreach (Unit e in map.Units)
                {
                    if (e.GetType() == typeof(Melee_Unit))
                    {
                        Melee_Unit m = (Melee_Unit)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Ranged_Unit))
                    {
                        Ranged_Unit m = (Ranged_Unit)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Fighter_Jets))
                    {
                        Fighter_Jets m = (Fighter_Jets)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Helicopter))
                    {
                        Helicopter m = (Helicopter)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Tank))
                    {
                        Tank m = (Tank)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                }
            }
        }

        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(Melee_Unit))
            {
                Melee_Unit m = (Melee_Unit)u;

                if (m.Health < 25)
                {
                    switch (r.Next(0, 4))
                    {
                    case 0: m.MovePos(Direction.North); break;

                    case 1: m.MovePos(Direction.East); break;

                    case 2: m.MovePos(Direction.South); break;

                    case 3: m.MovePos(Direction.West); break;
                    } //end switch
                }     //end if
                else
                {
                    bool inCombat = false;
                    foreach (Unit e in map.Units)
                    {
                        if (m.WithinRange(e))
                        {
                            m.Fight(e);
                            inCombat = true;
                        } //end if
                    }     //end foreach
                    if (!inCombat)
                    {
                        Unit c = m.NearestUnit(map.Units);
                        m.MovePos(m.DirectionTo(c));
                    } //end if
                }     //end else
            }         //end if
            else if (u.GetType() == typeof(Ranged_Unit))
            {
                Ranged_Unit m = (Ranged_Unit)u;
                if (m.IsDeath())
                {
                    m.Symbol = "D";
                }//end if
                if (m.Health < 25)
                {
                    switch (r.Next(0, 4))
                    {
                    case 0: m.MovePos(Direction.North); break;

                    case 1: m.MovePos(Direction.East); break;

                    case 2: m.MovePos(Direction.South); break;

                    case 3: m.MovePos(Direction.West); break;
                    } //end switch
                }     //end if
                else
                {
                    bool inCombat = false;
                    foreach (Unit e in map.Units)
                    {
                        if (m.WithinRange(e))
                        {
                            m.Fight(e);
                            inCombat = true;
                        } //end if
                    }     //end foreach
                    if (!inCombat)
                    {
                        Unit c = m.NearestUnit(map.Units);
                        m.MovePos(m.DirectionTo(c));
                    } //end if
                }     //end else
            }         //end else if
            else if (u.GetType() == typeof(Tank))
            {
                Tank m = (Tank)u;
                if (m.IsDeath())
                {
                    m.Symbol = "D";
                }//end if
                if (m.Health < 25)
                {
                    switch (r.Next(0, 4))
                    {
                    case 0: m.MovePos(Direction.North); break;

                    case 1: m.MovePos(Direction.East); break;

                    case 2: m.MovePos(Direction.South); break;

                    case 3: m.MovePos(Direction.West); break;
                    } //end switch
                }     //end if
                else
                {
                    bool inCombat = false;
                    foreach (Unit e in map.Units)
                    {
                        if (m.WithinRange(e))
                        {
                            m.Fight(e);
                            inCombat = true;
                        } //end if
                    }     //end foreach
                    if (!inCombat)
                    {
                        Unit c = m.NearestUnit(map.Units);
                        m.MovePos(m.DirectionTo(c));
                    } //end if
                }     //end else
            }         //end else if
            else if (u.GetType() == typeof(Fighter_Jets))
            {
                Fighter_Jets m = (Fighter_Jets)u;
                if (m.IsDeath())
                {
                    m.Symbol = "D";
                }//end if
                if (m.Health < 25)
                {
                    switch (r.Next(0, 4))
                    {
                    case 0: m.MovePos(Direction.North); break;

                    case 1: m.MovePos(Direction.East); break;

                    case 2: m.MovePos(Direction.South); break;

                    case 3: m.MovePos(Direction.West); break;
                    } //end switch
                }     //end if
                else
                {
                    bool inCombat = false;
                    foreach (Unit e in map.Units)
                    {
                        if (m.WithinRange(e))
                        {
                            m.Fight(e);
                            inCombat = true;
                        } //end if
                    }     //end foreach
                    if (!inCombat)
                    {
                        Unit c = m.NearestUnit(map.Units);
                        m.MovePos(m.DirectionTo(c));
                    } //end if
                }     //end else
            }         //end else if
            else if (u.GetType() == typeof(Helicopter))
            {
                Helicopter m = (Helicopter)u;
                if (m.IsDeath())
                {
                    m.Symbol = "D";
                }//end if
                if (m.Health < 25)
                {
                    switch (r.Next(0, 4))
                    {
                    case 0: m.MovePos(Direction.North); break;

                    case 1: m.MovePos(Direction.East); break;

                    case 2: m.MovePos(Direction.South); break;

                    case 3: m.MovePos(Direction.West); break;
                    } //end switch
                }     //end if
                else
                {
                    bool inCombat = false;
                    foreach (Unit e in map.Units)
                    {
                        if (m.WithinRange(e))
                        {
                            m.Fight(e);
                            inCombat = true;
                        } //end if
                    }     //end foreach
                    if (!inCombat)
                    {
                        Unit c = m.NearestUnit(map.Units);
                        m.MovePos(m.DirectionTo(c));
                    } //end if
                }     //end else
            }         //end else if
        }             //end foreach
    }                 // updates the map by chaging values of units. calls movement methods and fight methods to change values in order for the map to change.
Ejemplo n.º 12
0
Archivo: Map.cs Proyecto: LegendDRD/POE
    public Map(int maxX, int maxY, int numUnits, int numbuilding)
    {
        building = new Building[numbuilding];
        rb       = new ResourceBuilding[numbuilding];
        unit     = new Unit[numUnits];
        for (int i = 0; i < numUnits; i++)
        {
            if (i <= 10)
            {
                MeleeUnit M = new MeleeUnit(r.Next(0, maxX), r.Next(0, maxY), r.Next(60, 100) * 10, r.Next(5, 20), 1, 1, i % 2, "=", "Knight");
                Unit[i] = M;
            }


            if (i > 10 && i < 20)
            {
                RangedUnits R = new RangedUnits(r.Next(0, maxX), r.Next(0, maxY), r.Next(10, 20) * 10, r.Next(5, 20), 1, 1, i % 2, "}", "Archer");
                Unit[i] = R;
            }

            if (i >= 20 && i < 22)
            {
                Emperor E = new Emperor(r.Next(0, maxX), r.Next(0, maxY), r.Next(10, 20) * 10, r.Next(5, 20), 1, 1, i % 2, "#", "Emperor");
                unit[i] = E;
            }
            if (i >= 22 && i < 27)
            {
                RangedUnits E = new RangedUnits(r.Next(0, maxX), r.Next(0, maxY), r.Next(10, 20) * 10, r.Next(5, 20), 1, 1, i % 2, "->", "Muksmen");
                unit[i] = E;
            }
            if (i > 26)
            {
                MeleeUnit Lance = new MeleeUnit(r.Next(0, maxX), r.Next(0, maxY), r.Next(10, 20) * 10, r.Next(5, 20), 1, 1, i % 2, ">", "Lance");
                unit[i] = Lance;
            }
        }
        for (int i = 0; i < numbuilding; i++)
        {
            if (i <= 5)
            {
                FactoryBuilding fb = new FactoryBuilding(r.Next(-14, 20), r.Next(-22, maxY), r.Next(5, 20), 1, "F", r.Next(0, 1), r.Next(5, 10), buildingx);
                building[i] = fb;
            }


            if (i > 5)
            {
                FactoryBuilding fbr = new FactoryBuilding(r.Next(50, maxX), r.Next(-22, maxY), r.Next(5, 20), 0, "F", r.Next(0, 1), r.Next(5, 10), buildingx);
                building[i] = fbr;
            }
        }
        for (int i = 0; i < numbuilding; i++)
        {
            if (i <= 5)
            {
                ResourceBuilding fb = new ResourceBuilding(r.Next(-14, 20), r.Next(-22, maxY), r.Next(5, 20), 1, "RB", r.Next(0, 1), r.Next(5, 10), 400);
                rb[i] = fb;
            }


            if (i > 5)
            {
                ResourceBuilding fbr = new ResourceBuilding(r.Next(50, 80), r.Next(-22, maxY), r.Next(5, 20), 0, "RB", r.Next(0, 1), r.Next(5, 10), 400);
                rb[i] = fbr;
            }
        }
    }
Ejemplo n.º 13
0
    private void Update()
    {
        // If the game is not paused
        if (!isPaused)
        {
            // Increases amount of money based on how much time have passed since the last update and number of houses
            moneyAmount += Time.deltaTime * Time.timeScale * numHouses * houseMoneyRate;

            // Checks if primary mouse button is down
            if (Input.GetMouseButtonDown(0))
            {
                RaycastHit hitInfo = new RaycastHit();

                // Factory
                if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo) && hitInfo.transform.tag == "Factory")
                {
                    if (currentlySelectedFactory != null)                                           // Checks if a building is already selected
                    {
                        currentlySelectedFactory.ActivateGUI(false);                                // Disables menu of previously selected game object
                    }
                    currentlySelectedFactory = hitInfo.transform.GetComponent <FactoryBuilding>();  // Sets newly selected game object

                    // Makes sure it only trggers if FactoryBuilding were found
                    if (currentlySelectedFactory != null)
                    {
                        factorySelected = true;                                                     // Updates if factory is enabled
                        currentlySelectedFactory.ActivateGUI(true);                                 // Activates GUI of game object

                        // Sets arrow position above currently selected building
                        arrow.transform.position = new Vector3(currentlySelectedFactory.transform.position.x, currentlySelectedFactory.transform.position.y + 45, currentlySelectedFactory.transform.position.z);
                        arrow.enabled            = true;
                    }
                }
                else if (currentlySelectedFactory != null && !isInGUI && !UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())                              // Checks if there is a factory there and that you are outside of any relevant GUI element
                {
                    factorySelected = false;
                    arrow.enabled   = false;
                    currentlySelectedFactory.ActivateGUI(false);                                    // Disables menu of previously selected game object
                }
                else
                {
                    factorySelected = false;
                }
            }
        }

        if (factorySelected) // checks if the user is in a relevant GUI(Factory)
        {
            Debug.Log(currentlySelectedFactory.transform.position.y);

            // Make the arrow always face the player while active
            arrow.transform.LookAt(new Vector3(Camera.main.transform.position.x, currentlySelectedFactory.transform.position.y + 45, Camera.main.transform.position.z));
        }

        if (Time.frameCount % 500 == 0 && graph != null)
        {
            uint newPop = 0;
            foreach (var node in graph.Nodes.Where(node => node.attribute == GraphNode.Attribute.Residential))
            {
                newPop += (uint)node.GetComponent <ResidentialNode>().citizens.Count;
            }
            population = newPop;
        }
    }
Ejemplo n.º 14
0
    private void OnMouseDown()
    {
        //bool Found = false;
        string information = "";

        int x = (int)this.transform.position.x;
        int y = (int)this.transform.position.y;

        foreach (Unit u in poe_rts.map.Units)
        {
            if (u.GetType() == typeof(Melee_Unit))
            {
                Melee_Unit m = (Melee_Unit)u;

                if ((m.XPos == x) && (m.YPos == y))
                {
                    //Found = true;
                    information = m.ToString();
                }
            }
            else if (u.GetType() == typeof(Ranged_Unit))
            {
                Ranged_Unit m = (Ranged_Unit)u;

                if ((m.XPos == x) && (m.YPos == y))
                {
                    //Found = true;
                    information = m.ToString();
                }
            }
            else if (u.GetType() == typeof(Fighter_Jets))
            {
                Fighter_Jets m = (Fighter_Jets)u;

                if ((m.XPos == x) && (m.YPos == y))
                {
                    //Found = true;
                    information = m.ToString();
                }
            }
            else if (u.GetType() == typeof(Tank))
            {
                Tank m = (Tank)u;

                if ((m.XPos == x) && (m.YPos == y))
                {
                    //Found = true;
                    information = m.ToString();
                }
            }
            else if (u.GetType() == typeof(Helicopter))
            {
                Helicopter m = (Helicopter)u;

                if ((m.XPos == x) && (m.YPos == y))
                {
                    //Found = true;
                    information = m.ToString();
                }
            }
        }

        foreach (Building b in poe_rts.map.Buildings)
        {
            if (b.GetType() == typeof(FactoryBuilding))
            {
                FactoryBuilding m = (FactoryBuilding)b;

                if ((m.XPos == x) && (m.YPos == y))
                {
                    information = m.ToString();
                }
            }
            else if (b.GetType() == typeof(ResourceBuilding))
            {
                ResourceBuilding m = (ResourceBuilding)b;

                if ((m.XPos == x) && (m.YPos == y))
                {
                    information = m.ToString();
                }
            }
            else if (b.GetType() == typeof(Field_Hospital))
            {
                Field_Hospital m = (Field_Hospital)b;

                if ((m.XPos == x) && (m.YPos == y))
                {
                    information = m.ToString();
                }
            }
            else if (b.GetType() == typeof(Weapon_Upgrade))
            {
                Weapon_Upgrade m = (Weapon_Upgrade)b;

                if ((m.XPos == x) && (m.YPos == y))
                {
                    information = m.ToString();
                }
            }
        }



        healthText.text = information;
    }
Ejemplo n.º 15
0
 public void Generate()
 {
     for (int x = 0; x < sizeX; x++)
     {
         for (int y = 0; y < sizeY; y++)
         {
             Object.Instantiate(Sprites[0], new Vector3(x, y, 5), Quaternion.identity);
         }
     }
     for (int i = 0; i < numUnits; i++)
     {
         int r = Random.Range(0, 2);
         if (r == 0)
         {
             MeleeUnit m = new MeleeUnit(Random.Range(0, sizeX), Random.Range(0, sizeY), "Soldier", 40, 3, 3, i % 2 == 0 ? 1 : 0, "M");
             units.Add(m);
             numM++;
         }
         else
         {
             RangedUnit ru = new RangedUnit(Random.Range(0, sizeX), Random.Range(0, sizeY), "Archer", 40, 2, 5, 5, i % 2 == 0 ? 1 : 0, "R");
             units.Add(ru);
             numR++;
         }
     }
     for (int j = 0; j < numBuilds; j++)
     {
         int r = Random.Range(0, 2);
         if (r == 0)
         {
             int f = Random.Range(0, 2);
             if (f == 0)
             {
                 FactoryBuilding fb = new FactoryBuilding(Random.Range(0, sizeX), Random.Range(0, sizeY), 0, 80, 5, j % 2 == 0 ? 1 : 0, "FB");
                 builds.Add(fb);
             }
             else
             {
                 FactoryBuilding fb = new FactoryBuilding(Random.Range(0, sizeX), Random.Range(0, sizeY), 1, 80, 5, j % 2 == 0 ? 1 : 0, "FB");
                 builds.Add(fb);
             }
         }
         else
         {
             ResourceBuilding rb = new ResourceBuilding(Random.Range(0, sizeX), Random.Range(0, sizeY), "Swords", 80, 2, 60, j % 2 == 0 ? 1 : 0);
             builds.Add(rb);
         }
     }
     if (numR < numM)
     {
         for (int k = 0; k < Random.Range(numR, numM); k++)
         {
             WizardUnit wu = new WizardUnit(Random.Range(0, sizeX), Random.Range(0, sizeY), "Wizro", 20, 1, 10, 3, "W");
             units.Add(wu);
         }
     }
     else
     {
         for (int k = 0; k < Random.Range(numM, numR); k++)
         {
             WizardUnit wu = new WizardUnit(Random.Range(0, sizeX), Random.Range(0, sizeY), "Wizro", 20, 1, 10, 3, "W");
             units.Add(wu);
         }
     }
 }
Ejemplo n.º 16
0
    public void Clickon()
    {
        Ray          ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, Mathf.Infinity);

        if (hit)
        {
            float x = hit.collider.transform.position.x;
            float y = hit.collider.transform.position.y;

            foreach (Unit u in map.Unit)
            {
                if (u.GetType() == typeof(RangedUnits))
                {
                    RangedUnits r = (RangedUnits)u;
                    if (r.Xpos == x && r.Ypos == y)
                    {
                        texts.text = r.Tostring();
                    }
                }
                else if (u.GetType() == typeof(MeleeUnit))
                {
                    MeleeUnit m = (MeleeUnit)u;
                    if (m.Xpos == x && m.Ypos == y)
                    {
                        texts.text = m.Tostring();
                    }
                }
            }
            foreach (FactoryBuilding u in map.Building)
            {
                if (u.GetType() == typeof(FactoryBuilding))
                {
                    FactoryBuilding r = (FactoryBuilding)u;
                    if (r.Xpos == x && r.Ypos == y)
                    {
                        texts.text = r.toString();
                    }
                }
                else if (u.GetType() == typeof(FactoryBuilding))
                {
                    FactoryBuilding m = (FactoryBuilding)u;
                    if (m.Xpos == x && m.Ypos == y)
                    {
                        texts.text = m.toString();
                    }
                }
            }
            foreach (ResourceBuilding u in map.RB)
            {
                if (u.GetType() == typeof(ResourceBuilding))
                {
                    ResourceBuilding r = (ResourceBuilding)u;
                    if (r.Xpos == x && r.Ypos == y)
                    {
                        texts.text = r.toString();
                    }
                }
                else if (u.GetType() == typeof(ResourceBuilding))
                {
                    ResourceBuilding m = (ResourceBuilding)u;
                    if (m.Xpos == x && m.Ypos == y)
                    {
                        texts.text = m.toString();
                    }
                }
            }
        }
    }
Ejemplo n.º 17
0
    public void Display()
    {
        foreach (Unit u in map.Unit)
        {
            if (u.GetType() == typeof(MeleeUnit))
            {
                MeleeUnit m = (MeleeUnit)u;



                if (m.symbol == "=")
                {
                    if (m.Fact == 1)
                    {
                        GameObject clone = Instantiate(BlueKnight, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        clone.transform.parent = transform;
                    }
                    else
                    {
                        GameObject clone = Instantiate(RedKnight, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        clone.transform.parent = transform;
                    }
                    if (m.isDead())
                    {
                    }
                }
                else
                {
                    if (m.Fact == 1)
                    {
                        GameObject clone = Instantiate(BlueLance, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        clone.transform.parent = transform;
                    }
                    else
                    {
                        GameObject clone = Instantiate(RedLance, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        clone.transform.parent = transform;
                    }
                    if (m.isDead())
                    {
                    }
                }
            }
        }
        foreach (Unit u in map.Unit)
        {
            if (u.GetType() == typeof(RangedUnits))
            {
                RangedUnits m = (RangedUnits)u;



                if (m.symbol == "}")
                {
                    if (m.Fact == 1)
                    {
                        GameObject clone = Instantiate(BlueArcher, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        clone.transform.parent = transform;
                    }
                    else
                    {
                        GameObject clone = Instantiate(RedArcher, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        clone.transform.parent = transform;
                    }
                    if (m.isDead())
                    {
                    }
                }
                else
                {
                    if (m.Fact == 1)
                    {
                        GameObject clone = Instantiate(BlueMusk, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        clone.transform.parent = transform;
                    }
                    else
                    {
                        GameObject clone = Instantiate(RedMusk, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        clone.transform.parent = transform;
                    }
                    if (m.isDead())
                    {
                    }
                }
            }
        }


        foreach (Unit u in map.Unit)
        {
            if (u.GetType() == typeof(Emperor))
            {
                Emperor emperor = (Emperor)u;



                if (emperor.Fact == 1)
                {
                    GameObject clone = Instantiate(BLueEmp, new Vector2(emperor.Xpos, emperor.Ypos), Quaternion.identity);
                    clone.transform.parent = transform;
                }
                else
                {
                    GameObject clone = Instantiate(RedEmp, new Vector2(emperor.Xpos, emperor.Ypos), Quaternion.identity);
                    clone.transform.parent = transform;
                }
                if (emperor.isDead())
                {
                }
            }
        }
        foreach (Building b in map.Building)
        {
            if (b.GetType() == typeof(FactoryBuilding))
            {
                FactoryBuilding m = (FactoryBuilding)b;



                if (m.Fact == 1)
                {
                    GameObject clone = Instantiate(BlueFactory, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                    clone.transform.parent = transform;
                }
                else
                {
                    GameObject clone = Instantiate(RedFactory, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                    clone.transform.parent = transform;
                }
                if (m.isDestoryed())
                {
                }
            }
        }
        foreach (ResourceBuilding b in map.RB)
        {
            if (b.GetType() == typeof(ResourceBuilding))
            {
                ResourceBuilding m = (ResourceBuilding)b;



                if (m.Fact == 1)
                {
                    GameObject clone = Instantiate(BlueResource, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                    clone.transform.parent = transform;
                }
                else
                {
                    GameObject clone = Instantiate(RedResource, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                    clone.transform.parent = transform;
                }
                if (m.isDestoryed())
                {
                }
            }
        }
    }
Ejemplo n.º 18
0
    private void UpdateMap() // this will cycle through all the units and buildisngs to see if they need to move and whether or not they have been killed in combat
    {
        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(MeleeUnit))
            {
                MeleeUnit m = (MeleeUnit)u;
                if (m.health > 1)
                {
                    if (m.health < 25)
                    {
                        switch (r.Next(0, 4))
                        {
                        case 0: ((MeleeUnit)u).NewPos(Direction.North); break;

                        case 1: ((MeleeUnit)u).NewPos(Direction.East); break;

                        case 2: ((MeleeUnit)u).NewPos(Direction.South); break;

                        case 3: ((MeleeUnit)u).NewPos(Direction.West); break;
                        }
                    }
                    else if (m.health < 10)  // this method will check a units health to see if it below 10 and if it is there will be a 50% chance of that unit changing alleigance to the other team and the unit will gain a small amount of health as compensation for changing team
                    {
                        int teamChange = r.Next(0, 2);
                        if (teamChange == 0)
                        {
                            if (m.faction == 1)
                            {
                                m.faction = 0;
                                m.health  = m.health + 5;
                            }
                            else
                            {
                                m.faction = 1;
                                m.health  = m.health + 5;
                            }
                        }
                    }
                    else
                    {
                        bool inCombat = false;
                        foreach (Unit e in map.Units)
                        {
                            if (u.withinAttackRange(e))
                            {
                                u.combatWithUnit(e);
                                inCombat = true;
                            }
                        }
                        if (!inCombat)
                        {
                            Unit c = u.UnitDistance(map.Units);
                            m.NewPos(m.Directionto(c));
                        }
                    }
                }
                else
                {
                    m.symbol = "X";
                    if (m.faction == 1)
                    {
                        GameObject dup = Instantiate(RedDeath, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else if (m.faction == 0)
                    {
                        GameObject dup = Instantiate(BlueDeath, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else
                    {
                        GameObject dup = Instantiate(NeutralDeath, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                }
            }
        }
        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(RangedUnit))
            {
                RangedUnit m = (RangedUnit)u;
                if (m.health > 1)
                {
                    if (m.health < 25)
                    {
                        switch (r.Next(0, 4))
                        {
                        case 0: ((RangedUnit)u).NewPos(Direction.North); break;

                        case 1: ((RangedUnit)u).NewPos(Direction.East); break;

                        case 2: ((RangedUnit)u).NewPos(Direction.South); break;

                        case 3: ((RangedUnit)u).NewPos(Direction.West); break;
                        }
                    }
                    else if (m.health < 10)  // this method will check a units health to see if it below 10 and if it is there will be a 50% chance of that unit changing alleigance to the other team and the unit will gain a small amount of health as compensation for changing team
                    {
                        int teamChange = r.Next(0, 2);
                        if (teamChange == 0)
                        {
                            if (m.faction == 1)
                            {
                                m.faction = 0;
                                m.health  = m.health + 5;
                            }
                            else
                            {
                                m.faction = 1;
                                m.health  = m.health + 5;
                            }
                        }
                    }
                    else
                    {
                        bool inCombat = false;
                        foreach (Unit e in map.Units)
                        {
                            if (u.withinAttackRange(e))
                            {
                                u.combatWithUnit(e);
                                inCombat = true;
                            }
                        }
                        if (!inCombat)
                        {
                            Unit c = u.UnitDistance(map.Units);
                            m.NewPos(m.Directionto(c));
                        }
                    }
                }
                else
                {
                    m.symbol = "X";

                    if (m.faction == 1)
                    {
                        GameObject dup = Instantiate(RedDeath, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else if (m.faction == 0)
                    {
                        GameObject dup = Instantiate(BlueDeath, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else
                    {
                        GameObject dup = Instantiate(NeutralDeath, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                }
            }
        }

        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(WizardUnit))
            {
                WizardUnit w = (WizardUnit)u;
                if (w.health > 1)
                {
                    if (w.health < 25)
                    {
                        switch (r.Next(0, 4))
                        {
                        case 0: ((WizardUnit)u).NewPos(Direction.North); break;

                        case 1: ((WizardUnit)u).NewPos(Direction.East); break;

                        case 2: ((WizardUnit)u).NewPos(Direction.South); break;

                        case 3: ((WizardUnit)u).NewPos(Direction.West); break;
                        }
                    }

                    else
                    {
                        bool inCombat = false;
                        foreach (Unit e in map.Units)
                        {
                            if (u.withinAttackRange(e))
                            {
                                u.combatWithUnit(e);
                                inCombat = true;
                            }
                        }
                        if (!inCombat)
                        {
                            Unit c = u.UnitDistance(map.Units);
                            w.NewPos(w.Directionto(c));
                        }
                    }
                }
                else
                {
                    w.symbol = "X";
                    if (w.faction == 1)
                    {
                        GameObject dup = Instantiate(RedDeath, new Vector2(w.Xpos, w.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else if (w.faction == 0)
                    {
                        GameObject dup = Instantiate(BlueDeath, new Vector2(w.Xpos, w.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else
                    {
                        GameObject dup = Instantiate(NeutralDeath, new Vector2(w.Xpos, w.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                }
            }
        }

        foreach (Building b in map.Buildings)
        {
            if (b.GetType() == typeof(ResourceBuilding))
            {
                ResourceBuilding rb = (ResourceBuilding)b;
                rb.ResourceGenerate();
            }
        }

        foreach (Building b in map.Buildings)
        {
            if (b.GetType() == typeof(FactoryBuilding))
            {
                FactoryBuilding fb = (FactoryBuilding)b;
            }
        }
        #region SpawningOfUnits
        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(MeleeUnit))
            {
                MeleeUnit mu = (MeleeUnit)u;
                if (mu.symbol == "X")
                {
                    int             faction = mu.faction;
                    int             rand    = r.Next(0, 5);
                    FactoryBuilding fb      = (FactoryBuilding)map.Buildings[rand];
                    fb.Spawner(20, 20, faction);
                }
            }
        }

        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(RangedUnit))
            {
                RangedUnit mu = (RangedUnit)u;
                if (mu.symbol == "X")
                {
                    int             faction = mu.faction;
                    int             rand    = r.Next(0, 5);
                    FactoryBuilding fb      = (FactoryBuilding)map.Buildings[rand];
                    fb.Spawner(20, 20, faction);
                }
            }
        }
        #endregion
    }
Ejemplo n.º 19
0
    private void DisplayMap()
    {
        GameObject[] unitList = GameObject.FindGameObjectsWithTag("unit");

        foreach (GameObject g in unitList)
        {
            Destroy(g);
        }

        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(Melee_Unit))
            {
                Melee_Unit m = (Melee_Unit)u;

                if (m.Faction == 1)
                {
                    Instantiate(redMelee, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                }//end if
                else
                {
                    Instantiate(blueMelee, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                }//end else
                if (m.IsDeath())
                {
                    Instantiate(death, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                } //end if
            }     //end if
            else if (u.GetType() == typeof(Ranged_Unit))
            {
                Ranged_Unit m = (Ranged_Unit)u;

                if (m.Faction == 1)
                {
                    Instantiate(redRanged, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                }//end if
                else
                {
                    Instantiate(blueRanged, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                }//end else
                if (m.IsDeath())
                {
                    Instantiate(death, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                } //end if
            }     //end else if
            else if (u.GetType() == typeof(Tank))
            {
                Tank m = (Tank)u;

                if (m.Faction == 1)
                {
                    Instantiate(redTank, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                }//end if
                else
                {
                    Instantiate(blueTank, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                }//end else
                if (m.IsDeath())
                {
                    Instantiate(death, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                } //end if
            }     //end else if
            else if (u.GetType() == typeof(Helicopter))
            {
                Helicopter m = (Helicopter)u;

                if (m.Faction == 1)
                {
                    Instantiate(redHeli, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                }//end if
                else
                {
                    Instantiate(blueHeli, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                }//end else
                if (m.IsDeath())
                {
                    Instantiate(death, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                } //end if
            }     //else if
            else if (u.GetType() == typeof(Fighter_Jets))
            {
                Fighter_Jets m = (Fighter_Jets)u;

                if (m.Faction == 1)
                {
                    Instantiate(redFighterJet, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                }//end if
                else
                {
                    Instantiate(blueFighterJet, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                }//end else
                if (m.IsDeath())
                {
                    Instantiate(death, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                } //end if
            }     //end else if
        }         //end for each

        foreach (Building b in map.Buildings)
        {
            if (b.GetType() == typeof(FactoryBuilding))
            {
                FactoryBuilding fb = (FactoryBuilding)b;

                if (fb.Faction == 1)
                {
                    Instantiate(redFactory, new Vector2(fb.XPos, fb.YPos), Quaternion.identity);
                }//end if
                else
                {
                    Instantiate(blueFactory, new Vector2(fb.XPos, fb.YPos), Quaternion.identity);
                }//end else
                if (fb.IsDestroyed())
                {
                    Instantiate(death, new Vector2(fb.XPos, fb.YPos), Quaternion.identity);
                } //end if
            }     //end if
            else if (b.GetType() == typeof(ResourceBuilding))
            {
                ResourceBuilding rb = (ResourceBuilding)b;

                if (rb.Faction == 1)
                {
                    Instantiate(redSource, new Vector2(rb.XPos, rb.YPos), Quaternion.identity);
                }//end if
                else
                {
                    Instantiate(bluesource, new Vector2(rb.XPos, rb.YPos), Quaternion.identity);
                }//end else
                if (rb.IsDestroyed())
                {
                    Instantiate(death, new Vector2(rb.XPos, rb.YPos), Quaternion.identity);
                }
            }//end else if
            else if (b.GetType() == typeof(Field_Hospital))
            {
                Field_Hospital fh = (Field_Hospital)b;

                if (fh.Faction == 1)
                {
                    Instantiate(redHospital, new Vector2(fh.XPos, fh.YPos), Quaternion.identity);
                }//end if
                else
                {
                    Instantiate(blueHospital, new Vector2(fh.XPos, fh.YPos), Quaternion.identity);
                }//end else
                if (fh.IsDestroyed())
                {
                    Instantiate(death, new Vector2(fh.XPos, fh.YPos), Quaternion.identity);
                }
            }//end else if
            else if (b.GetType() == typeof(Weapon_Upgrade))
            {
                Weapon_Upgrade wu = (Weapon_Upgrade)b;

                if (wu.Faction == 1)
                {
                    Instantiate(redUpgrade, new Vector2(wu.XPos, wu.YPos), Quaternion.identity);
                }//end if
                else
                {
                    Instantiate(blueUpgrade, new Vector2(wu.XPos, wu.YPos), Quaternion.identity);
                }//end else
                if (wu.IsDestroyed())
                {
                    Instantiate(death, new Vector2(wu.XPos, wu.YPos), Quaternion.identity);
                } //end if
            }     //end else if
        }         //end foreach
    }             // creates new buttons for every unit and building saved in the arrays. each button is made to match the type of unit or building it is by changing colours and letters displayed on it.
Ejemplo n.º 20
0
    public void DisplayMap()
    {
        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(MeleeUnit))
            {
                int       start_x = 20;
                int       start_Y = 20;
                MeleeUnit m       = (MeleeUnit)u;
                if (m.health > 0)
                {
                    if (m.faction == 1)
                    {
                        GameObject dup = Instantiate(RedMelee, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else if (m.faction == 0)
                    {
                        GameObject dup = Instantiate(BlueMelee, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else
                    {
                        GameObject dup = Instantiate(GreyMelee, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                }
                if (m.isDead())
                {
                    m.symbol = "X";
                    if (m.faction == 1)
                    {
                        GameObject dup = Instantiate(RedDeath, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else if (m.faction == 0)
                    {
                        GameObject dup = Instantiate(BlueDeath, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else
                    {
                        GameObject dup = Instantiate(NeutralDeath, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                }
            }
        }

        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(RangedUnit))
            {
                int        start_x = 20;
                int        start_Y = 20;
                RangedUnit m       = (RangedUnit)u;
                if (m.health > 0)
                {
                    if (m.faction == 1)
                    {
                        GameObject dup = Instantiate(RedRanged, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else if (m.faction == 0)
                    {
                        GameObject dup = Instantiate(BlueRanged, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else
                    {
                        GameObject dup = Instantiate(GreyRanged, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                }
                if (m.isDead())
                {
                    m.symbol = "X";
                    if (m.faction == 1)
                    {
                        GameObject dup = Instantiate(RedDeath, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else if (m.faction == 0)
                    {
                        GameObject dup = Instantiate(BlueDeath, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else
                    {
                        GameObject dup = Instantiate(NeutralDeath, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                }
            }
        }

        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(WizardUnit))
            {
                int        start_x = 20;
                int        start_Y = 20;
                WizardUnit m       = (WizardUnit)u;
                if (m.health > 0)
                {
                    if (m.faction == 1)
                    {
                        GameObject dup = Instantiate(RedWizard, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else if (m.faction == 0)
                    {
                        GameObject dup = Instantiate(BlueWizard, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                }
                if (m.isDead())
                {
                    m.symbol = "X";
                    if (m.faction == 1)
                    {
                        GameObject dup = Instantiate(RedDeath, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else if (m.faction == 0)
                    {
                        GameObject dup = Instantiate(BlueDeath, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                }
            }
        }

        foreach (Building u in map.Buildings)
        {
            if (u.GetType() == typeof(FactoryBuilding))
            {
                int             start_x = 20;
                int             start_Y = 20;
                FactoryBuilding m       = (FactoryBuilding)u;
                if (m.health > 0)
                {
                    if (m.faction == 1)
                    {
                        GameObject dup = Instantiate(RedFactory, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else if (m.faction == 0)
                    {
                        GameObject dup = Instantiate(BlueFactory, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                }
                if (m.isDead())
                {
                    m.symbol = "X";
                    if (m.faction == 1)
                    {
                        GameObject dup = Instantiate(RedDeath, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else if (m.faction == 0)
                    {
                        GameObject dup = Instantiate(BlueDeath, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                }
            }
        }

        foreach (Building u in map.Buildings)
        {
            if (u.GetType() == typeof(ResourceBuilding))
            {
                int start_x        = 20;
                int start_Y        = 20;
                ResourceBuilding m = (ResourceBuilding)u;
                if (m.health > 0)
                {
                    if (m.faction == 1)
                    {
                        GameObject dup = Instantiate(RedMine, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else if (m.faction == 0)
                    {
                        GameObject dup = Instantiate(BlueMine, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                }
                if (m.isDead())
                {
                    m.symbol = "X";
                    if (m.faction == 1)
                    {
                        GameObject dup = Instantiate(RedDeath, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else if (m.faction == 0)
                    {
                        GameObject dup = Instantiate(BlueDeath, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                }
            }
        }
    }
Ejemplo n.º 21
0
    //Handles generation of the units
    public void Generate()
    {
        //PvP Teams
        for (int i = 0; i < numUnits; i++)
        {
            int holdMe;
            holdMe = Random.Range(0, 2);

            if (holdMe == 0) //Generate Melee Unit
            {
                MeleeUnit m = new MeleeUnit("Barbarian",
                                            Random.Range(0, width),
                                            Random.Range(0, height),
                                            (i % 2 == 0 ? 1 : 0),
                                            30,
                                            1,
                                            5,
                                            1,
                                            false
                                            );
                units.Add(m);
            }
            else if (holdMe == 1) // Generate Ranged Unit
            {
                RangedUnit ru = new RangedUnit("Tank",
                                               Random.Range(0, width),
                                               Random.Range(0, height),
                                               (i % 2 == 0 ? 1 : 0),
                                               20,
                                               1,
                                               3,
                                               2,
                                               false
                                               );
                units.Add(ru);
            }
            else
            {
                WizardUnit wu = new WizardUnit("Lich",
                                               Random.Range(0, width),
                                               Random.Range(0, height),
                                               3,
                                               6,
                                               1,
                                               5,
                                               1,
                                               false
                                               );
                units.Add(wu);
            }
        }

        for (int l = 0; l < 6; l++)
        {
            WizardUnit wu = new WizardUnit("Lich",
                                           Random.Range(0, width),
                                           Random.Range(0, height),
                                           3,
                                           15,
                                           1,
                                           5,
                                           1,
                                           false
                                           );
            units.Add(wu);
        }

        for (int k = 0; k < numBuildings; k++)
        {
            if (Random.Range(0, 2) == 0) //Generate Resource Building
            {
                ResourceBuilding rb = new ResourceBuilding(Random.Range(0, width),
                                                           Random.Range(0, height),
                                                           20,
                                                           (k % 2 == 0 ? 1 : 0),
                                                           10);
                buildings.Add(rb);
            }
            else //Generate Unit Building
            {
                FactoryBuilding fb = new FactoryBuilding(Random.Range(0, width),
                                                         Random.Range(0, height),
                                                         20,
                                                         (k % 2 == 0 ? 1 : 0),
                                                         3,
                                                         (Random.Range(0, 2) == 1 ? "Melee" : "Ranged"),
                                                         35);

                buildings.Add(fb);
            }
        }
    }
Ejemplo n.º 22
0
    public void castRay()
    {
        Ray          ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, Mathf.Infinity);

        if (hit)
        {
            float x = hit.collider.transform.position.x;
            float y = hit.collider.transform.position.y;


            Debug.Log("" + x + " " + y);

            foreach (Unit u in map.Units)
            {
                if (u.GetType() == typeof(RangedUnit))
                {
                    RangedUnit r = (RangedUnit)u;

                    if (r.Xpos == x && r.Ypos == y)
                    {
                        info.text = "" + r.toString();
                    }
                }

                else if (u.GetType() == typeof(MeleeUnit))
                {
                    MeleeUnit m = (MeleeUnit)u;

                    if (m.Xpos == x && m.Ypos == y)
                    {
                        info.text = "" + m.toString();
                    }
                }

                else if (u.GetType() == typeof(WizardUnit))
                {
                    WizardUnit m = (WizardUnit)u;

                    if (m.Xpos == x && m.Ypos == y)
                    {
                        info.text = "" + m.toString();
                    }
                }
            }

            foreach (Building b in map.Buildings)
            {
                if (b.GetType() == typeof(FactoryBuilding))
                {
                    FactoryBuilding fb = (FactoryBuilding)b;

                    if (fb.Xpos == x && fb.Ypos == y)
                    {
                        info.text = "" + fb.toString();
                    }
                }

                else if (b.GetType() == typeof(ResourceBuilding))
                {
                    ResourceBuilding rb = (ResourceBuilding)b;

                    if (rb.Xpos == x && rb.Ypos == y)
                    {
                        info.text = "" + rb.toString();
                    }
                }
            }
        }
    }
Ejemplo n.º 23
0
Archivo: Map.cs Proyecto: AJMuller/POE
    }     //makes objects and generates values for these objects

    public void Read(int numUnits, int numBuildings)
    {
        int counter = 0;



        string[] stringArray = File.ReadAllLines("MeleeUnit.txt");
        units = new Unit[numUnits];

        foreach (string line in stringArray)
        {
            if (line != "")
            {
                Melee_Unit m = new Melee_Unit(line.Split(',')[0], Convert.ToInt32(line.Split(',')[2]),
                                              Convert.ToInt32(line.Split(',')[1]),
                                              Convert.ToInt32(line.Split(',')[3]),
                                              Convert.ToInt32(line.Split(',')[6]),
                                              Convert.ToInt32(line.Split(',')[5]),
                                              Convert.ToInt32(line.Split(',')[4]),
                                              Convert.ToInt32(line.Split(',')[7]),
                                              line.Split(',')[8]);
                counter++;
                units[counter - 1] = m;
            } //end if
        }     //end foreach


        string[] rstringArray = File.ReadAllLines("RangedUnit.txt");

        foreach (string line in rstringArray)
        {
            if (line != "")
            {
                Ranged_Unit m = new Ranged_Unit(line.Split(',')[0], Convert.ToInt32(line.Split(',')[2]),
                                                Convert.ToInt32(line.Split(',')[1]),
                                                Convert.ToInt32(line.Split(',')[3]),
                                                Convert.ToInt32(line.Split(',')[6]),
                                                Convert.ToInt32(line.Split(',')[5]),
                                                Convert.ToInt32(line.Split(',')[4]),
                                                Convert.ToInt32(line.Split(',')[7]),
                                                line.Split(',')[8]);
                counter++;
                units[counter - 1] = m;
            } //end if
        }     // end foreach

        string[] TtringArray = File.ReadAllLines("Tank.txt");

        foreach (string line in TtringArray)
        {
            if (line != "")
            {
                Tank m = new Tank(line.Split(',')[0], Convert.ToInt32(line.Split(',')[2]),
                                  Convert.ToInt32(line.Split(',')[1]),
                                  Convert.ToInt32(line.Split(',')[3]),
                                  Convert.ToInt32(line.Split(',')[6]),
                                  Convert.ToInt32(line.Split(',')[5]),
                                  Convert.ToInt32(line.Split(',')[4]),
                                  Convert.ToInt32(line.Split(',')[7]),
                                  line.Split(',')[8]);
                counter++;
                units[counter - 1] = m;
            } //end if
        }     // end foreach

        string[] hstringArray = File.ReadAllLines("Helicopter.txt");

        foreach (string line in hstringArray)
        {
            if (line != "")
            {
                Helicopter m = new Helicopter(line.Split(',')[0], Convert.ToInt32(line.Split(',')[2]),
                                              Convert.ToInt32(line.Split(',')[1]),
                                              Convert.ToInt32(line.Split(',')[3]),
                                              Convert.ToInt32(line.Split(',')[6]),
                                              Convert.ToInt32(line.Split(',')[5]),
                                              Convert.ToInt32(line.Split(',')[4]),
                                              Convert.ToInt32(line.Split(',')[7]),
                                              line.Split(',')[8]);
                counter++;
                units[counter - 1] = m;
            } //end if
        }     // end foreach

        string[] fjstringArray = File.ReadAllLines("Fighter_Jets.txt");

        foreach (string line in fjstringArray)
        {
            if (line != "")
            {
                Fighter_Jets m = new Fighter_Jets(line.Split(',')[0], Convert.ToInt32(line.Split(',')[2]),
                                                  Convert.ToInt32(line.Split(',')[1]),
                                                  Convert.ToInt32(line.Split(',')[3]),
                                                  Convert.ToInt32(line.Split(',')[6]),
                                                  Convert.ToInt32(line.Split(',')[5]),
                                                  Convert.ToInt32(line.Split(',')[4]),
                                                  Convert.ToInt32(line.Split(',')[7]),
                                                  line.Split(',')[8]);
                counter++;
                units[counter - 1] = m;
            } //end if
        }     // end foreach



        int bcounter = 0;

        string[] fbstringArray = File.ReadAllLines("FactoryBuilding.txt");
        buildings = new Building[numBuildings];
        foreach (string line in fbstringArray)
        {
            if (line != "")
            {
                FactoryBuilding m = new FactoryBuilding(Convert.ToInt32(line.Split(',')[1]),
                                                        Convert.ToInt32(line.Split(',')[2]),
                                                        Convert.ToInt32(line.Split(',')[3]),
                                                        Convert.ToInt32(line.Split(',')[4]),
                                                        line.Split(',')[5]);

                bcounter++;
                buildings[bcounter - 1] = m;
            } //end if
        }     //end foreach


        string[] rbstringArray = File.ReadAllLines("ResourceBuilding.txt");


        foreach (string line in rbstringArray)
        {
            if (line != "")
            {
                ResourceBuilding m = new ResourceBuilding(Convert.ToInt32(line.Split(',')[1]),
                                                          Convert.ToInt32(line.Split(',')[2]),
                                                          Convert.ToInt32(line.Split(',')[3]),
                                                          Convert.ToInt32(line.Split(',')[4]),
                                                          line.Split(',')[5]);

                bcounter++;
                buildings[bcounter - 1] = m;
            } //end if
        }     //end foreach

        string[] fhstringArray = File.ReadAllLines("Field_Hospital.txt");


        foreach (string line in fhstringArray)
        {
            if (line != "")
            {
                Field_Hospital m = new Field_Hospital(Convert.ToInt32(line.Split(',')[1]),
                                                      Convert.ToInt32(line.Split(',')[2]),
                                                      Convert.ToInt32(line.Split(',')[3]),
                                                      Convert.ToInt32(line.Split(',')[4]),
                                                      line.Split(',')[5]);

                bcounter++;
                buildings[bcounter - 1] = m;
            } //end if
        }     //end foreach

        string[] wustringArray = File.ReadAllLines("Weapon_Upgrade.txt");


        foreach (string line in wustringArray)
        {
            if (line != "")
            {
                Weapon_Upgrade m = new Weapon_Upgrade(Convert.ToInt32(line.Split(',')[1]),
                                                      Convert.ToInt32(line.Split(',')[2]),
                                                      Convert.ToInt32(line.Split(',')[3]),
                                                      Convert.ToInt32(line.Split(',')[4]),
                                                      line.Split(',')[5]);

                bcounter++;
                buildings[bcounter - 1] = m;
            } //end if
        }     //end foreach
    }         // reads from textfile and creates objects with the values from the textfile
Ejemplo n.º 24
0
    //Checks to see if the closest enemy is in attack range and if they are calls combat or move if they aren't
    public override void CheckAttackRange(List <Unit> uni, List <Building> build)
    {
        units     = uni;
        buildings = build;

        closestUnit     = ClosestEnemy();
        closestBuilding = ClosestEnemyBuilding();

        int enemyType;

        int xDis = 0, yDis = 0;

        int uDistance = 10000, bDistance = 10000;
        int distance;

        if (closestUnit is MeleeUnit)
        {
            MeleeUnit M = (MeleeUnit)closestUnit;
            xDis = Mathf.Abs((PosX - M.PosX) * (PosX - M.PosX));
            yDis = Mathf.Abs((PosY - M.PosY) * (PosY - M.PosY));

            uDistance = (int)Mathf.Round(Mathf.Sqrt(xDis + yDis));
        }
        else if (closestUnit is RangedUnit)
        {
            RangedUnit R = (RangedUnit)closestUnit;
            xDis = Mathf.Abs((PosX - R.PosX) * (PosX - R.PosX));
            yDis = Mathf.Abs((PosY - R.PosY) * (PosY - R.PosY));

            uDistance = (int)Mathf.Round(Mathf.Sqrt(xDis + yDis));
        }
        else if (closestUnit is WizardUnit)
        {
            WizardUnit W = (WizardUnit)closestUnit;
            xDis = Mathf.Abs((PosX - W.PosX) * (PosX - W.PosX));
            yDis = Mathf.Abs((PosY - W.PosY) * (PosY - W.PosY));

            uDistance = (int)Mathf.Round(Mathf.Sqrt(xDis + yDis));
        }

        if (closestBuilding is FactoryBuilding)
        {
            FactoryBuilding FB = (FactoryBuilding)closestBuilding;
            xDis = Mathf.Abs((PosX - FB.PosX) * (PosX - FB.PosX));
            yDis = Mathf.Abs((PosY - FB.PosY) * (PosY - FB.PosY));

            bDistance = (int)Mathf.Round(Mathf.Sqrt(xDis + yDis));
        }
        else if (closestBuilding is ResourceBuilding)
        {
            ResourceBuilding RB = (ResourceBuilding)closestBuilding;
            xDis = Mathf.Abs((PosX - RB.PosX) * (PosX - RB.PosX));
            yDis = Mathf.Abs((PosY - RB.PosY) * (PosY - RB.PosY));

            bDistance = (int)Mathf.Round(Mathf.Sqrt(xDis + yDis));
        }

        if (units[0] != null)
        {
            if (uDistance < bDistance)
            {
                distance  = uDistance;
                enemyType = 0;
            }
            else
            {
                distance  = bDistance;
                enemyType = 1;
            }
        }
        else
        {
            distance  = bDistance;
            enemyType = 1;
        }

        //Checks to see if they are below 25% health so they move rather than attacking
        if (Health > MaxHealth * 0.25)
        {
            if (distance <= AttackRange)
            {
                IsAttacking = true;
                Combat(enemyType);
            }
            else
            {
                IsAttacking = false;
                Move(enemyType);
            }
        }
        else
        {
            Move(enemyType);
        }
    }
Ejemplo n.º 25
0
    //**************************************************************************************************************** Methods *************************************************************************************************************************************

    public void PopulateBattlefield()
    {
        arrBuilding[0] = new FactoryBuilding("Hero", 19, 19);
        arrBuilding[1] = new FactoryBuilding("Enemy", 0, 19);
        arrBuilding[2] = new ResourceBuilding("Hero", 0, 0);
        arrBuilding[3] = new ResourceBuilding("Enemy", 19, 0);

        for (int j = 0; j < 20; j++)
        {
            for (int i = 0; i < 20; i++)
            {
                arrMap[j, i] = ',';
            }
        }


        arrMap[19, 19] = arrBuilding[0].Buildingsymbol;
        arrMap[0, 19]  = arrBuilding[1].Buildingsymbol;
        arrMap[0, 0]   = arrBuilding[2].Buildingsymbol;
        arrMap[19, 0]  = arrBuilding[3].Buildingsymbol;

        for (int i = 0; i < ArrUnit.Length; i++)
        {
            int number = random.Next(1, 10);
            xpos = random.Next(1, 20);
            ypos = random.Next(1, 20);

            if (arrMap[xpos, ypos] != '#' && arrMap[xpos, ypos] != '@')
            {
                if (number % 2 == 0 && arrMap[xpos, ypos] == ',')
                {
                    int number2 = random.Next(1, 10);

                    if (number2 % 2 == 0)
                    {
                        Faction = "Hero";
                        Symbol  = '$';
                    }

                    if (number2 % 2 != 0)
                    {
                        Faction = "Enemy";
                        Symbol  = '%';
                    }

                    ArrUnit[i]         = new MeleeUnit(xpos, ypos, Faction, Symbol);
                    arrMap[xpos, ypos] = Symbol;
                }

                else if (number % 2 != 0 && arrMap[xpos, ypos] == ',')
                {
                    int number3 = random.Next(1, 10);

                    if (number3 % 2 == 0)
                    {
                        Faction = "Hero";
                        Symbol  = '^';
                    }

                    if (number3 % 2 != 0)
                    {
                        Faction = "Enemy";
                        Symbol  = '&';
                    }



                    ArrUnit[i]         = new RangedUnit(xpos, ypos, Faction, Symbol);
                    arrMap[xpos, ypos] = Symbol;
                }
                else
                {
                    i--;
                }
            }
            else
            {
                i--;
            }
        }
    }
Ejemplo n.º 26
0
    //Changes the x and y position towards the closest enemy or to run away
    public override void Move(int type)
    {
        //Moves towards closest enemey
        if (Health > MaxHealth * 0.25)
        {
            if (type == 0)
            {
                if (closestUnit is MeleeUnit)
                {
                    MeleeUnit closestUnitM = (MeleeUnit)closestUnit;

                    if (closestUnitM.PosX > posX && PosX < MapWidth - 1)
                    {
                        posX++;
                    }
                    else if (closestUnitM.PosX < posX && posX > 0)
                    {
                        posX--;
                    }

                    if (closestUnitM.PosY > posY && PosY < MapHeight - 1)
                    {
                        posY++;
                    }
                    else if (closestUnitM.PosY < posY && posY > 0)
                    {
                        posY--;
                    }
                }
                else if (closestUnit is RangedUnit)
                {
                    RangedUnit closestUnitR = (RangedUnit)closestUnit;

                    if (closestUnitR.PosX > posX && PosX < MapWidth - 1)
                    {
                        posX++;
                    }
                    else if (closestUnitR.PosX < posX && posX > 0)
                    {
                        posX--;
                    }

                    if (closestUnitR.PosY > posY && PosY < MapHeight - 1)
                    {
                        posY++;
                    }
                    else if (closestUnitR.PosY < posY && posY > 0)
                    {
                        posY--;
                    }
                }
                else if (closestUnit is WizardUnit)
                {
                    WizardUnit closestUnitW = (WizardUnit)closestUnit;

                    if (closestUnitW.PosX > posX && PosX < MapWidth - 1)
                    {
                        posX++;
                    }
                    else if (closestUnitW.PosX < posX && posX > 0)
                    {
                        posX--;
                    }

                    if (closestUnitW.PosY > posY && PosY < MapHeight - 1)
                    {
                        posY++;
                    }
                    else if (closestUnitW.PosY < posY && posY > 0)
                    {
                        posY--;
                    }
                }
            }
            else
            {
                if (closestBuilding is FactoryBuilding)
                {
                    FactoryBuilding closestBuildingFB = (FactoryBuilding)closestBuilding;

                    if (closestBuildingFB.PosX > posX && PosX < MapHeight - 1)
                    {
                        posX++;
                    }
                    else if (closestBuildingFB.PosX < posX && posX > 0)
                    {
                        posX--;
                    }

                    if (closestBuildingFB.PosY > posY && PosY < MapWidth - 1)
                    {
                        posY++;
                    }
                    else if (closestBuildingFB.PosY < posY && posY > 0)
                    {
                        posY--;
                    }
                }
                else if (closestBuilding is ResourceBuilding)
                {
                    ResourceBuilding closestBuildingRB = (ResourceBuilding)closestBuilding;

                    if (closestBuildingRB.PosX > posX && PosX < MapHeight - 1)
                    {
                        posX++;
                    }
                    else if (closestBuildingRB.PosX < posX && posX > 0)
                    {
                        posX--;
                    }

                    if (closestBuildingRB.PosY > posY && PosY < MapWidth - 1)
                    {
                        posY++;
                    }
                    else if (closestBuildingRB.PosY < posY && posY > 0)
                    {
                        posY--;
                    }
                }
            }
        }
        else //Moves in random direction to run away
        {
            int direction = Random.Range(0, 4);

            if (direction == 0 && PosX < MapHeight - 1)
            {
                posX++;
            }
            else if (direction == 1 && posX > 0)
            {
                posX--;
            }
            else if (direction == 2 && posY < MapWidth - 1)
            {
                posY++;
            }
            else if (direction == 3 && posY > 0)
            {
                posY--;
            }
        }
    }
Ejemplo n.º 27
0
    public void Click()
    {
        int x = map.PosX;
        int Y = map.PosY;

        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(RangedUnit))
            {
                RangedUnit r = (RangedUnit)u;

                if (r.PosX == x && r.PosY == Y)
                {
                    txtTexts.text = "" + m.toString;
                }
            }

            else if (u.GetType() == typeof(MeeleeUnit))
            {
                MeeleeUnit m = (MeeleeUnit)u;

                if (m.PosX == x && m.PosY == Y)
                {
                    txtTexts.text = "" + m.toString();
                }
            }

            else if (u.GetType() == typeof(WarlockUnit))
            {
                WarlockUnit m = (WarlockUnit)u;

                if (m.PosX == x && m.PosY == Y)
                {
                    txtTexts.text = "" + m.toString();
                }
            }
        }

        foreach (Building b in map.Buildings)
        {
            if (b.GetType() == typeof(FactoryBuilding))
            {
                FactoryBuilding fb = (FactoryBuilding)b;

                if (fb.PosX == x && fb.PosY == Y)
                {
                    txtTexts.text = "" + fb.toString();
                }
            }

            else if (b.GetType() == typeof(ResourceBuilding))
            {
                ResourceBuilding rb = (ResourceBuilding)b;

                if (rb.PosX == x && rb.PosY == Y)
                {
                    txtTexts.text = "" + rb.toString();
                }
            }
        }
    }
Ejemplo n.º 28
0
    // Loads save from file
    public void Load()
    {
        // Ensures load only runs on the island scene
        if (SceneManager.GetActiveScene().name == "PrivateIsland")
        {
            // Load
            if (File.Exists(path))
            {
                // Opens stream
                FileStream stream = new FileStream(path, FileMode.Open);

                try
                {
                    // Loads resources
                    int numResources = (int)formatter.Deserialize(stream);
                    for (int i = 0; i < numResources; i++)
                    {
                        ResourceSave resourceData = formatter.Deserialize(stream) as ResourceSave;

                        // Instantiate resource
                        GameObject resourceObject = Resources.Load("Prefabs/WorldResources/Raw resources/" + RemoveCopyInName(resourceData.objectName)) as GameObject;
                        GameObject worldObject    = LoadObject(resourceObject, resourceData.position, resourceData.rotation);

                        ResourceWorldObject resource = worldObject.GetComponentInChildren <ResourceWorldObject>();

                        // ERROR lies here, somehow
                        resource.LoadFromSave(resourceData.resourceAmount);
                    }

                    // Load factories
                    int numFactories = (int)formatter.Deserialize(stream);
                    for (int i = 0; i < numFactories; i++)
                    {
                        FactorySave factoryData = formatter.Deserialize(stream) as FactorySave;

                        // Instantiate factory
                        GameObject factoryObject = Resources.Load("Prefabs/Buildings/Factory/Primary buildings/" + RemoveCopyInName(factoryData.objectName)) as GameObject;
                        GameObject worldObject   = LoadObject(factoryObject, factoryData.position, factoryData.rotation);

                        // Updates position, makes sure the building finishes building if it is finished
                        FactoryBuilding factory = worldObject.GetComponent <FactoryBuilding>();
                        factory.LoadFromSave(factoryData.presentHealth, factoryData.buildingFinished, factoryData.yOffset);
                        factory.LoadFactory(factoryData.isWorking, factoryData.remainingTime, factoryData.timeRound, factoryData.index, factoryData.remainingRounds, factoryData.originalRounds);
                    }


                    // Load harvesters
                    int numHarvesters = (int)formatter.Deserialize(stream);
                    for (int i = 0; i < numHarvesters; i++)
                    {
                        BuildingSave harvesterData = formatter.Deserialize(stream) as BuildingSave;

                        // Instantiate harvester
                        GameObject resourceObject = Resources.Load("Prefabs/Buildings/ResourceGathering/" + RemoveCopyInName(harvesterData.objectName)) as GameObject;
                        GameObject worldObject    = LoadObject(resourceObject, harvesterData.position, harvesterData.rotation);

                        // Updates position, makes sure the building finishes building if it is finished
                        AbstractResourceHarvesting harvester = worldObject.GetComponent <AbstractResourceHarvesting>();
                        harvester.LoadFromSave(harvesterData.presentHealth, harvesterData.buildingFinished, harvesterData.yOffset);
                    }

                    // Load houses
                    int numHouses = (int)formatter.Deserialize(stream);
                    for (int i = 0; i < numHouses; i++)
                    {
                        BuildingSave houseData = formatter.Deserialize(stream) as BuildingSave;

                        // Instantiate harvester
                        // GameObject resourceObject = Resources.Load("Prefabs/Buildings/" + RemoveCopyInName(houseData.objectName)) as GameObject;
                        GameObject resourceObject = Resources.Load("Prefabs/Buildings/HouseTemplate") as GameObject;
                        GameObject worldObject    = LoadObject(resourceObject, houseData.position, houseData.rotation);

                        // Updates position, makes sure the building finishes building if it is finished
                        AbstractHouse house = worldObject.GetComponent <AbstractHouse>();
                        house.LoadFromSave(houseData.presentHealth, houseData.buildingFinished, houseData.yOffset);
                    }

                    // Resource amounts
                    for (int i = 0; i < GameManager.resources.Length; i++)
                    {
                        // Sends in amount of resource
                        GameManager.resources[i].amount = (float)formatter.Deserialize(stream);
                    }

                    // Money
                    GameManager.moneyAmount = (float)formatter.Deserialize(stream);

                    // Roads

                    int numRoads = (int)formatter.Deserialize(stream);
                    roadPlacer.enabled = true;
                    Debug.Log("NumberOfRoads: " + numRoads);

                    for (int i = 0; i < numRoads; i++)
                    {
                        RoadSave roadeData = formatter.Deserialize(stream) as RoadSave;

                        Vector3 startPos      = new Vector3(roadeData.startPos_X, roadeData.startPos_Y, roadeData.startPos_Z);
                        Vector3 controllNode1 = new Vector3(roadeData.controllNode1_X, roadeData.controllNode1_Y, roadeData.controllNode1_Z);
                        Vector3 controllNode2 = new Vector3(roadeData.controllNode2_X, roadeData.controllNode2_Y, roadeData.controllNode2_Z);
                        Vector3 endPos        = new Vector3(roadeData.endPos_X, roadeData.endPos_Y, roadeData.endPos_Z);

                        roadPlacer.GenerateRoad(startPos, controllNode1, controllNode2, endPos);
                        Debug.Log("LoadingRoads");
                    }
                    roadPlacer.enabled = false;
                }
                catch (System.Exception e)
                {
                    Debug.Log("Error: " + e);
                }

                // Camera position
                Camera.main.transform.position = new Vector3((float)formatter.Deserialize(stream), (float)formatter.Deserialize(stream), (float)formatter.Deserialize(stream));

                // Camera rotation
                if (cameraMovement != null)
                {
                    cameraMovement.LoadAngles((float)formatter.Deserialize(stream), (float)formatter.Deserialize(stream));
                }

                // Loads sun position
                sunManager.UpdatePosition((float[])formatter.Deserialize(stream));

                // Time
                timeManager.UpdateTime((int[])formatter.Deserialize(stream));

                // Camera mode
                GameManager.inputManager.frozenAngle = (bool)formatter.Deserialize(stream);
                Cursor.visible = /*GameManager.isPaused || */ GameManager.inputManager.frozenAngle;
                if (Cursor.visible)
                {
                    Cursor.lockState = CursorLockMode.None;
                }
                else
                {
                    Cursor.lockState = CursorLockMode.Locked;
                }

                // Close stream
                stream.Close();
            }
            else
            {
                Debug.Log("No save file found");
            }
        }
    }
Ejemplo n.º 29
0
    public void CheckDeath()
    {
        //Checks to see who has died and needs to be deleted
        for (int i = 0; i < m.rangedUnits.Count; i++)
        {
            if (m.rangedUnits[i].Death())
            {
                m.rangedUnits.RemoveAt(i);
            }
        }

        for (int i = 0; i < m.meleeUnits.Count; i++)
        {
            if (m.meleeUnits[i].Death())
            {
                m.meleeUnits.RemoveAt(i);
            }
        }

        for (int i = 0; i < m.wizardUnits.Count; i++)
        {
            if (m.wizardUnits[i].Death())
            {
                m.wizardUnits.RemoveAt(i);
            }
        }

        for (int i = 0; i < m.units.Count; i++)
        {
            if (m.units[i].Death())
            {
                if (m.units[i] is MeleeUnit)
                {
                    MeleeUnit M = (MeleeUnit)m.units[i];
                }
                else if (m.units[i] is RangedUnit)
                {
                    RangedUnit R = (RangedUnit)m.units[i];
                }
                else if (m.units[i] is WizardUnit)
                {
                    WizardUnit W = (WizardUnit)m.units[i];
                }

                m.units.RemoveAt(i);
            }
        }

        for (int i = 0; i < m.factories.Count; i++)
        {
            if (m.factories[i].Death())
            {
                m.factories.RemoveAt(i);
            }
        }

        for (int i = 0; i < m.mines.Count; i++)
        {
            if (m.mines[i].Death())
            {
                m.mines.RemoveAt(i);
            }
        }

        for (int i = 0; i < m.buildings.Count; i++)
        {
            if (m.buildings[i].Death())
            {
                if (m.buildings[i] is FactoryBuilding)
                {
                    FactoryBuilding FB = (FactoryBuilding)m.buildings[i];
                }
                else if (m.buildings[i] is ResourceBuilding)
                {
                    ResourceBuilding RB = (ResourceBuilding)m.buildings[i];
                }

                m.buildings.RemoveAt(i);
            }
        }
    }
Ejemplo n.º 30
0
    private void GameLogic()
    {
        ResourceDisplay();
        //Working out if both teams are alive
        red  = 0;
        blue = 0;

        foreach (Building B in map.buildings)
        {
            if (B is ResourceBuilding)
            {
                ResourceBuilding RB = (ResourceBuilding)B;
                if (RB.FactionType == 0)
                {
                    red++;
                }
                else
                {
                    blue++;
                }
            }
            else
            {
                FactoryBuilding FB = (FactoryBuilding)B;
                if (FB.FactionType == 0)
                {
                    red++;
                }
                else
                {
                    blue++;
                }
            }
        }

        foreach (Unit u in map.Units)
        {
            if (u is MeleeUnit)
            {
                MeleeUnit mu = (MeleeUnit)u;
                if (mu.FactionType == 0)
                {
                    red++;
                }
                else
                {
                    blue++;
                }
            }
            else if (u is RangedUnit)
            {
                RangedUnit ru = (RangedUnit)u;
                if (ru.FactionType == 0)
                {
                    red++;
                }
                else
                {
                    blue++;
                }
            }
            else
            {
            }
        }

        if (red > 0 && blue > 0)//Checks to see if both teams are still alive
        {
            //Reset resource values
            redResourcesLeft  = 0;
            blueResourcesLeft = 0;

            foreach (Building b in map.buildings)
            {
                if (b is ResourceBuilding)
                {
                    ResourceBuilding RB = (ResourceBuilding)b;
                    if (RB.FactionType == 0)
                    {
                        redResources     += RB.GenerateResource();
                        redResourcesLeft += RB.ResresourcesLeft;
                    }
                    else if (RB.FactionType == 1)
                    {
                        blueResources     += RB.GenerateResource();
                        blueResourcesLeft += RB.ResresourcesLeft;
                    }
                }
                else
                {
                    FactoryBuilding FB = (FactoryBuilding)b;
                    Unit            u  = FB.SpawnUnit();

                    if (FB.FactionType == 0 && redResources > FB.SpawnCost)
                    {
                        if (round % FB.SpawnSpeed == 0)
                        {
                            map.units.Add(u);

                            if (u is MeleeUnit)
                            {
                                MeleeUnit M = (MeleeUnit)u;

                                M.MapHeight = mapHeight;
                                M.MapWidth  = mapWidth;
                                map.Units.Add(M);
                            }
                            else if (u is RangedUnit)
                            {
                                RangedUnit R = (RangedUnit)u;

                                R.MapHeight = mapHeight;
                                R.MapWidth  = mapWidth;
                                map.Units.Add(R);
                            }
                            redResources -= FB.SpawnCost;
                        }
                    }
                    else if (FB.FactionType == 1 && blueResources > FB.SpawnCost)
                    {
                        if (round % FB.SpawnSpeed == 0)
                        {
                            if (u is MeleeUnit)
                            {
                                MeleeUnit M = (MeleeUnit)u;

                                map.Units.Add(M);
                            }
                            else if (u is RangedUnit)
                            {
                                RangedUnit R = (RangedUnit)u;

                                map.Units.Add(R);
                            }
                            blueResources -= FB.SpawnCost;
                        }
                    }
                }
            }
            foreach (Unit u in map.units)
            {
                u.CheckAttackRange(map.units, map.buildings);
            }

            round++;
            CheckDeath();
            Display();
        }
        else
        {
            Display();
            runGame = false;

            if (red > blue)
            {
                txtWinText.text = "Red Wins!";
            }
            else
            {
                txtWinText.text = "Blue Wins!";
            }
        }
    }