Пример #1
0
 //Deals damage to closest unit if they are in attack range
 public override void Combat(int type)
 {
     if (type == 0)
     {
         if (closestUnit is MeleeUnit)
         {
             MeleeUnit M = (MeleeUnit)closestUnit;
             M.Health -= Attack;
         }
         else if (closestUnit is RangedUnit)
         {
             RangedUnit R = (RangedUnit)closestUnit;
             R.Health -= Attack;
         }
         else if (closestUnit is WizardUnit)
         {
             WizardUnit W = (WizardUnit)closestUnit;
             W.Health -= Attack;
         }
     }
     else if (type == 1)
     {
         if (closestBuilding is FactoryBuilding)
         {
             FactoryBuilding FB = (FactoryBuilding)closestBuilding;
             FB.Health -= Attack;
         }
         else if (closestBuilding is ResourceBuilding)
         {
             ResourceBuilding RB = (ResourceBuilding)closestBuilding;
             RB.Health -= Attack;
         }
     }
 }
Пример #2
0
        /// <summary>
        /// Places a resource building inside the region.
        /// </summary>
        /// <param name="building"></param>
        /// <param name="canWalk"></param>
        public void PlaceResourceBuilding(ResourceBuilding building, int[,] canWalk)
        {
            Block[] blocks = RateRegionTiles(canWalk);

            // DEFINERER BYGGNINGSTYPEN TIL HVER TILE:
            for (int i = 0; i < economy.woodMineCount; i++)
            {
                float minDistance = building.MinDistFromTown;
                float maxDistance = building.MaxDistFromTown;

                for (int j = 0; j < GetArea(); j++)
                {
                    float distance = blocks[j].GetDistanceFromCastle();

                    if (blocks[j].CanPlaceBuilding(building.ShapeType))
                    {
                        if (distance >= minDistance && distance <= maxDistance)
                        {
                            // KLAR TIL Å PLASSERE
                            building.Origo = (blocks[j].GetPosition());
                            building.FlipCanWalk(canWalk);

                            // Plasserer bygning.
                            buildings.Add(building);
                            break;
                        }
                        // TODO: CANT PLACE.
                    }
                }
            }
        }
Пример #3
0
 // adds a building to the appropriate dictionary
 public void addBuilding(Tuple t, Building b)
 {
     if (b.GetType() == typeof(HeadQuarterBuilding))
     {
         HeadQuarterBuilding head = (HeadQuarterBuilding)b;
         hq           = head;
         hqLocation.x = t.x;
         hqLocation.y = t.y;
     }
     else if (b.GetType() == typeof(DecorativeBuilding))
     {
         DecorativeBuilding decBuilding = (DecorativeBuilding)b;
         decorativeBuildings.Add(t, decBuilding);
     }
     else if (b.GetType() == typeof(ResourceBuilding))
     {
         ResourceBuilding resBuilding = (ResourceBuilding)b;
         resourceBuildings.Add(t, resBuilding);
     }
     else if (b.GetType() == typeof(ResidenceBuilding))
     {
         ResidenceBuilding resBuilding = (ResidenceBuilding)b;
         residenceBuildings.Add(t, resBuilding);
     }
 }
Пример #4
0
    public void GenUnit()
    {
        ResourceBuilding resourceBuildingUsed = GameObject.FindObjectOfType <ResourceBuilding>();

        if (gameObject.tag == "Night Riders")
        {
            if (resourceBuildingUsed.generatedNR >= neededResources)
            {
                GameObject unit = Instantiate(generatedUnits[Random.Range(0, 2)]);
                unit.tag = "Night Riders";
                unit.GetComponent <MeshRenderer>().material = mat[0];
                unit.transform.position = this.transform.position;
            }
        }
        else if (gameObject.tag == "Day Walkers")
        {
            if (resourceBuildingUsed.generatedDW >= neededResources)
            {
                GameObject unit = Instantiate(generatedUnits[Random.Range(0, 2)]);
                unit.tag = "Day Walkers";
                unit.GetComponent <MeshRenderer>().material = mat[1];
                unit.transform.position = this.transform.position;
            }
        }
    }
