1
什麼是實行軍銜制的最佳方式:如何實現等級結構
這裏是我的代碼將使用
public class MyRank
{
private int LevelOneMaxPoints = 100;
private int LevelTwoMinPoints = 200;
private int LevelTwoMaxPoints = 299;
private int LevelThreeMinPoints = 300;
private int LevelThreeMaxPoints = 399;
private int LevelFourMinPoints = 400;
private int LevelFourMaxPoints = 599;
private int LevelFourPlusMinPoints = 600;
private int LevelFourPlusMaxPoints = 999;
private int LevelFiveMinPoints = 1000;
private int LevelFiveMaxPoints = 1299;
private int LevelSixMinPoints = 1300;
private int LevelSixMaxPoints = 2699;
private int LevelSevenMinPoints = 2700;
private int LevelSevenMaxPoints = 3999;
private int LevelEightMinPoints = 4000;
private int LevelEightMaxPoints = 5499;
private int LevelEightPlusMinPoints = 5500;
private int LevelEightPlusMaxPoints = 7499;
private int LevelNineMinPoints = 7500;
private int LevelNineMaxPoints = 9999;
private int LevelTenMinPoints = 10000;
private string LevelOneName = "Private";
private string LevelTwoName = "PV2";
private string LevelThreeName = "Private Fist Class";
private string LevelFourName = "Specialist";
private string LevelFourPlusName = "Corporal";
private string LevelFiveName = "Sergeant";
//private string LevelSixName = "Staff Sergeant";
private string LevelSevenName = "Sergeant First Class";
private string LevelEightName = "Master Sergeant";
private string LevelEightPlusName = "First Sergeant";
private string LevelNineName = "Sergeant Major";
//private string LevelTenName = "Sergeant Major of the Answers";
private int points = 0;
public string RankName { get; private set; }
public MyRank(int points)
{
this.points = points;
RankName = GetRankName();
}
private string GetRankName()
{
if (points >= Int32.MinValue && points <= LevelOneMaxPoints)
return LevelOneName;
else if (points >= LevelTwoMinPoints && points <= LevelTwoMaxPoints)
return LevelTwoName;
else if (points >= LevelThreeMinPoints && points <= LevelThreeMaxPoints)
return LevelThreeName;
else if (points >= LevelFourMinPoints && points <= LevelFourMaxPoints)
return LevelFourName;
else if (points >= LevelFourPlusMinPoints && points <= LevelFourPlusMaxPoints)
return LevelFourPlusName;
else if (points >= LevelFiveMinPoints && points <= LevelFiveMaxPoints)
return LevelFiveName;
else if (points >= LevelSixMinPoints && points <= LevelSixMaxPoints)
return LevelFiveName;
else if (points >= LevelSevenMinPoints && points <= LevelSevenMaxPoints)
return LevelSevenName;
else if (points >= LevelEightMinPoints && points <= LevelEightMaxPoints)
return LevelEightName;
else if (points >= LevelEightPlusMinPoints && points <= LevelEightPlusMaxPoints)
return LevelEightPlusName;
else if (points >= LevelNineMinPoints && points <= LevelNineMaxPoints)
return LevelNineName;
else if (points >= LevelNineMinPoints && points <= LevelNineMaxPoints)
return LevelNineName;
else if (points >= LevelTenMinPoints)
return LevelFourName;
else
return "No Rank";
}
}
你覺得這是要做到這一點的最有效方法是什麼?
我得到一個語法錯誤 - 無法找到類型或名稱空間「描述」。我的屬性有問題嗎? – Luke101 2010-06-15 17:09:05
行..我想通了 – Luke101 2010-06-15 17:52:45
太棒了!這個解決方案看起來更易於管理嗎? – hunter 2010-06-16 15:12:21