Esempio n. 1
0
        // Loads new level:
        void LoadLevel()
        {
            // Clearing key press adapter:
            this.keyPressAdapters.Clear();

            try
            {
                // Creating a level:
                this.level = new CPlayLevel(++LevelNumber, Players, constructionMap);

                // Setting statistics to show whel level completed:
                this.level.OnLevelExit += OnShowStatistics;

                // Setting key press adapter for player 1:
                for (int i = 0; i < Players.Count; i++)
                {
                    this.keyPressAdapters.Add(new CKeyPressAdapter(ControlKeys[i], Players[i]));
                }

                // Setting scene painter:
                this.gamePainter = level.DrawLevel;

                // Setting current status to Playing:
                this.CurrentGameStatus = GameStatuses.Playing;
            }

            catch (Exception)
            {
                MessageBox.Show("Error loading level!");

                this.gamePainter = null;
            }
        }
Esempio n. 2
0
        // Shows statistics:
        void OnShowStatistics(object sender, EventArgs e)
        {
            try
            {
                // Setting status to show statistics:
                this.CurrentGameStatus = GameStatuses.ShowStatistics;

                // Getting players:
                CTankPlayer[] players = (sender as CPlayLevel).Players.ToArray();

                // Modify hiscore if any player hits it:
                foreach (CTankPlayer p in players)
                {
                    if (p.Points > hiScore)
                    {
                        hiScore = p.Points;
                    }
                }

                // Creating statistics, taking game status and player from level:
                this.levelStatistics = new CStatisticsViewer((e as LevelEventArgs).GameStatus, this.levelNumber, this.hiScore, players);

                // Setting event that shoud occur when statistics shown
                this.levelStatistics.OnEnd += OnStatisticsEnd;

                // Setting game painter to statistics:
                this.gamePainter = levelStatistics.DrawStatistics;
            }
            catch (Exception)
            {
                MessageBox.Show("Error on statistics show! Going to menu...");

                this.gamePainter = null;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Construct a new Game Form.
        /// </summary>
        public GameForm()
        {
            InitializeComponent();
            InitializeCells();

            this.DoubleBuffered = true;
            Painter             = new GamePainter {
                GameForm = this
            };
        }
Esempio n. 4
0
        // Runs game mode:
        public override void RunGameMode()
        {
            switch (CurrentGameStatus)
            {
            case GameStatuses.Playing:

                // Processing level:
                level.ProcessLevel();

                break;

            case GameStatuses.PlayerWin:

                // Loading next level:
                LoadLevel();

                break;

            case GameStatuses.ShowStatistics:

                // If statistics created, process it:
                if (levelStatistics != null)
                {
                    levelStatistics.ProcessObject();
                }

                break;

            case GameStatuses.GameOver:

                // GAME OVER screen:
                if (gameOverTimeout == 200)
                {
                    gamePainter = new CGameOver().DrawElement;
                }

                // After timeout initialize OnGameOver event:
                if ((OnGameOver != null) && (gameOverTimeout-- < 0))
                {
                    OnGameOver(this, new EventArgs());
                }

                break;
            }
        }