Пример #5
0
    public void UpdateDisplay()
    {
        DrawBlankMap();

        foreach (GameObject unit in units)
        {
            if (unit.GetComponent <Unit>() != null)
            {
                Unit lUnit = unit.GetComponent <Unit>();
                PlaceUnit(unit, lUnit.xPosition, lUnit.yPosition);
            }
            else if (unit.GetComponent <WizardUnit>() != null)
            {
                WizardUnit lUnit = unit.GetComponent <WizardUnit>();
                PlaceUnit(unit, lUnit.xPosition, lUnit.yPosition);
            }
        }

        foreach (GameObject building in buildings)
        {
            if (building.GetComponent <FactoryBuilding>() != null)
            {//place Factories
                FactoryBuilding lBuilding = building.GetComponent <FactoryBuilding>();
                PlaceUnit(building, lBuilding.xPosition, lBuilding.yPosition);
            }
            if (building.GetComponent <ResourceBuilding>() != null)
            {//Place Resource Buildings
                ResourceBuilding lBuilding = building.GetComponent <ResourceBuilding>();
                PlaceUnit(building, lBuilding.xPosition, lBuilding.yPosition);
            }
        }
    }
Пример #6
0
    public Map()
    {
        marrUnits = new MeleeUnit[10];
        rarrUnits = new RangedUnit[10];
        warrUnits = new WizardUnit[10];


        for (int k = 0; k < 10; k++)
        {
            {
                marrUnits[k] = new MeleeUnit(r.Next(0, 20), r.Next(0, 20), "rogue", "m", "def");
                rarrUnits[k] = new RangedUnit(r.Next(0, 20), r.Next(0, 20), "viking", "r", "def");
                warrUnits[k] = new WizardUnit(r.Next(0, 20), r.Next(0, 20), "wizard", "w", "def");
            }
        }
        res  = new ResourceBuilding[5];
        fact = new FactoryBuilding[5];

        for (int j = 0; j < 5; j++)
        {
            {
                res[j]  = new ResourceBuilding(r.Next(0, 20), r.Next(0, 20), "rogue", "r");
                fact[j] = new FactoryBuilding(r.Next(0, 20), r.Next(0, 20), "viking", "f");
                res[j]  = new ResourceBuilding(r.Next(0, 20), r.Next(0, 20), "wizard", "r");
            }
        }
    }
Пример #7
0
    public override (Building, int) ClosestBuilding(List <Building> buildings)
    {
        int      shortest = 100;
        Building closest  = Spawn;

        //Closest Building and Distance
        foreach (Building b in buildings)
        {
            if (b is FactoryBuilding)
            {
                FactoryBuilding fb       = (FactoryBuilding)b;
                int             distance = Math.Abs(this.xPos - fb.xPos)
                                           + Math.Abs(this.yPos - fb.yPos);
                if (distance < shortest)
                {
                    shortest = distance;
                    closest  = fb;
                }
            }
            else if (b is ResourceBuilding)
            {
                ResourceBuilding rb = (ResourceBuilding)b;
                int distance        = Math.Abs(this.xPos - rb.xPos)
                                      + Math.Abs(this.yPos - rb.yPos);
                if (distance < shortest)
                {
                    shortest = distance;
                    closest  = rb;
                }
            }
        }
        return(closest, shortest);
    }
Пример #8
0
 public void Generate()
 {
     for (int i = 0; i < NumBuildings; i++)
     {
         if (random.Next(0, 2) == 0)
         {
             if (random.Next(0, 2) == 0)
             {
                 ResourceBuilding r = new ResourceBuilding(random.Next(0, mapWidth), random.Next(0, mapHeight), 20, 0, "{}", random.Next(0, 3), 0, 10, 500);
                 Buildings.Add(r);
             }
             else
             {
                 FactoryBuilding f = new FactoryBuilding(random.Next(0, mapWidth), random.Next(0, mapHeight), 15, 0, "[]", random.Next(0, 3), 4);
                 Buildings.Add(f);
             }
         }
         else
         {
             if (random.Next(0, 2) == 0)
             {
                 ResourceBuilding r = new ResourceBuilding(random.Next(0, mapWidth), random.Next(0, mapHeight), 20, 1, "{}", random.Next(0, 3), 0, 10, 500);
                 Buildings.Add(r);
             }
             else
             {
                 FactoryBuilding f = new FactoryBuilding(random.Next(0, mapWidth), random.Next(0, mapHeight), 15, 1, "[]", random.Next(0, 3), 4);
                 Buildings.Add(f);
             }
         }
     }
 }
