Ejemplo n.º 1
0
        //доступ к журналу
        public List <TankDetail> SelectTankDetails(bool delete)
        {
            //очистка журнала
            if (delete)
            {
                ClearTankJournal();
            }

            using (TankContext db = new TankContext()) {
                return(db.TankDetails.ToList());
            }
        }
Ejemplo n.º 2
0
        //стратегия
        public List <Tank> ApplyStrategy(List <Tank> tanks, TankColor tankColor, string player, bool attack)
        {
            int[] field2 = FillField(tanks);
            for (int i = 0; i < cellCount; i++)
            {
                for (int j = 0; j < cellCount; j++)
                {
                    field[i, j] = field2[i * cellCount + j];
                }
            }

            int x, y;

            foreach (var tank1 in tanks.ToList())
            {
                if (tank1.Color == (int)tankColor)
                {
                    tank1.Strategy(out x, out y, field, attack);
                    //если танк подбит
                    if (x != -1)
                    {
                        foreach (var tank2 in tanks.ToList())
                        {
                            if (tank2.X == x && tank2.Y == y)
                            {
                                tanks.Remove(tank2);
                            }
                        }
                    }
                }

                //заполнение журнала
                using (TankContext db = new TankContext()) {
                    TankDetail tank = new TankDetail {
                        X        = tank1.X,
                        Y        = tank1.Y,
                        Color    = (tank1.Color == -1)?"Красный":"Синий",
                        Orient   = Orient(tank1),
                        Player   = player,
                        Strategy = (attack) ? "Aтака" : "Оборона",
                    };

                    db.TankDetails.Add(tank);
                    db.SaveChanges();
                }
            }
            return(tanks);
        }
Ejemplo n.º 3
0
 //очистка журнала
 private void ClearTankJournal()
 {
     using (TankContext db = new TankContext()) {
         db.Database.ExecuteSqlCommand("TRUNCATE TABLE [TankDetails]");
     }
 }