Beispiel #1
0
        public bool SaveAchievement()
        {
            DataRow result = (from row in ds.Tables[(int)XMLTbls.player_achievement].AsEnumerable()
                              where row.Field <string>("player_ID") == Player_ID.ToString() &&
                              row.Field <string>("achievement_ID") == ((int)Player_Achievement).ToString()
                              select row).SingleOrDefault();

            result.BeginEdit();

            int.TryParse(result.ItemArray[(int)PlayerAchievementsTbl.achievement_data].ToString(), out int achievementCount); //current player achievement count

            if (Player_Achievement == Achievements.Star_Light)                                                                // Star Collection is a counter
            {
                if (achievementCount == 0)                                                                                    // record first level achievement
                {
                    DataRow r = (from row in ds.Tables[(int)XMLTbls.player_achievement].AsEnumerable()
                                 where row.Field <string>("player_ID") == Player_ID.ToString() &&
                                 row.Field <string>("achievement_ID") == ((int)Achievements.Star_Power).ToString()
                                 select row).SingleOrDefault();
                    r.BeginEdit();
                    r[(int)PlayerAchievementsTbl.achievement_data] = achieved.ToString();
                    r[(int)PlayerAchievementsTbl.achievement_date] = DateTime.Now.ToString(); //record date of achievement
                    r.EndEdit();
                    r.AcceptChanges();
                    xmlUtils.UpdateXMLfile(ds);
                }
                result.ItemArray[(int)PlayerAchievementsTbl.achievement_data] = (Achievement_Data + achievementCount).ToString();
                if ((Achievement_Data + achievementCount) >= (int)Achievement_Counters.Stars && result.ItemArray[(int)PlayerAchievementsTbl.achievement_date].ToString() == string.Empty)
                {
                    result[(int)PlayerAchievementsTbl.achievement_date] = DateTime.Now.ToString(); //record date of achievement
                }
            }

            if (Player_Achievement == Achievements.Electrocuted) // Death by Lighting is a counter
            {
                if (achievementCount == 0)                       // record first level achievement
                {
                    DataRow r = (from row in ds.Tables[(int)XMLTbls.player_achievement].AsEnumerable()
                                 where row.Field <string>("player_ID") == Player_ID.ToString() &&
                                 row.Field <string>("achievement_ID") == ((int)Achievements.Shocked).ToString()
                                 select row).SingleOrDefault();
                    r.BeginEdit();
                    r[(int)PlayerAchievementsTbl.achievement_data] = achieved.ToString();
                    r[(int)PlayerAchievementsTbl.achievement_date] = DateTime.Now.ToString(); //record date of achievement
                    r.EndEdit();
                    r.AcceptChanges();
                    xmlUtils.UpdateXMLfile(ds);
                }
                result.ItemArray[(int)PlayerAchievementsTbl.achievement_data] = (Achievement_Data + achievementCount).ToString();
                if ((Achievement_Data + achievementCount) >= (int)Achievement_Counters.Lighting && result.ItemArray[(int)PlayerAchievementsTbl.achievement_date].ToString() == string.Empty)
                {
                    result[(int)PlayerAchievementsTbl.achievement_date] = DateTime.Now.ToString();
                }
            }

            if (Player_Achievement == Achievements.Kills_1)
            {
                result.ItemArray[(int)PlayerAchievementsTbl.achievement_data] = (Achievement_Data + achievementCount).ToString();
                if (Achievement_Data >= (int)Achievement_Counters.Kill_1)
                {
                    result[(int)PlayerAchievementsTbl.achievement_data] = 1;
                    result[(int)PlayerAchievementsTbl.achievement_date] = DateTime.Now.ToString(); // record date of first achievement
                }
            }

            if (Player_Achievement == Achievements.Kills_2)
            {
                result.ItemArray[(int)PlayerAchievementsTbl.achievement_data] = (Achievement_Data + achievementCount).ToString();
                if (Achievement_Data >= (int)Achievement_Counters.Kill_2)
                {
                    result[(int)PlayerAchievementsTbl.achievement_data] = 1;
                    result[(int)PlayerAchievementsTbl.achievement_date] = DateTime.Now.ToString(); // record date of first achievement
                }
            }

            if (Player_Achievement == Achievements.Kills_3)
            {
                result.ItemArray[(int)PlayerAchievementsTbl.achievement_data] = (Achievement_Data + achievementCount).ToString();
                if (Achievement_Data >= (int)Achievement_Counters.Kill_3)
                {
                    result[(int)PlayerAchievementsTbl.achievement_data] = 1;
                    result[(int)PlayerAchievementsTbl.achievement_date] = DateTime.Now.ToString(); // record date of first achievement
                }
            }

            // All other achievements are true or false data types, save as 1, to change from default of 0
            if (result.ItemArray[(int)PlayerAchievementsTbl.achievement_date].ToString() == string.Empty)
            {
                result[(int)PlayerAchievementsTbl.achievement_data] = 1;
                result[(int)PlayerAchievementsTbl.achievement_date] = DateTime.Now.ToString(); // record date of first achievement
            }

            result.EndEdit();
            result.AcceptChanges();
            xmlUtils.UpdateXMLfile(ds);

            return(true);
        }
