0

基本的に私はこの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()メソッドを使用するにはどうすればよいですか? たとえば、サブレベルの名前とレベル (クラス内の変数) の配列を使用して、スキルを作成した方法を確認できます。の関数にアクセスし、その中の配列を使用しての変数を設定するにはどうすればよいですか? この行を試しましたが、IDE がエラーをスローし続けます。(Microsoft Visual Studio Ultimate 2010 を使用しています)skillplayerplayerthieveryskillthieveryset()thieverythievery.set(// insertvarshere)

編集:みんなありがとう。何らかの理由でset()関数を public に設定しても何も変わりませんでした。thievery.set()IDEを呼び出すと、下に赤い線が表示されthieveryます。チャールズのアドバイスを受けてサブスキルのスキルを作成し、可能であればそれらに何らかのタグを付けて、メジャースキルの一部としてマークします. それは可能ですか、それともタグ用に独自のクラス/関数などを作成する必要がありますか?

4

3 に答える 3

3

一見すると、公開する必要があります。

public void set(int l, int a, string[] sub_s, int[] sub_l) {
  ...

次に、各スキル インスタンスに対して、次のように呼び出すことができます。

thievery.set( ... );

どこで呼び出すか、どのパラメーター引数を使用するかは、あなた次第です。

于 2013-07-22T17:30:03.167 に答える