Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Start");

            Greetings g = new Greetings(SayHello);

            g("Ari");

            g += SayHallo;
            g("Ari");

            // Anonym, d.h. direkt mit eine Methodenimplementierung
            Anonym a = delegate(string name) {
                Console.WriteLine("Ich bin Anonym " + name);
            };

            a("Anonymous");

            Timer t = new Timer();

            t.Start();
            CounterUp u = new CounterUp(t);

            // Warten Simulieren
            Thread.Sleep(10000);
            t.Stopp();

            Console.WriteLine("End");
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            #region анонімні методи без параметрів
            Anonym anonym = delegate
            {
                DirectoryInfo dir = new DirectoryInfo("E:\\");
                foreach (DirectoryInfo d in dir.GetDirectories())//Виводить назву кожної папки(диркеторії)
                {
                    Console.WriteLine(d.Name);
                }
            };

            anonym();
            #endregion
            #region анонімні методи з параметрами

            Anonym2 anon2 = delegate(int a, int b)
            {
                for (int i = a; i <= b; i++)
                {
                    Console.WriteLine("Спортсмен на {0} километре. До финиша {1}", i, b - i);
                }
                Console.Read();
            };



            anon2(1, 12);
            Console.Read();
            #endregion
        }
Esempio n. 3
0
        public ActionResult Index()
        {
            int    currentUser         = 0;
            string sessionKey          = HttpContext.Session.SessionID;
            string CurrentUserIdentity = System.Web.HttpContext.Current.User.Identity.Name;

            string isSessionIdExist = (from x in db.Anonym
                                       where x.SessionID == sessionKey
                                       select x.SessionID).FirstOrDefault();

            string isUsernNameExist = (from une in new ApplicationDbContext().Users
                                       where une.UserName == CurrentUserIdentity
                                       select une.UserName).SingleOrDefault();

            if (CurrentUserIdentity == isUsernNameExist)
            {
                string isUserExist = (from x in db.Anonym
                                      where x.SessionID == CurrentUserIdentity
                                      select x.SessionID).FirstOrDefault();
                if (isUserExist != CurrentUserIdentity)
                {
                    var query = (from asd in db.Anonym
                                 where asd.SessionID == sessionKey
                                 select asd.ID).FirstOrDefault();
                    if (query != null)
                    {
                        Anonym helper = db.Anonym.Find(query);
                        helper.SessionID = CurrentUserIdentity;
                    }
                    else
                    {
                        db.Anonym.Add(new Anonym(CurrentUserIdentity));
                    }
                }
                db.SaveChanges();

                currentUser = (from x in db.Anonym
                               where x.SessionID == CurrentUserIdentity
                               select x.ID).FirstOrDefault();
            }
            else
            {
                if (isSessionIdExist != sessionKey)
                {
                    db.Anonym.Add(new Anonym(sessionKey));
                }
                db.SaveChanges();

                currentUser = (from x in db.Anonym
                               where x.SessionID == sessionKey
                               select x.ID).FirstOrDefault();
            }
            return(View());
        }
Esempio n. 4
0
        private void InitGame()
        {
            _bombs = 0;

            for (int i = 0; i < COL_SIZE + 2; i++)
            {
                for (int j = 0; j < ROW_SIZE + 2; j++)
                {
                    _cells[j, i] = new Cell(new Sprite(Textures.textures["squere"], 50, 50), new Vector2((j * 50) - 50, (LAYER_HEIGHT + i * 50) - 50));
                }
            }

            int bombCount = 0;

            while (bombCount < 8)
            {
                bombCount = 0;

                for (int i = 1; i <= COL_SIZE; i++)
                {
                    for (int j = 1; j <= ROW_SIZE; j++)
                    {
                        if (_random.Next(1, 6) < 2 &&
                            (i != 0 && i != 11) && (j != 0 && j != 11))
                        {
                            _cells[j, i].isBomb   = true;
                            _cells[j, i].isEmpty  = false;
                            _cells[j, i].isNumber = false;

                            _cells[j - 1, i - 1].AddBomb();
                            _cells[j - 1, i].AddBomb();
                            _cells[j - 1, i + 1].AddBomb();

                            _cells[j, i - 1].AddBomb();
                            _cells[j, i + 1].AddBomb();

                            _cells[j + 1, i - 1].AddBomb();
                            _cells[j + 1, i].AddBomb();
                            _cells[j + 1, i + 1].AddBomb();

                            bombCount++;
                        }
                    }
                }
            }

            Anonym SetToNone = (index) =>
            {
                for (int i = 0; i < COL_SIZE + 2; i++)
                {
                    _cells[index, i].State = CellState.None;
                }
            };

            SetToNone(0);

            for (int i = 0; i < ROW_SIZE + 2; i++)
            {
                _cells[i, 0].State  = CellState.None;
                _cells[i, 11].State = CellState.None;
            }

            SetToNone(9);

            foreach (var bomb in _cells)
            {
                if (bomb.isBomb)
                {
                    _bombs++;
                }
            }

            foreach (var entity in _cells)
            {
                _entityManager.AddEntity(entity);
            }

            _counter.Bombs = _bombs;

            _gameState = GameState.Playing;
        }