/// <summary> /// Get Score Game and update /// </summary> /// <param name="ps"></param> /// <param name="isWin"></param> private void UpdatePlayerScore(PlayerScore ps, bool isWin) { string[] arr = File.ReadAllLines(c_FileName); int nameChangeFileIndex = -1; for (int i = 0; i < arr.Length; i++) { var spliteLine = arr[i].Split(','); if (ps.Name == spliteLine[(int)ePlayerScoreIndex.Name] && ps.Mode.ToString() == spliteLine[(int)ePlayerScoreIndex.Mode]) { ps.Score = int.Parse(spliteLine[(int)ePlayerScoreIndex.Score]); ps.TotalGames = int.Parse(spliteLine[(int)ePlayerScoreIndex.Games]); if (isWin) { ps.Score++; } ps.TotalGames++; nameChangeFileIndex = i; break; } } if (nameChangeFileIndex > 0) { arr[nameChangeFileIndex] = ps.ToString(); File.WriteAllLines(c_FileName, arr); } }
/// <summary> /// Function on Mouse Down Click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnMouseDown(object sender, MouseEventArgs e) { Button btn = sender as Button; if (m_StartGameTime == default) { BtnStartGame_Click(sender, e); } if (!timer1.Enabled) { return; } if (e.Button == MouseButtons.Left) { OnLeftMouseClick(btn); } else if (e.Button == MouseButtons.Right) { OnRightMouseClick(btn); } if (IsWinGame()) { PlayerScore ps = new PlayerScore(); ps.Name = m_NamePlayer; ps.Mode = (eGameMode)(m_ComboBox.SelectedIndex); m_ScoreManager.SetScore(ps, true); MessageBox.Show("You are a Winner GEVER"); } }
public void SetScore(PlayerScore playerScore, bool isWin) { if (!File.Exists(c_FileName)) { return; } if (IsPlayerInFile(playerScore.Name)) { UpdatePlayerScore(playerScore, isWin); return; } File.WriteAllText(c_FileName, playerScore.ToString()); }
private void GameOver() { PlayerScore ps = new PlayerScore(); ps.Name = m_NamePlayer; ps.Mode = (eGameMode)(m_ComboBox.SelectedIndex); monkeyFail.Visible = true; monkeySmile.Visible = false; m_ScoreManager.SetScore(ps, false); DialogResult result = MessageBox.Show("Do you want to play again?", "Game Over", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { StartGame(m_NumOfBoombs); } else { this.Close(); } }