Exemple #1
0
 public void Delete(BattleUnitsStack b)
 {
     for (int i = 0; i < a.Length(); i++)
     {
         if (a.getcArmy()[i] == b)
         {
             a.Remove(i);
             Destroy(transform.GetChild(i).gameObject);
             return;
         }
     }
 }
Exemple #2
0
        private void Awake()
        {
            Map        m;
            BattleArmy a1;
            BattleArmy a2;

            string[] MapBits   = PlayerPrefs.GetString("Map").Split(' ');
            string[] Army1Bits = PlayerPrefs.GetString("Army1").Split(' ');
            string[] Army2Bits = PlayerPrefs.GetString("Army2").Split(' ');

            int h = Convert.ToInt32(MapBits[0]);
            int w = Convert.ToInt32(MapBits[1]);


            int a1Size = Convert.ToInt32(Army1Bits[0]);
            int a2Size = Convert.ToInt32(Army2Bits[0]);

            UnitsStack[] A1 = new UnitsStack[a1Size];
            UnitsStack[] A2 = new UnitsStack[a2Size];

            for (int z = 1, i = 0; i < a1Size; i++, z++)
            {
                if (Army1Bits[z].Equals("0"))
                {
                    A1[i] = null;
                }
                else
                {
                    A1[i] = new UnitsStack(new Unit(Army1Bits[z + 1]), Convert.ToInt32(Army1Bits[z]));
                    z++;
                }
            }

            for (int z = 1, i = 0; i < a2Size; i++, z++)
            {
                if (Army2Bits[z].Equals("0"))
                {
                    A2[i] = null;
                }
                else
                {
                    A2[i] = new UnitsStack(new Unit(Army2Bits[z + 1]), Convert.ToInt32(Army2Bits[z]));
                    z++;
                }
            }

            a1    = new BattleArmy(true, A1);
            a2    = new BattleArmy(false, A2);
            m     = new Map(h, w);
            map   = GameObject.FindWithTag("Map");
            army1 = GameObject.FindWithTag("Units1");
            army2 = GameObject.FindWithTag("Units2");


            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    var cellClone = Instantiate(CellPrefab, map.transform);
                    cellClone.transform.name = "Cell(" + (i + 1) + "," + (j + 1) + ")";
                    char bit = MapBits[2][i * w + j];

                    m.setMapCell(i, j, bit == '1' ? CellContent.STONE : CellContent.FREE);
                }
            }

            foreach (BattleUnitsStack bus in a1.getcArmy())
            {
                int i = bus.getcPos().getX;
                int j = bus.getcPos().getY;

                var busClone = Instantiate(BUSPrefab, army1.transform);
                busClone.GetComponent <RectTransform>().localPosition = getPos(i, j);
                m.setMapCell(i, j, CellContent.UNIT1);
            }

            foreach (BattleUnitsStack bus in a2.getcArmy())
            {
                int i = bus.getcPos().getX;
                int j = bus.getcPos().getY;

                var busClone = Instantiate(BUSPrefab, army2.transform);
                busClone.GetComponent <RectTransform>().localPosition = getPos(i, j);
                m.setMapCell(i, j, CellContent.UNIT2);
            }

            map.GetComponent <uMap>().fill(m);
            army1.GetComponent <uBattleArmy>().fill(a1);
            army2.GetComponent <uBattleArmy>().fill(a2);
            battle    = new Battle(a1, a2, m);
            activeBUS = battle.Begin(true);
            map.GetComponent <uMap>().Recolor();
            activeSpell = -1;
            SpellsMenu.GetComponent <BattleMenu>().RefreshSpells(activeBUS);
        }