// 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; } }
// 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; } }
/// <summary> /// Construct a new Game Form. /// </summary> public GameForm() { InitializeComponent(); InitializeCells(); this.DoubleBuffered = true; Painter = new GamePainter { GameForm = this }; }
// 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; } }