Пример #9
0
    public void InfoClick()
    {
        Ray          ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, Mathf.Infinity);

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

            foreach (Unit u in map.Units)
            {
                if (u is MeleeUnit)
                {
                    MeleeUnit mu = (MeleeUnit)u;
                    if (mu.xPos == mouseX && mu.yPos == mouseY)
                    {
                        Info.text = mu.Info();
                    }
                }
                else if (u is RangedUnit)
                {
                    RangedUnit ru = (RangedUnit)u;
                    if (ru.xPos == mouseX && ru.yPos == mouseY)
                    {
                        Info.text = ru.Info();
                    }
                }
                else if (u is WizzardUnit)
                {
                    WizzardUnit wu = (WizzardUnit)u;
                    if (wu.xPos == mouseX && wu.yPos == mouseY)
                    {
                        Info.text = wu.Info();
                    }
                }
            }

            foreach (Building bg in map.Buildings)
            {
                if (bg is FactoryBuilding)
                {
                    FactoryBuilding fb = (FactoryBuilding)bg;
                    if (fb.xPos == mouseX && fb.yPos == mouseY)
                    {
                        Info.text = fb.Info();
                    }
                }
                else if (bg is ResourceBuilding)
                {
                    ResourceBuilding rb = (ResourceBuilding)bg;
                    if (rb.xPos == mouseX && rb.yPos == mouseY)
                    {
                        Info.text = rb.Info();
                    }
                }
            }
        }
    }
Пример #10
0
    // Update is called once per frame
    void Update()
    {
        healthBar.fillAmount = ((float)hp / maxHp);
        DeathCheck();
        if (Random.Range(0, 9) < 3)
        {
            GameObject[] objects = (GameObject[])Object.FindObjectsOfType(typeof(GameObject));
            foreach (GameObject node in objects)
            {
                resources = null;
                resources = node.GetComponent <Resources>();
                if (resources != null)
                {
                    break;
                }
            }
            Debug.Log(resources.TotalTeam1Out);


            foreach (GameObject node in objects)
            {
                resourceBuilding = node.GetComponent <ResourceBuilding>();
                if (resourceBuilding != null && resourceBuilding.Team == this.team)
                {
                    switch (resourceBuilding.Team)
                    {
                    case 1:
                        if (resources.TotalTeam1Out >= spawnCost)
                        {
                            SpawnUnit();
                            resourceBuilding.Generated -= spawnCost;
                            resources.TotalTeam1Out    -= spawnCost;
                        }
                        break;

                    case 2:
                        if (resources.TotalTeam2Out >= spawnCost)
                        {
                            SpawnUnit();
                            resourceBuilding.Generated -= spawnCost;
                            resources.TotalTeam2Out    -= spawnCost;
                        }
                        break;

                    case 3:
                        if (resources.TotalTeam3Out >= spawnCost)
                        {
                            SpawnUnit();
                            resourceBuilding.Generated -= spawnCost;
                            resources.TotalTeam3Out    -= spawnCost;
                        }
                        break;
                    }
                }
            }
        }
    }
Пример #11
0
    public Map(int maxX, int maxY, int numUnits, int numBuildings) // these will create the archer and melee units and place them within the units array
    {
        int buildingX, buildingY;

        units     = new Unit[numUnits];
        buildings = new Building[numBuildings];
        for (int i = 0; i < numUnits; i++)
        {
            if (i <= 10)
            {
                MeleeUnit M = new MeleeUnit(r.Next(0, maxX), r.Next(0, maxY), r.Next(10, 20) * 10, r.Next(10, 30), 1, 1, i % 2, "M", "Knight");
                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, "R", "Archer");
                Units[i] = R;
            }
            if (i == 21)
            {
                WizardUnit W = new WizardUnit(r.Next(0, maxX), r.Next(0, maxY), r.Next(25, 35) * 10, r.Next(20, 40), 1, 1, 0, "W", "Wizard");
                Units[i] = W;
            }
            if (i == 22)
            {
                WizardUnit W = new WizardUnit(r.Next(0, maxX), r.Next(0, maxY), r.Next(25, 35) * 10, r.Next(20, 40), 1, 1, 1, "W", "Wizard");
                Units[i] = W;
            }
            if (i > 22 && i <= 27)
            {
                MeleeUnit MN = new MeleeUnit(r.Next(0, maxX), r.Next(0, maxY), r.Next(10, 20) * 10, r.Next(10, 30), 1, 1, 2, "M", "Knight");
                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, "R", "Archer");
                Units[i] = RN;
            }
        }

        for (int i = 0; i < numBuildings; i++) // these will create the buildings that will then be put into the buildings array
        {
            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, "FB", 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, "RB", "Gold", r.Next(5, 15), r.Next(100, 400));
                Buildings[i] = rb;
            }
        }
    }
Пример #12
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;
            }
        }
    }
