package day02; import javax.print.attribute.standard.JobName; import javax.swing.*; import java.util.ArrayList; import java.util.Collections; import java.util.Timer; import java.util.TimerTask; public class Y { public static void main(String[] args) { JFrame frame = new JFrame("羊了个羊"); JPanel panel = new JPanel(null);//消除布局 JLabel background = new JLabel(new ImageIcon("images/背景.jpg")); frame.setIconImage(new ImageIcon("images/草.png").getImage()); background.setSize(480,800); panel.add(background); frame.add(panel); frame.setSize(492,842); frame.setLocationRelativeTo(null);//窗口居中 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置关闭窗口,关闭程序 initGame(panel); frame.setVisible(true); } private static void initGame(JPanel panel) { ArrayList<JButton> cards = creatCards(9); ArrayList<JButton> trough = new ArrayList<>();//trough 槽子 Collections.shuffle(cards);//洗牌 poseForCards(panel, cards,7,7,0,30,100); poseForCards(panel, cards,6,6,49,60,130); poseForCards(panel, cards,5,7,49+36,30,160); poseForCards(panel, cards,6,6,49+36+35,60,130+60); checkCovered(cards); addAction(cards, trough, panel);//点击事件 } /** * 从槽子里删除成对的牌 * @param trough 槽子 * @param index 刚刚插入的卡牌位置 * @param current 刚刚插入的卡牌 * @param panel 面板 */ static Timer timer = new Timer(); public static void r
羊了个羊(面向过程简单实现)
最新推荐文章于 2024-05-18 09:59:11 发布