public static string Format(this RaceName race) { if (RaceFormatMap.ContainsKey(race)) { return(RaceFormatMap[race]); } else { return(race.ToString()); } }
/// <summary> /// Saves the force power descriptor. /// </summary> /// <returns>Race Object</returns> public Race SaveRace() { SqlDataReader result; DatabaseConnection dbconn = new DatabaseConnection(); SqlCommand command = new SqlCommand(); SqlConnection connection = new SqlConnection(dbconn.SQLSEVERConnString); try { connection.Open(); command.Connection = connection; command.CommandType = CommandType.StoredProcedure; command.CommandText = "InsertUpdate_Race"; command.Parameters.Add(dbconn.GenerateParameterObj("@RaceID", SqlDbType.Int, RaceID.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@RaceName", SqlDbType.VarChar, RaceName.ToString(), 50)); command.Parameters.Add(dbconn.GenerateParameterObj("@RaceDescription", SqlDbType.VarChar, RaceDescription.ToString(), 1000)); command.Parameters.Add(dbconn.GenerateParameterObj("@OtherDescription", SqlDbType.VarChar, OtherDescription.ToString(), 1000)); command.Parameters.Add(dbconn.GenerateParameterObj("@SizeID", SqlDbType.Int, SizeID.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@Sex", SqlDbType.Char, Sex.ToString(), 1)); command.Parameters.Add(dbconn.GenerateParameterObj("@RageAbility", SqlDbType.Bit, RageAbility.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@ShapeShiftAbility", SqlDbType.Bit, ShapeShiftAbility.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@Primitive", SqlDbType.Bit, Primitive.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@BonusSkill", SqlDbType.Bit, BonusSkill.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@BonusFeat", SqlDbType.Bit, BonusFeat.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@AverageHeight", SqlDbType.Decimal, AverageHeight.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@AverageWeight", SqlDbType.Decimal, AverageWeight.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@SpeedID", SqlDbType.Int, SpeedID.ToString(), 0)); result = command.ExecuteReader(); result.Read(); SetReaderToObject(ref result); } catch { Exception e = new Exception(); this._insertUpdateOK = false; this._insertUpdateMessage.Append(e.Message + " Inner Exception= " + e.InnerException); throw e; } finally { command.Dispose(); connection.Close(); } return(this); }
public void LoadRecord(RaceName raceName, string playerName, float time) { string filePath = Application.streamingAssetsPath + "/XML/RaceRecord.xml"; if (File.Exists(filePath)) { List <string> nameRank = new List <string>() { "", "", "" }; List <float> timeRank = new List <float>() { 0, 0, 0 }; XmlDocument myDoc = new XmlDocument(); myDoc.Load(filePath); XmlNodeList nodeList = myDoc.SelectSingleNode("root").ChildNodes; //获得XML中赛道纪录,将纪录存入容器中 foreach (XmlElement tempRace in nodeList) { if (tempRace.Name == raceName.ToString()) { foreach (XmlAttribute RaceInf in tempRace.Attributes) { if (RaceInf.Name == "FName") { nameRank[0] = RaceInf.Value; } else if (RaceInf.Name == "SName") { nameRank[1] = RaceInf.Value; } else if (RaceInf.Name == "TName") { nameRank[2] = RaceInf.Value; } else if (RaceInf.Name == "FiresRecord") { timeRank[0] = float.Parse(RaceInf.Value); } else if (RaceInf.Name == "SecondRecord") { timeRank[1] = float.Parse(RaceInf.Value); } else if (RaceInf.Name == "ThirdRecord") { timeRank[2] = float.Parse(RaceInf.Value); } } } } //与传入数据相比较,若更快则存入容器中 for (int i = 0; i < timeRank.Count; i++) { if (time < timeRank[i]) { for (int j = timeRank.Count - 1; j >= i + 1; j--) { timeRank[j] = timeRank[j - 1]; nameRank[j] = nameRank[j - 1]; } timeRank[i] = time; nameRank[i] = playerName; break; } } foreach (XmlElement tempRace in nodeList) { if (tempRace.Name == raceName.ToString()) { foreach (XmlAttribute RaceInf in tempRace.Attributes) { if (RaceInf.Name == "FName") { RaceInf.Value = nameRank[0]; } else if (RaceInf.Name == "SName") { RaceInf.Value = nameRank[1]; } else if (RaceInf.Name == "TName") { RaceInf.Value = nameRank[2]; } else if (RaceInf.Name == "FiresRecord") { RaceInf.Value = timeRank[0].ToString(); } else if (RaceInf.Name == "SecondRecord") { RaceInf.Value = timeRank[1].ToString(); } else if (RaceInf.Name == "ThirdRecord") { RaceInf.Value = timeRank[2].ToString(); } } } } myDoc.Save(filePath); nameRank.Clear(); timeRank.Clear(); } }
public static RaceData Find(RaceName name) { return(RaceDataList[name.ToString()]); }
public string PresentableName() { return(name.ToString().ToLower()); }