Java卡游戏阵列

时间:2014-07-01 03:44:48

标签: java arrays

main的输出显示以下内容:

第1轮 球员0:俱乐部女王
球员1:俱乐部之王
计算机胜利 战争

我想将播放器1的名称更改为计算机,但我在我的'中使用了一个阵列。声明。不知道如何更改它,以便它只是说电脑。我想我需要用player1然后再用电脑重写这个部分。任何人都可以帮我吗?

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 %s\n", 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");
        }

1 个答案:

答案 0 :(得分:0)

添加玩家字符串数组怎么样

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

然后使用语句

在for循环中打印

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