Пример #13
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //Saves all of the game data in a text file
            string saveString;



            saveString = "";

            Directory.CreateDirectory("Saves");
            Directory.CreateDirectory("Saves/Units");
            Directory.CreateDirectory("Saves/Buildings");

            FileStream ufs = new FileStream("Saves/Units/units", FileMode.Create, FileAccess.Write);
            FileStream bfs = new FileStream("Saves/Buildings/buildings", FileMode.Create, FileAccess.Write);

            StreamWriter uwriter = new StreamWriter(ufs);

            for (int i = 0; i < gameEngine.map.arrUnits.Length; i++)
            {
                saveString = (gameEngine.map.arrUnits[i].symbol + "," + gameEngine.map.arrUnits[i].xPos + "," + gameEngine.map.arrUnits[i].yPos + "," + gameEngine.map.arrUnits[i].maxHP + "," + gameEngine.map.arrUnits[i].HP + "," + gameEngine.map.arrUnits[i].unitName + "," + gameEngine.map.arrUnits[i].team + "," + gameEngine.map.arrUnits[i].speed + "," + gameEngine.map.arrUnits[i].isAttacking + "," + gameEngine.map.arrUnits[i].attack + "," + gameEngine.map.arrUnits[i].attackRange);
                uwriter.WriteLine(saveString);
            }
            uwriter.Close();


            saveString = "";

            StreamWriter bwriter = new StreamWriter(bfs);

            for (int i = 0; i < gameEngine.map.arrBuildings.Length; i++)
            {
                string   buildingType = gameEngine.map.arrBuildings[i].GetType().ToString();
                string[] buildingArr  = buildingType.Split('.');
                buildingType = buildingArr[buildingArr.Length - 1];

                if (buildingType == "ResourceBuilding")
                {
                    ResourceBuilding bld = (ResourceBuilding)gameEngine.map.arrBuildings[i];
                    saveString = (bld.Symbol + "," + bld.XPos + "," + bld.YPos + "," + bld.Team + "," + bld.MaxHP + "," + bld.hP + "," + bld.resourceType + "," + bld.resourcesGeneratedPerRound + "," + bld.resourcesGenerated + "," + bld.resourcePool);
                }
                else
                {
                    FactoryBuilding bld = (FactoryBuilding)gameEngine.map.arrBuildings[i];
                    saveString = (bld.Symbol + "," + bld.XPos + "," + bld.YPos + "," + bld.Team + "," + bld.MaxHP + "," + bld.hP + "," + bld.productionSpeed + "," + bld.spawnYPos + "," + bld.unitToProduce + "," + bld.unitsProduced);
                }
                bwriter.WriteLine(saveString);
            }
            bwriter.Close();

            ufs.Close();
            bfs.Close();
        }
Пример #14
0
 public void AddResourceContainer(ResourceBuilding building)
 {
     building.Resource.ResourceChanged += UpdateCachedResources;
     // Cache all of the buildings current resources
     foreach (ResourceType t in building.Resource.CurrentResources.Keys)
     {
         UpdateCachedResources(t, building.Resource.CurrentResources[t]);
     }
     // Cache this Resource Containers position
     // Being a building type, it should never move.
     _resourcePositions.Add(building.transform.position);
     // Add the resource reference to the city's current resource pool
     _resources.Add(building.Resource);
 }
Пример #15
0
        public static void DestroyBuilding(int camp_id, int b_id, int type)
        {
            /*
             * 1 - resource
             * 2 - offensive
             * 3 - defensive
             * 4 - utility
             */

            using (var db = new MinionWarsEntities())
            {
                Camp camp = db.Camp.Find(camp_id);

                switch (type)
                {
                case 1:
                    ResourceBuilding rb = db.ResourceBuilding.Find(b_id);

                    UserTreasury ut = db.UserTreasury.Where(x => x.user_id == camp.owner_id && x.res_id == rb.rtype_id).First();
                    ut.generation -= 5;
                    db.UserTreasury.Attach(ut);
                    db.Entry(ut).State = System.Data.Entity.EntityState.Modified;

                    db.ResourceBuilding.Remove(rb);

                    break;

                case 2:
                    db.OffensiveBuilding.Remove(db.OffensiveBuilding.Find(b_id));
                    break;

                case 3:
                    db.DefensiveBuilding.Remove(db.DefensiveBuilding.Find(b_id));
                    break;

                case 4:
                    db.UtilityBuilding.Remove(db.UtilityBuilding.Find(b_id));
                    break;
                }

                camp.building_count--;
                db.Camp.Attach(camp);
                db.Entry(camp).State = System.Data.Entity.EntityState.Modified;

                db.SaveChanges();
            }
        }
    public Unit Spawn(FactoryBuilding spawner, List <Building> builds)
    {
        ResourceBuilding res = (ResourceBuilding)builds[tempSpot];

        if (spawner.UnitType() == 0)
        {
            res.Pool -= 4;
            RangedUnit r = new RangedUnit(spawner.PosX, spawner.spawnPoint, "archer", 100, 1, 20, 5, spawner.Faction, "R");
            return(r);
        }
        else
        {
            res.Pool -= 5;
            MeleeUnit m = new MeleeUnit(spawner.PosX, spawner.spawnPoint, "soldier", 100, 1, 20, spawner.Faction, "M");
            return(m);
        }
    }
