基本上我创建了这个skill
类:
public class skill
{
public int level { get; set; } //Level of the skill (average of sub-skills' levels)
public int arrayCount { get; set; } //Number of skill/levels in the below arrays
public string[] sub_skills { get; set; } //Names of sub-skills ([0] connect's to levels' [0], etc.)
public int[] sub_levels { get; set; } //Levels of sub-skills ([0] connect's to names' [0], etc.)
void set(int l, int a, string[] sub_s, int[] sub_l)
{
this.level = l; //Sets the skill's level to the input'd l value
this.arrayCount = a; //Sets the skill's array count to the input'd a value
for (int i = 0; i < arrayCount; i++) //For loop to assign each value in both arrays
{
this.sub_skills[i] = sub_s[i]; //Assigns each input'd sub_s array value to each sub_skills value
this.sub_levels[i] = sub_l[i]; //Assigns each input'd sub_l array value to each sub_levels value
}
}
}
现在我创建了另一个类player
:
public class Player
{
public string name { get; set; } //Name of Player
public int level { get; set; } //Player's combat level (average of combat-related skills' levels)
//Start Thievery skill block
string[] thief_s = { "lockpicking", "looting", "pickpocketing", "sneaking" }; //Array for thievery's sub-skill names
int[] thief_i = { 1, 1, 1, 1 }; //Array for thievery's sub-levels
skill thievery = new skill(); //Creates the skill of Thievery (stealing items / passing unnoticed)
//Start Melee skill block
skill melee = new skill(); //Creates the skill of Melee (close-range, strong combat)
//Start Archery skill block
skill archery = new skill(); //Creates the skill of Archery (long-range, weak combat)
//Start Magicka skill block
skill magicka = new skill(); //Creates the skill of Magicka (medium-range, medium combat)
//Start Craftship skill block
skill craftship = new skill(); //Creates the skill of Craftship (retreivement then creation of items from materials)
}
对于在类内创建的特定技能,我如何使用类内类的set()
方法?例如,您可以看到我是如何在那里创建技能的,已经使用它的数组来表示它的子级别的名称和级别(类中的变量)。如何访问's函数并使用其中的数组来设置's 变量?我试过这条线,但我的 IDE 不断抛出错误。(我正在使用 Microsoft Visual Studio Ultimate 2010)skill
player
player
thievery
skill
thievery
set()
thievery
thievery.set(// insertvarshere)
编辑:谢谢大家。出于某种原因,将set()
功能设置为 public 并没有改变任何东西。当我调用thievery.set()
我的 IDE 时,会在thievery
. 我将听取查尔斯的建议并制作子技能技能,然后,如果可能的话,对它们应用某种标签,将它们标记为主要技能的一部分。这是可能的,还是我必须为标签创建自己的类/函数等?