1

Visual C# 2010 と XNA 4.0 を使用して Uno カード ゲームを開発しています。すべての Uno カードの 108 要素の配列を配列要素として作成しました。

ここで、ゲームの開始時に 4 人のプレイヤーのそれぞれにランダムに 7 枚のカードを割り当てたいと考えています。そこで、乱数を作成し、その番号のカードをプレイヤーに割り当てます。

    for (int i = 0; i < 7; i++)
        {
            int r = rnd.Next(108);
            if (vis[r] != 1)  //vis[] is an array to checkk visited elements
            {

              //  u[i] = Content.Load<Texture2D>("toString.Allcards[r]");
                u[i]=Content.Load<Texture2D>(ToString("Allcards[r]"));
            } 

これは機能していません。助けてください。

4

3 に答える 3

0
    for (int i = 0; i < 7; i++)
            {
                int r = rnd.Next(108);
                if (vis[r] != 1)  //vis[] is an array to checkk visited elements
                {

                  //  u[i] = Content.Load<Texture2D>("toString.Allcards[r]");
                    u[i]=Content.Load<Texture2D>(Allcards[r].ToString());
                } 
            }
于 2013-01-21T04:25:29.070 に答える
0

Content.Load<Texture2D>(Allcards[r]);Allcards が文字列の配列であると仮定します。Allcards が Texture2D オブジェクトの配列である場合は、Content.Load既に読み込まれているため不要です。使用できますu[i] = Allcards[r]

そうは言っても、プレイヤーにテクスチャを与えるだけではだめでしょう。あなたは彼らに実際のカードを渡したいと思うでしょう. Card クラスを作成し、それにテクスチャを割り当てることをお勧めします。また、ID などの有用な情報や、その機能を説明するためのプロパティもいくつか指定することをお勧めします。

于 2013-01-29T17:15:11.880 に答える
0

Assuming "Allcards[r]" holds the textures for the cards (ie, Allcards[1] == "Ace of Spades" and theres a texture called Ace of Spades in your project), you probably want this instead:

u[i]=Content.Load<Texture2D>(Allcards[r]);
于 2013-01-20T08:31:48.097 に答える