Пример #17
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);
    }
Пример #18
0
    public bool IsDead()
    {
        bool             dead = false;
        ResourceBuilding resourceBuildingUsed = GameObject.FindObjectOfType <ResourceBuilding>();

        if (this.BuildingHp <= 0)
        {
            GameObject.Destroy(gameObject);
            if (gameObject.tag == "Day Walkers")
            {
                resourceBuildingUsed.generatedNR++;
            }
            else if (gameObject.tag == "Night Riders")
            {
                resourceBuildingUsed.generatedDW++;
            }
            dead = true;
        }

        return(dead);
    }
Пример #19
0
    public GameObject GenerateResourceBuilding(int aUnitNumber)
    {
        Vector2    point     = GetRandomOpenPosition();
        GameObject lBuilding = Instantiate(resourceBuilding, GetDisplayCoord((int)point.x, (int)point.y), Quaternion.identity);

        int xPos = (int)point.x;
        int yPos = (int)point.y;

        ResourceBuilding building = lBuilding.GetComponent <ResourceBuilding>();

        building.map       = this;
        building.name      = $"aUnitNumber";
        building.xPosition = xPos;
        building.yPosition = yPos;
        building.Health    = 12;
        building.resourcesGeneratedPerRound = 1;

        PlaceUnit(lBuilding, xPos, yPos);
        //buildings.Add(lBuilding);
        return(lBuilding);
    }
Пример #20
0
    public bool CompleteCollecting(Player player, GameObject resource)
    {
        if (!CanCompleteCollecting(player, resource))
        {
            return(false);
        }
        Debug.Log("completeCollecting");
        ResourceBuilding resourceType = resource.GetComponent <ResourceBuilding>();

        GameObject cube = null;

        switch (resourceType.resourceEnum)
        {
        case ResourceEnum.Coal:
            cube = GameObject.Instantiate(coalCubePrefab, player.transform);
            break;

        case ResourceEnum.Ore:
            cube = GameObject.Instantiate(oreCubePrefab, player.transform);
            break;

        case ResourceEnum.Rock:
            cube = GameObject.Instantiate(rockCubePrefab, player.transform);
            break;

        case ResourceEnum.Wood:
            cube = GameObject.Instantiate(woodCubePrefab, player.transform);
            break;
        }

        cube.transform.SetPositionAndRotation(cube.transform.position + player.transform.forward * 2.0f, cube.transform.rotation);

        InteractiveObject item = cube.GetComponent <InteractiveObject>();

        player.GetComponent <Player>().SetCarryingItem(item);

        CleanMap(player, resource);

        return(true);
    }
Пример #21
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;
        }
    }
Пример #22
0
    public void CreateResourceBuilding(int t_type)
    {
        int numOfTries = 30;

        for (int i = 0; i < numOfTries; i++)
        {
            int index = Random.Range(0, m_resourceTiles.Count);

            if (m_resourceTiles[index].GetResourceTile().GetResourceType() == (ResourceType)t_type)
            {
                ResourceBuilding resourceBuilding = Instantiate(m_resourceBuildingPrefab).GetComponent <ResourceBuilding>();
                resourceBuilding.GetComponent <ResourceBuilding>().Initialize(m_resourceTiles[index], this);
                AddResourceBuilding(resourceBuilding);
                if (m_resourceTiles[index].GetResourceTile().GetResourceType() == ResourceType.Horses)
                {
                    m_enabledStables = true;
                }
                m_resourceTiles.RemoveAt(index);
                return;
            }
        }
    }
Пример #23
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
        }
    }
