-1

我正在尝试创建一个计算机生成的二十一点,它可以洗牌 54 张牌,并将它们与分数一起显示,以及该人是否获得二十一点。我不断收到此错误,我不知道为什么,如果有人可以提供帮助,那就太好了(:

import java.awt.GridLayout;
import java.util.Random;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class DisplayCards extends JFrame {
public DisplayCards() {
    int cardCount = 54;
    Random ran = new Random();
    setLayout(new GridLayout(1,4,5,5));

    //Generate 3 random numbers
    for(int i=0;i<3;i++){
      int imageId = ran.nextInt(cardCount)+1;
      int blackjack = 0,
            result = 0;
      add(new JLabel(new ImageIcon("image/card/"+imageId+".png")));

        switch (imageId)
        {
        case 1:
                blackjack = 1;

        case 2:
                blackjack = 2;

            case 3:
                blackjack = 3;

            case 4:
                blackjack = 4;

            case 5:
                blackjack = 5;

            case 6:
                blackjack = 6;

            case 7:
                blackjack = 7;

            case 8:
                blackjack = 8;

            case 9:
                blackjack = 9;

            case 10:
                blackjack = 10;

            case 11:
                blackjack = 10;

        case 12:
                blackjack = 10;

            case 13:
                blackjack = 10;

            case 14:
                blackjack = 1;

            case 15:
                blackjack = 2;

            case 16:
                blackjack = 3;

            case 17:
                blackjack = 4;

            case 18:
                blackjack = 5;

            case 19:
                blackjack = 6;

            case 20:
                blackjack = 7;

            case 21:
                blackjack = 8;

        case 22:
                blackjack = 9;

            case 23:
                blackjack = 10;

            case 24:
                blackjack = 10;

            case 25:
                blackjack = 10;

            case 26:
                blackjack = 10;

            case 27:
                blackjack = 1;

            case 28:
                blackjack = 2;

            case 29:
                blackjack = 3;

            case 30:
                blackjack = 4;

            case 31:
                blackjack = 5;

        case 32:
                blackjack = 6;

            case 33:
                blackjack = 7;

            case 34:
                blackjack = 8;

            case 35:
                blackjack = 9;

            case 36:
                blackjack = 10;

            case 37:
                blackjack = 10;

            case 38:
                blackjack = 10;

            case 39:
                blackjack = 10;

            case 40:
                blackjack = 1;

            case 41:
                blackjack = 2;

        case 42:
                blackjack = 3;

            case 43:
                blackjack = 4;

            case 44:
                blackjack = 5;

            case 45:
                blackjack = 6;

            case 46:
                blackjack = 7;

            case 47:
                blackjack = 8;

            case 48:
                blackjack = 9;

            case 49:
                blackjack = 10;

            case 50:
                blackjack = 10;

            case 51:
                blackjack = 10;

        case 52:
                blackjack = 10;

            case 53:
                blackjack = 0;

            case 54:
                blackjack = 0;

            blackjack + result = result; // error here
    }
}
    //add(new JLabel(result));
    //if (result == 21)
    add(new JLabel("Black Jack!"));
    //else if(result != 21)
    //add(new JLabel("Sorry, You do not have Black Jack."));

}
public static void main(String[] args) {
    DisplayCards frame = new DisplayCards();
    frame.setTitle("Black Jack!");
    frame.setSize(300, 170);
    frame.setDefaultCloseOperation(3);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
}

错误:

DisplayCards.java:196: error: unexpected type
            blackjack + result = result; 
                      ^
 required: variable
 found:    value
 1 error
4

1 回答 1

1

在 Java 中,您应该执行如下分配:

result = blackjack + result;

对您来说,学习该语言的基本教程可能也是一个好主意。试试这个

于 2014-02-24T04:04:42.303 回答