Ejemplo n.º 1
0
        /// <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);
            }
        }
Ejemplo n.º 2
0
        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());
        }