Пример #24
0
    public SecondaryResourceBuildingList()
    {
        resourceList = new ResourceList();
        buildings    = new Dictionary <string, Building>();
        var ArableFarm = new ResourceBuilding(
            "Arable Farm", "Secondary Resource", "Tertiary Resource", "Produces grain", true, 3, 2,
            new Dictionary <string, int> {
            { "Lumber", 50 },
            { "Grain", 30 }
        }
            );

        ArableFarm.statBonusOrdering = "srdfa";
        ArableFarm.bonusStat         = "strength";
        ArableFarm.startingResources = new Dictionary <string, Resource> {
            { "Grain", resourceList.Grain },
            { "Clay", resourceList.Clay }
        };
        ArableFarm.spawnChance = new Dictionary <string, int> {
            { "Grain", 5 },
            { "Clay", 95 }
        };
        buildings.Add("Arable Farm", ArableFarm);
    }
Пример #25
0
    // Start is called before the first frame update
    void Start()
    {
        map = new Map(20, 6, 20, 20);
        map.Generate();

        foreach (Building B in map.buildings)
        {
            if (B is ResourceBuilding)
            {
                ResourceBuilding RB = (ResourceBuilding)B;
                if (RB.FactionType == 0)
                {
                    redResourcesLeft += RB.ResresourcesLeft;
                }
                else if (RB.FactionType == 1)
                {
                    blueResourcesLeft += RB.ResresourcesLeft;
                }
            }
        }
        Display();
        round = 0;
        ResourceDisplay();
    }
Пример #26
0
 /**
  * Copypasta code for now. make it more modular later
  */
 public bool ResourceGain(int amount, ResourceBuilding.ResourceType type)
 {
     int dummy;
     bool pay;
     switch (type) {
         case ResourceBuilding.ResourceType.fire:
             dummy = SaveState.state.fire;
             pay = ManageSlider(amount, ref dummy, SaveState.state.maxFire, GetSliderByName("Fire Slider"));
             GetTextByName("FireCount").text = "" + dummy;
             SaveState.state.fire = dummy;
             break;
         case ResourceBuilding.ResourceType.water:
             dummy = SaveState.state.water;
             pay = ManageSlider(amount, ref dummy, SaveState.state.maxWater, GetSliderByName("Water Slider"));
             GetTextByName("WaterCount").text = "" + dummy;
             SaveState.state.water = dummy;
             break;
         case ResourceBuilding.ResourceType.air:
             dummy = SaveState.state.air;
             pay = ManageSlider(amount, ref dummy, SaveState.state.maxAir, GetSliderByName("Wind Slider"));
             GetTextByName("AirCount").text = "" + dummy;
             SaveState.state.air = dummy;
             break;
         case ResourceBuilding.ResourceType.earth:
             dummy = SaveState.state.earth;
             pay = ManageSlider(amount, ref dummy, SaveState.state.maxEarth, GetSliderByName("Earth Slider"));
             GetTextByName("EarthCount").text = "" + dummy;
             SaveState.state.earth = dummy;
             break;
         default:
             Debug.LogError("ResourceIncrementer: Illegal resource type");
             pay = false;
             break;
     }
     return pay;
 }
 /**
  * Spends a certain amount of a given resource, return value determines if subtraction was successful
  * type refers to which type of resource you are spending
  * amount obviously refers to the amount you are withdrawing
  */
 public bool spendResource(ResourceBuilding.ResourceType type, int amount)
 {
     switch(type) {
         case ResourceBuilding.ResourceType.fire:
             if (amount > SaveState.state.fire)
                 return false;
             else {
                 SaveState.state.fire -= amount;
                 return true;
             }
         case ResourceBuilding.ResourceType.air:
             if (amount > SaveState.state.air)
                 return false;
             else {
                 SaveState.state.air -= amount;
                 return true;
             }
         case ResourceBuilding.ResourceType.water:
             if (amount > SaveState.state.water)
                 return false;
             else {
                 SaveState.state.water -= amount;
                 return true;
             }
         case ResourceBuilding.ResourceType.earth:
             if (amount > SaveState.state.earth)
                 return false;
             else {
                 SaveState.state.earth -= amount;
                 return true;
             }
     default:
             Debug.LogError("ResourceManager => spendResource: Illegal resource type");
             return false;
     }
 }
Пример #28
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;
                }
            }
        }
    }
Пример #29
0
 public void AddResourceBuilding(ResourceBuilding t_resourceBuilding)
 {
     m_resourceBuildings.Add(t_resourceBuilding);
 }
