예제 #1
0
        //unitsToUpdate[unitType] = modifier
        public void UnitUpdate(int kingdom, Field field, Dictionary<int, int> unitsToUpdate)
        {
            IList<Unit> units = new UnitDAO().GetFromArea(field.MapId, field.FieldX, field.FieldY, 1, 1);

            HashSet<int> done = new HashSet<int>();

            foreach (Unit u in units)
            {
                bool mod = false;

                if (u.KingdomId != kingdom)
                {
                    mod = true;
                    u.Count = 0;
                }
                if (unitsToUpdate.ContainsKey(u.UnitTypeId))
                {
                    u.Count += unitsToUpdate[u.UnitTypeId];
                    done.Add(u.UnitTypeId);
                    mod = true;
                }

                //jesli zmodyfikowany to update
                if (mod)
                {
                    if (u.Count < 1)
                    {
                        new UnitDAO().Remove(u.UnitId);
                    }
                    else
                    {
                        new UnitDAO().Update(u);
                    }
                }
            }

            foreach (int ut in unitsToUpdate.Keys)
            {
                if (!done.Contains(ut))
                {
                    Unit newUnit = new Unit();
                    newUnit.Count = unitsToUpdate[ut];
                    newUnit.FieldId = field.FieldId;
                    newUnit.KingdomId = kingdom;
                    newUnit.UnitName = "Nie wiem po co jest to pole";
                    newUnit.UnitTypeId = ut;

                    new UnitDAO().Add(newUnit);
                }
            }

        }
예제 #2
0
 public int Add(Field o)
 {
     return new FieldDAO().Add(o);
 }
예제 #3
0
        public void InitializeKingdom(int mapId, int kingdomId)
        {

            int actMapSize = new FieldDAO().GetByMapId(mapId).Count;

            actMapSize /= 9;

            int x=0;
            int y=0;

            int xDone = 0;
            int yDone = 0;

            int xDir = 1;
            int yDir = 1;

            int xSize = 1;
            int ySize = 1;

            bool xMod = true;

            for (int i = 1; i < actMapSize+1; i++)
            {
                if (xMod)
                {
                    x += xDir*3;
                    xDone++;
                    if (xDone == xSize)
                    {
                        xDir *= -1;
                        xSize++;
                        xDone = 0;
                        xMod = false;
                    }
                }
                else
                {
                    y += yDir*3;
                    yDone++;
                    if (yDone == ySize)
                    {
                        yDir *= -1;
                        ySize++;
                        yDone = 0;
                        xMod = true;
                    }
                }
            }


           
            
            String[] area = {"Pola", "Dolina", "Wzgórza", "Łąki", "Las", "Mokradła", "Góry"};
            String[] describe = {"Mrocznych","Wichrowych", "Wesołych", "Wielkich", "Małych", "Smutnych", "Krwawych", "Czarnych", "Kolorowych", "Białych", "Żelaznych", "Stalowych", "Miedzianych", "Srebrnych", "Złotych", "Diamentowych"};
            String[] thing = {"Ostrzy", "Kucyków","Teściochych","Wilków","Wron","Szkieletów","Noży", "Chłopów", "Włóczni","Mieczy","Bibliotekarzy", "Krów"};

            Random rand = new Random();
            

            for (int i = x - 1; i < x + 2; i++)
            {
                for (int j = y - 1; j < y + 2; j++)
                {
                    System.Text.StringBuilder name = new System.Text.StringBuilder();
                    name.Append(area[rand.Next(area.Length)]);
                    name.Append(" ");
                    name.Append(describe[rand.Next(describe.Length)]);
                    name.Append(" ");
                    name.Append(thing[rand.Next(thing.Length)]);

                    Field field = new Field();
                    field.FieldX = i;
                    field.FieldY = j;

                    if(i==x && j==y) field.KingdomId = kingdomId;

                    field.MapId = mapId;
                    field.FieldName = name.ToString();

                    new FieldDAO().Add(field);
                }
            }

            // 1: wyciągam z bazy wszystkie pola należące do danej mapy

            // 2: wyciagam rozmiar

            // 3: wyliczam gzie powinien sie znalesc srodek nowego krolestwa(dodawane po spirali)

            // 4: dodaje nowe krolestwo o rozmiarze i i dodaje obwodke
        }