0

私はプログラミングに不慣れで、コードに問題があります。それがどのように呼ばれるのかよくわからないので、グーグルで検索するのは難しいです。しかし、人間は私が何を意味するのかを理解すると思います。

whileループは、毎回i++ずつ増加します。コメント欄で表現したい

i = 1の場合、player1.cards[j]=ランダム; i = 2、player2.cards[j]=ランダム;

void cardScramble()
{
  int random;
  int i = 1;
  while (i <= 4)
  {
    cout << "Card of Player " << i << " : ";
    int j = 0;
    while (j < 13)
    {
      random = rand() % 52;
      if (cards[random] == NULL)
      {
        cards[random] = i;
        cout << cardName(random) << " , ";
        /*   player(i).cards[j] = random; */
        /* That's what I'm doubt with */
        j++;
      }
    }

    cout << endl;
    i++;
  }
  return;
}

それを定義するか、文字列として操作しようとしましたが、機能しませんでした。誰でもこれについて私を助けることができますか?どうもありがとう!

4

2 に答える 2

4

あなたが考えているようにそれを行うことはできません。player1代わりに、とplayer2(および他のプレーヤー)を組み合わせて配列にします。例えば:

Player_Type player[2]; // alternatively std::array<Player_Type,2> player;

i次に、次のように使用して各プレーヤーを参照できます。

player[i].cards[j] = random;

または、1から開始する場合はi、1を減算します。

player[i-1].cards[j] = random;
于 2013-02-01T18:58:58.193 に答える
1

下記のようにご利用いただけます。intの配列を持つ構造体が必要です。

 struct Player
    {
        public
        int[] cards = new int[13];
    }; 

次に、whileループは次のようになります

Palyer []player = new Palyer[4];

int random;
        int i = 1;
        while (i <= 4)
        {
            cout << "Card of Player " << i << " : ";
            int j = 0;
            while (j < 13)
            {
                random = rand() % 52;
                if (player[i].cards[random] == NULL)
                {
                    cards[random] = i;
                    cout << cardName(random) << " , ";
                     player[i].cards[j] = random; 
                    /* That's what I'm doubt with */
                    j++;
                }
            }
            i++;
        }

//役に立ったら答えのように

于 2013-02-01T20:04:37.090 に答える