如何在GUI

时间:2015-06-07 15:05:32

标签: java user-interface war shuffle

大家好我正在制作GUI。这将是一个名为战争的纸牌游戏我想要做的是在用户和计算机之间随机分割。我已经为你的计算机制作了三个数组,并且完整的套牌我做了一个没有任何内容的for循环,因为我尝试的一切都没有用。任何帮助将不胜感激

public class WarMultiScreen {

static int[] fullDeck = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
        15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
        32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
        49, 50, 51, 52 };
static int[] playerDeck; // the players deck
static int[] opponentDeck; // the computers deck

static String tMade = new String();
static int turnsMade = 0;
static int warsDeclared = 0;
private JFrame frmWarcardGame;
JPanel panelScreen1;
JPanel panelScreen2;
Random rand = new Random();
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                WarMultiScreen window = new WarMultiScreen();
                window.frmWarcardGame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the application.
 */
public WarMultiScreen() {
    initialize();
}

/**
 * Initialize the contents of the frame.
 */
private void initialize() {
    frmWarcardGame = new JFrame();
    frmWarcardGame.setTitle("War (Card Game)");
    frmWarcardGame.setBounds(100, 100, 450, 300);
    frmWarcardGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frmWarcardGame.getContentPane().setLayout(new CardLayout(0, 0));

    panelScreen1 = new JPanel();
    panelScreen1.setBackground(new Color(124, 252, 0));
    frmWarcardGame.getContentPane().add(panelScreen1,
            "name_180601670832760");
    panelScreen1.setLayout(null);

    panelScreen2 = new JPanel();
    panelScreen2.setBackground(Color.BLACK);
    frmWarcardGame.getContentPane().add(panelScreen2,
            "name_180620303895729");
     // Loop for shuffling deck
    for (int i = 0; i <= fullDeck.length; i++) {


    }</i>

1 个答案:

答案 0 :(得分:0)

看看这个问题来改变你的数组: Random shuffling of an array

一旦它被改组,迭代阵列并将牌交给球员阵列。像这样:

for(int i = 0; i < cards.size(); i++){
    if(i % 2 == 0){
        userDeck.add(i);
    } else{
        computerDeck.add(i)
    }
}