Java纸牌游戏数组



main的输出如下:

第一轮
玩家0:梅花皇后
玩家1:梅花国王
电脑赢了战争的

我想将玩家1的名称更改为计算机,但我在"for"语句中使用数组。不知道该怎么改,让它只写电脑。我想我需要用player1和computer重写这部分。有人能帮我吗?

public static void main(String[] args) {

    Card[][] hands = new Card[2][1];
    Deck myDeck = new Deck();
    int score1;
    int score2;
    score1 = 0;
    score2 = 0;
    for (int i = 0; i < 26; i++) {
        System.out.printf("nRound %sn", i);

        for (int player = 0; player < hands.length; player++) {
            hands[player][0] = myDeck.dealCard();
        }
        for (int player = 0; player < hands.length; player++) {
            System.out.printf("Player %d: ", player);
            printHand(hands[player]);

        }
        int player1 = hands[0][0].getValue(); 
        int computer = hands[1][0].getValue();
        if (player1 > computer) {
            System.out.println("Player One Wins The War");
            score1 += 1;
        } else if (computer > player1) {
            System.out.println("Computer Wins The War");
            score2 += 1;
        } else {
            System.out.println("Tie");
        }

如何添加一个球员字符串数组

String[] playerName = {"Player One", "Computer"};

然后在for循环中打印语句

System.out.println(playerName[player]);

最新更新