private void InitGameOver() { fallingTimer.Enabled = false; if (TetrisBoard.ScoresTable.Count > 0) { foreach (var player in TetrisBoard.ScoresTable) { if (board.Score > player.Score || TetrisBoard.ScoresTable.Count < TetrisBoard.MaxScores) { SaveScoreForm saveScoreForm = new SaveScoreForm(); saveScoreForm.ShowDialog(); if (!String.IsNullOrWhiteSpace(saveScoreForm.PlayerName)) { board.SaveScore(saveScoreForm.PlayerName); } break; } } } else { SaveScoreForm saveScoreForm = new SaveScoreForm(); saveScoreForm.ShowDialog(); if (!String.IsNullOrWhiteSpace(saveScoreForm.PlayerName)) { board.SaveScore(saveScoreForm.PlayerName); } } board = null; g.Clear(TetrisBoard.BackColor); gNext.Clear(TetrisBoard.BackColor); MessageBox.Show("Game Over!"); }
private void SaveScore() { if (TetrisBoard.ScoresTable.Count == 0) { return; } SaveScoreForm saveScoreForm = new SaveScoreForm(); saveScoreForm.ShowDialog(); if (!String.IsNullOrWhiteSpace(saveScoreForm.PlayerName)) { TetrisBoard.ScoresTable.Add(new Player(saveScoreForm.PlayerName, board.Score)); } var sr = new System.IO.StreamWriter(TetrisBoard.ScoresTablePath); TetrisBoard.ScoresTable.OrderBy(player => player.Score).ToList().ForEach(player => sr.WriteLine(player)); }