Пример #30
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            //Loads saved simulation from textfile into program and initializes the simulation
            load = true;
            int count;

            FileStream ufs = new FileStream("Saves/Units/units", FileMode.Open, FileAccess.Read);
            FileStream bfs = new FileStream("Saves/Buildings/buildings", FileMode.Open, FileAccess.Read);

            StreamReader usr = new StreamReader(ufs);
            StreamReader bsr = new StreamReader(bfs);

            for (int i = 0; i < 20; i++)
            {
                for (int k = 0; k < 20; k++)
                {
                    gameEngine.map.arrMap[i, k] = ',';
                }
            }

            count = File.ReadAllLines("Saves/Units/units").Length;
            gameEngine.map.arrUnits = new unit[count];
            for (int i = 0; i < count; i++)
            {
                string line = usr.ReadLine();



                string[] arrline = line.Split(',');

                char   uSymbol     = Convert.ToChar(arrline[0]);
                int    x           = Convert.ToInt32(arrline[1]);
                int    y           = Convert.ToInt32(arrline[2]);
                int    Maxhp       = Convert.ToInt32(arrline[3]);
                int    HP          = Convert.ToInt32(arrline[4]);
                string Name        = (arrline[5]);
                string Team        = (arrline[6]);
                int    Speed       = Convert.ToInt32(arrline[7]);
                bool   IsAttacking = Convert.ToBoolean(arrline[8]);
                int    Attack      = Convert.ToInt32(arrline[9]);
                int    AttackRange = Convert.ToInt32(arrline[10]);


                if (uSymbol == 'x' || uSymbol == 'X')
                {
                    MeleeUnit un = new MeleeUnit(Name, x, y, HP, Speed, Attack, AttackRange, Team, uSymbol, IsAttacking);
                    gameEngine.map.arrUnits[i] = un;
                    gameEngine.map.arrMap[un.xPos, un.yPos] = un.symbol;
                }
                else if (uSymbol == 'o' || uSymbol == 'O')
                {
                    RangedUnit un = new RangedUnit(Name, x, y, HP, Speed, Attack, AttackRange, Team, uSymbol, IsAttacking);
                    gameEngine.map.arrUnits[i] = un;
                    gameEngine.map.arrMap[un.xPos, un.yPos] = un.symbol;
                }
                else
                {
                    Wizard un = new Wizard(Name, x, y, HP, Speed, Attack, AttackRange, Team, uSymbol, IsAttacking);
                    gameEngine.map.arrUnits[i] = un;
                    gameEngine.map.arrMap[un.xPos, un.yPos] = un.symbol;
                }
            }

            ufs.Close();
            usr.Close();

            count = File.ReadAllLines("Saves/Buildings/buildings").Length;
            gameEngine.map.arrBuildings = new Building[count];
            for (int i = 0; i < count; i++)
            {
                string line = bsr.ReadLine();



                string[] arrline = line.Split(',');

                char   bSymbol = Convert.ToChar(arrline[0]);
                int    x       = Convert.ToInt32(arrline[1]);
                int    y       = Convert.ToInt32(arrline[2]);
                string team    = (arrline[3]);
                int    maxHP   = Convert.ToInt32(arrline[4]);
                int    HP      = Convert.ToInt32(arrline[5]);


                if (bSymbol == 'F')
                {
                    int    Production     = Convert.ToInt32(arrline[6]);
                    int    Yspawn         = Convert.ToInt32(arrline[7]);
                    string UnitProduction = (arrline[8]);
                    int    unitsProduced  = Convert.ToInt32(arrline[9]);

                    FactoryBuilding bld = new FactoryBuilding(x, y, HP, team, bSymbol, UnitProduction, Production, Yspawn);
                    gameEngine.map.arrBuildings[i]            = bld;
                    gameEngine.map.arrMap[bld.XPos, bld.YPos] = bld.Symbol;
                }
                else
                {
                    string Resource      = (arrline[6]);
                    int    GatheringRate = Convert.ToInt32(arrline[7]);
                    int    Gathered      = Convert.ToInt32(arrline[8]);
                    int    ResourcePool  = Convert.ToInt32(arrline[9]);

                    ResourceBuilding bld = new ResourceBuilding(x, y, HP, team, bSymbol, Resource, Gathered, GatheringRate, ResourcePool);
                    gameEngine.map.arrBuildings[i]            = bld;
                    gameEngine.map.arrMap[bld.XPos, bld.YPos] = bld.Symbol;
                }
            }
            bfs.Close();
            bsr.Close();
            lblMap.Text = gameEngine.map.MapDisplay();
            timer1.Start();
        }
