Java 如何在GUI中洗牌/发牌
大家好,我正在制作一个GUI。这将是一款名为“战争”的纸牌游戏,我想做的是在用户和计算机之间随机分割纸牌。我制作了三个阵列,一个用于你的计算机和整个甲板,我制作了一个for循环,其中没有任何内容,因为我尝试的一切都不起作用。任何帮助都将不胜感激Java 如何在GUI中洗牌/发牌,java,user-interface,war,shuffle,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,
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>
公共类多屏幕{
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 };
静态int[]playerDeck;//玩家组
static int[]opponentDeck;//计算机组
静态字符串tMade=新字符串();
静态int turnsMade=0;
静态int warsDeclared=0;
私人JFrame FRMWARCARDARGAME;
JPanel PanelScreen 1;
JPanel PanelScreen 2;
Random rand=新的Random();
私有JTextField textField;
私有JTextField textField_1;
私有JTextField textField_2;
私有JTextField textField_3;
/**
*启动应用程序。
*/
公共静态void main(字符串[]args){
invokeLater(新的Runnable(){
公开募捐{
试一试{
WarMultiScreen窗口=新建WarMultiScreen();
window.frmWarcardGame.setVisible(true);
}捕获(例外e){
e、 printStackTrace();
}
}
});
}
/**
*创建应用程序。
*/
公共屏幕(){
初始化();
}
/**
*初始化框架的内容。
*/
私有void初始化(){
FRMWARCARDCAME=新JFrame();
设置标题(“战争(纸牌游戏)”;
frmWarcardGame.挫折(100100450300);
frmWarcardGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmWarcardGame.getContentPane().setLayout(新的CardLayout(0,0));
panelScreen1=新的JPanel();
面板屏幕1.背景(新颜色(1242520));
frmWarcardGame.getContentPane().add(面板屏幕1,
“名称(180601670832760”);
panelScreen1.setLayout(空);
panelScreen2=新的JPanel();
面板屏幕2.背景(颜色:黑色);
frmWarcardGame.getContentPane().add(面板屏幕2,
“名称(1806203033895729”);
//洗牌牌套牌循环
对于(int i=0;i请看这个问题来洗牌数组:
洗牌后,在阵列上迭代,并将牌发给玩家阵列。如下所示:
for(int i = 0; i < cards.size(); i++){
if(i % 2 == 0){
userDeck.add(i);
} else{
computerDeck.add(i)
}
}
for(int i=0;i
我做了所有的事情,但当我去做。添加时,它说将不适用于int[]使用arraylist,而不是原始数组。