Exemplo n.º 1
0
        // коли користувач створює нову гру то генеруємо карту і ворогів
        // інакше це робимо в RestoreState
        private void GenerateWorld(bool isFirstGame)
        {
            timer = new Timer();

            if (!isFirstGame)
            {
                countOfEnemies = 0;
                GenerateMap();
                GenerateEnemies();
            }

            GenerateCharacter();

            enemyTimer.Start();

            GameState = new GameMemento(level, countOfEnemies, xml.GetUserById(currentUserId), score);

            createStats(level, character.killedEnemies);

            saveBtn.Location        = new Point(width - 300, 700);
            saveBtn.Size            = new Size(120, 40);
            saveBtn.BackgroundImage = Image.FromFile(pathForBackground2);
            saveBtn.FlatStyle       = FlatStyle.Popup;
            saveBtn.Font            = new Font(saveBtn.Font.Name, 13, FontStyle.Bold);
            saveBtn.ForeColor       = Color.White;
            saveBtn.Enabled         = false;
            saveBtn.Text            = "Зберегти";
            saveBtn.Click          += new EventHandler((o, ev) =>
            {
                history.CreateGameSave(characterState, enemyStateList, MapState, GameState);
                saveBtn.Enabled = false;
                exitBtn.Enabled = false;
            });
            this.Controls.Add(saveBtn);

            exitBtn.Location        = new Point(width - 170, 700);
            exitBtn.Size            = new Size(120, 40);
            exitBtn.BackgroundImage = Image.FromFile(pathForBackground2);
            exitBtn.FlatStyle       = FlatStyle.Popup;
            exitBtn.Font            = new Font(exitBtn.Font.Name, 13, FontStyle.Bold);
            exitBtn.ForeColor       = Color.White;
            exitBtn.Text            = "Вийти";
            exitBtn.Enabled         = false;
            exitBtn.Click          += new EventHandler((o, ev) =>
            {
                Application.Exit();
            });
            this.Controls.Add(exitBtn);

            background.Image    = Image.FromFile(pathForBackground);
            background.Location = new Point(0, 0);
            background.Size     = new Size(750, 750);
            background.SizeMode = PictureBoxSizeMode.StretchImage;
            background.BringToFront();
            this.Controls.Add(background);

            character.sprite.BackgroundImage = background.Image;
        }