羊了个羊(面向过程简单实现)

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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值