Beispiel #2
0
        public bool SaveLevel()
        {
            DataTable dt    = ds.Tables[(int)XMLTbls.player_history];
            int       count = dt.AsEnumerable()
                              .Where(i => i.Field <string>("player_ID") == StartScreen.PlayerID.ToString())
                              .Count();

            if (count > 0)
            {
                //player_history
                DataRow result = (from row in ds.Tables[(int)XMLTbls.player_history].AsEnumerable()
                                  where row.Field <string>("player_ID") == Player_ID.ToString() && //player1
                                  row.Field <string>("level_ID") == Level_ID.ToString()         //level1
                                  select row).SingleOrDefault();
                result.BeginEdit();
                int.TryParse(result.ItemArray[(int)PlayerHistoryTbl.points].ToString(), out int level_score);
                if (Level_Score > level_score)
                {
                    result[(int)PlayerHistoryTbl.points] = Level_Score.ToString(); // final score of the level
                }

                int.TryParse(result.ItemArray[(int)PlayerHistoryTbl.level_time].ToString(), out int level_time);
                if (Level_Time < level_time || level_time == 0)
                {
                    result[(int)PlayerHistoryTbl.level_time] = Level_Time;
                    // how long it took to complete the level in seconds
                }

                int.TryParse(result.ItemArray[(int)PlayerHistoryTbl.special_count].ToString(), out int special_count);
                if (Special_Count > special_count)
                {
                    result[(int)PlayerHistoryTbl.special_count] = Special_Count;
                    // how many special items were found in the level-default is one if the player finished the level
                }

                int.TryParse(result.ItemArray[(int)PlayerHistoryTbl.monster_count].ToString(), out int monster_count);
                if (Monster_Count > monster_count)
                {
                    result[(int)PlayerHistoryTbl.monster_count] = Monster_Count; // how many bad guys were defeated
                }

                result[(int)PlayerHistoryTbl.last_played] = DateTime.Now.ToString(); //last played

                if (result.ItemArray[(int)PlayerHistoryTbl.completed].ToString() == string.Empty)
                {
                    result[(int)PlayerHistoryTbl.completed] = DateTime.Now.ToString(); //completed the first time
                }

                int.TryParse(result.ItemArray[(int)PlayerHistoryTbl.level_attempts].ToString(), out int level_attempts);
                if (Level_Attempts < level_attempts || level_attempts == 0)
                {
                    result[(int)PlayerHistoryTbl.level_attempts] = Level_Attempts.ToString();
                    // how many times the level has been played
                }
                result.EndEdit();
                result.AcceptChanges();
                xmlUtils.UpdateXMLfile(ds);
            }

            dt    = ds.Tables[(int)XMLTbls.player];
            count = dt.AsEnumerable()
                    .Where(i => i.Field <string>("player_ID") == StartScreen.PlayerID.ToString())
                    .Count();

            if (count > 0)
            {
                //player character update
                DataRow result = (from row in ds.Tables[(int)XMLTbls.player].AsEnumerable()
                                  where row.Field <string>("player_ID") == Player_ID.ToString() //player1
                                  select row).SingleOrDefault();
                result.BeginEdit();

                int.TryParse(result.ItemArray[(int)PlayerTbl.char_points].ToString(), out int char_points);
                int.TryParse(result.ItemArray[(int)PlayerTbl.char_level].ToString(), out int char_level);
                decimal points = char_points + Char_Points;
                int     lvl    = 0;
                if (points >= LevelUp)
                {
                    points = points / LevelUp;
                    lvl    = (int)Math.Round(points);
                }
                result[(int)PlayerTbl.char_level] = char_level + lvl;
                Char_Level = char_level + lvl;
                result[(int)PlayerTbl.char_points] = char_points - (lvl * LevelUp);

                result.EndEdit();
                result.AcceptChanges();
                xmlUtils.UpdateXMLfile(ds);
            }

            return(true);
        }