0

我开始编写 War(纸牌游戏)并且方法已经被实例化我需要知道为什么我不断收到这些错误。

import java.util.*;

public class CardGame {
    public static void main(String[] args) {

        CardDeck CardDeckA = new CardDeck();
        //creates a standard card deck with 52 cards 1 - 10, J, Q, K, A diamond, spade, club, heart


        //Card( int value, int suit)

        int[] player1 = new int[52];
        int[] player2 = new int[52];
        int a = player1.length;
        int b = player2.length;

        for (int i = 0; a <= 26; i++) {
            player1[i].deal(); //Error: int cannot be dereferenced
            //deal( int n):Deals n cards from the top of the CardDeck, returns Card[]
        }

        for (int j = 0; a <= 26; j++) {
            player2[j].deal();//Error: int cannot be dereferenced
        }
    }
}
4

1 回答 1

1

您应该将该方法称为

player = CardDeckA.deal(1)

代替

player1[i].deal()

因为player1[i]是一个原始的int,它没有方法。

deal返回int[],取决于你如何使用它,我怀疑它会类似于:

player = CardDeckA.deal(26)
于 2013-05-23T00:56:24.720 回答