Пример #31
0
        //CLASS METHODS
        public void RandomBattlefield()
        {
            int randomX, randomY;
            int random;

            randomX = 1;
            randomY = 1;

            arrUnits     = new unit[sumUnits];
            arrBuildings = new Building[sumBuildings];
            Random rnd = new Random();

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

            for (int i = 0; i < sumUnits; i++)
            {
                randomX = rnd.Next(0, 20);
                randomY = rnd.Next(0, 20);


                random = rnd.Next(1, 5);

                while (arrMap[randomX, randomY] == 'x' || arrMap[randomX, randomY] == 'X' || arrMap[randomX, randomY] == 'o' || arrMap[randomX, randomY] == 'O')
                {
                    randomX = rnd.Next(0, 20);
                    randomY = rnd.Next(0, 20);
                }

                if (random == 1)
                {
                    MeleeUnit unit = new MeleeUnit("Knight", randomX, randomY, 100, 1, 5, 1, "Team1", 'X', false);
                    arrMap[unit.xPos, unit.yPos] = unit.symbol;
                    arrUnits[i] = unit;
                }
                else if (random == 2)
                {
                    MeleeUnit unit = new MeleeUnit("Knight", randomX, randomY, 100, 1, 5, 1, "Team2", 'x', false);
                    arrMap[unit.xPos, unit.yPos] = unit.symbol;
                    arrUnits[i] = unit;
                }
                else if (random == 3)
                {
                    RangedUnit unit = new RangedUnit("Archer", randomX, randomY, 80, 1, 3, 3, "Team1", 'O', false);
                    arrMap[unit.xPos, unit.yPos] = unit.symbol;
                    arrUnits[i] = unit;
                }
                else
                {
                    RangedUnit unit = new RangedUnit("Archer", randomX, randomY, 80, 1, 3, 3, "Team2", 'o', false);
                    arrMap[unit.xPos, unit.yPos] = unit.symbol;
                    arrUnits[i] = unit;
                }
            }

            for (int k = 0; k < sumBuildings; k++)
            {
                randomX = rnd.Next(0, 20);
                randomY = rnd.Next(0, 20);

                while (arrMap[randomX, randomY] == 'x' || arrMap[randomX, randomY] == 'X' || arrMap[randomX, randomY] == 'o' || arrMap[randomX, randomY] == 'O')
                {
                    randomX = rnd.Next(0, 20);
                    randomY = rnd.Next(0, 20);
                }

                random = rnd.Next(1, 7);

                int spawnYPos;
                spawnYPos = 0;

                if (randomY == 19)
                {
                    spawnYPos = 18;
                }
                else if (randomY == 0)
                {
                    spawnYPos = 1;
                }
                else
                {
                    spawnYPos = randomY - 1;
                }

                if (random == 1)
                {
                    ResourceBuilding building = new ResourceBuilding(randomX, randomY, 200, "Team1", 'R', "Tiberuim", 0, 5, 2000);
                    arrMap[building.xPos, building.yPos] = building.symbol;
                    arrBuildings[k] = building;
                }
                else if (random == 2)
                {
                    ResourceBuilding building = new ResourceBuilding(randomX, randomY, 200, "Team2", 'R', "Tiberuim", 0, 5, 2000);
                    arrMap[building.xPos, building.yPos] = building.symbol;
                    arrBuildings[k] = building;
                }
                else if (random == 3)
                {
                    FactoryBuilding building = new FactoryBuilding(randomX, randomY, 200, "Team1", 'F', "Melee Unit", 10, spawnYPos);
                    arrMap[building.xPos, building.yPos] = building.symbol;
                    arrBuildings[k] = building;
                }
                else if (random == 4)
                {
                    FactoryBuilding building = new FactoryBuilding(randomX, randomY, 200, "Team1", 'F', "Ranged Unit", 10, spawnYPos);
                    arrMap[building.xPos, building.yPos] = building.symbol;
                    arrBuildings[k] = building;
                }
                else if (random == 5)
                {
                    FactoryBuilding building = new FactoryBuilding(randomX, randomY, 200, "Team2", 'F', "Melee Unit", 10, spawnYPos);
                    arrMap[building.xPos, building.yPos] = building.symbol;
                    arrBuildings[k] = building;
                }
                else
                {
                    FactoryBuilding building = new FactoryBuilding(randomX, randomY, 200, "Team2", 'F', "Ranged  Unit", 10, spawnYPos);
                    arrMap[building.xPos, building.yPos] = building.symbol;
                    arrBuildings[k] = building;
                }
            }
        }
    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);
            }
        }
    }
 public ResourceBuildingViewModel(int level, ResourceBuilding building)
     : base(level, building)
 {
     this.ResourceIncome = building.ResourceGeneration[level];
     this.NextResourceIncome = building.ResourceGeneration[level + 1];
 }
Пример #34
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();
                }
            }
        }
    }