Ejemplo n.º 1
0
 public Direction Directionto(Unit u) // this will find the direction to move towards
 {
     if (u.GetType() == typeof(MeeleeUnit))
     {
         MeeleeUnit m = (MeeleeUnit)u;
         if (m.PosX < PosX)
         {
             return(Direction.North);
         }
         else if (m.PosX > PosX)
         {
             return(Direction.South);
         }
         else if (m.PosY < PosY)
         {
             return(Direction.West);
         }
         else
         {
             return(Direction.East);
         }
     }
     else
     {
         return(Direction.North);
     }
 }
Ejemplo n.º 2
0
    public Unit Spawner(int maxX, int maxY, int faction)
    {
        Random     r = new Random();
        MeeleeUnit M = new MeeleeUnit(r.Next(0, maxX), r.Next(0, maxY), r.Next(5, 10) * 10, r.Next(5, 20), 1, 1, faction, "M", "Knight");

        return(M);
    }
Ejemplo n.º 3
0
    public Map(int maxX, int maxY, int numUnits, int numBuildings)
    {
        int buildingX, buildingY;

        units     = new Unit[numUnits];
        buildings = new Building[numBuildings];
        for (int i = 0; i < numUnits; i++)
        {
            if (i <= 10)
            {
                MeeleeUnit M = new MeeleeUnit(r.Next(0, maxX), r.Next(0, maxY), r.Next(10, 20) * 10, r.Next(10, 30), 1, 1, i % 2, "blue tank.png", "Tank");
                Units[i] = M;
            }
            if (i > 10 && i <= 20)
            {
                RangedUnit R = new RangedUnit(r.Next(0, maxX), r.Next(0, maxY), r.Next(10, 20) * 10, r.Next(10, 30), 1, 1, i % 2, "blue archer.png", "Archer");
                Units[i] = R;
            }
            if (i == 21)
            {
                WarlockUnit W = new WarlockUnit(r.Next(0, maxX), r.Next(0, maxY), r.Next(25, 35) * 10, r.Next(20, 40), 1, 1, 0, "blue warlock.png", "Warlock");
                Units[i] = W;
            }
            if (i == 22)
            {
                WarlockUnit W = new WarlockUnit(r.Next(0, maxX), r.Next(0, maxY), r.Next(25, 35) * 10, r.Next(20, 40), 1, 1, 1, "red warlock.png", "Warlock");
                Units[i] = W;
            }
            if (i > 22 && i <= 27)
            {
                MeeleeUnit MN = new MeeleeUnit(r.Next(0, maxX), r.Next(0, maxY), r.Next(10, 20) * 10, r.Next(10, 30), 1, 1, 2, "red tank.png", "Tank");
                Units[i] = MN;
            }
            if (i > 27)
            {
                RangedUnit RN = new RangedUnit(r.Next(0, maxX), r.Next(0, maxY), r.Next(10, 20) * 10, r.Next(10, 30), 1, 1, 2, "red archer.png", "Archer");
                Units[i] = RN;
            }
        }

        for (int i = 0; i < numBuildings; i++)
        {
            if (i <= 5)
            {
                buildingX = r.Next(0, maxX);
                buildingY = r.Next(0, maxX);
                FactoryBuilding fb = new FactoryBuilding(buildingX, r.Next(0, maxY), r.Next(5, 10) * 10, i % 2, "blue factory.png", r.Next(0, 1), r.Next(5, 10), buildingX + 1, buildingY + 1);
                Buildings[i] = fb;
            }

            if (i > 5 && i <= 10)
            {
                ResourceBuilding rb = new ResourceBuilding(r.Next(0, maxX), r.Next(0, maxY), r.Next(5, 10) * 10, i % 2, "blue building.png", "Iron", r.Next(5, 15), r.Next(100, 400));
                Buildings[i] = rb;
            }
        }
    }
Ejemplo n.º 4
0
 private int DistanceTo(Unit u) //uses the manhatten distance method to calculate distance
 {
     if (u.GetType() == typeof(MeeleeUnit))
     {
         MeeleeUnit m = (MeeleeUnit)u;
         int        d = Math.Abs(PosX - m.PosX) + Math.Abs(PosY - m.PosY);
         return(d);
     }
     else
     {
         return(0);
     }
 }
Ejemplo n.º 5
0
 public override bool withinRange(Unit u) //this checks to see which enemies are within the range of the unit
 {
     if (u.GetType() == typeof(MeeleeUnit))
     {
         MeeleeUnit M = (MeeleeUnit)u;
         if (DistanceTo(u) <= attackRange)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     return(false);
 }
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
    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.º 8
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);
                }
            }
        }
    }