Java 编写的连连看游戏(第二个) 窗体程序 直接运行

今天,为分享的第二个连连看游戏的开发与制作。今天分享第二个版本的连连看游戏比第一个功能更加漂亮和强大,希望大家可以喜欢。喜欢的帮忙点赞和关注,一起学习编程技术、一起进步。

开发环境

开发语言为Java,开发环境Eclipse或者IDEA都可以。运行主程序,或者执行打开JAR文件即可以运行本程序。运行程序可以对准Main.Java文件,点右键 run as application,也可以打包成jar包,双击JAR包即可以。

系统框架

利用JDK自带的SWING框架开发,不需要安装第三方JAR包。纯窗体模式,直接运行Main文件即可以。同时带有详细得设计文档

游戏规则

选择两个点,如果两点的图片完全一样,并且两点之间可以用不超过3条直线连接起来,则该两点可以消除。

积分规则

1 在限定时间内完成,超过200秒,则没有时间奖励分

2 时间奖励分为剩余时间*2,即每提前一秒钟奖励2分

3 当已经选择点后,如果选择的第二个点与第一个点之间无法消除,扣一份,如有解则增加10分

4 使用提示功能,提示成功后,则扣10分

游戏运行效果

1 主界面

2 游戏结束界面

3 游戏规则、计分、排行榜

4 关于游戏

关键代码

package com.yunzhi.lianliankan;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

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

public  class Lianliankan extends JFrame implements WindowListener,ActionListener{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    /**
     * @param args
     */
    JPanel panel;
    JButton button;
    JLabel label;
    ImageIcon img;
    Dimension screen;
    int SCRW,SCRH;
    int COLS,ROWS;
    int activity;
    int imgw,imgh;
    public Lianliankan()
    {
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        screen=Toolkit.getDefaultToolkit().getScreenSize();
        img=new ImageIcon("src/menu.png");
        SCRH=img.getIconHeight();
        SCRW=img.getIconWidth();
        this.setBounds(screen.width/2-SCRW/2,screen.height/2-SCRH/2,SCRW,SCRH);
        this.setTitle("lianliankan");
        label=new JLabel(img);
        label.setBounds(0,0,SCRW,SCRH);
        this.getLayeredPane().add(label,new Integer(Integer.MIN_VALUE));
        this.setLayout(null);
        panel=new JPanel();
        panel.setLayout(null);
        panel.setBounds(0,SCRH/2,SCRW,SCRH/2);
        buttonCreated("src/start.png","start",0);
        buttonCreated("src/more.png","more",1);
        panel.setOpaque(false);
        this.setContentPane(panel);
        this.setVisible(true);
    }
    public Lianliankan(int i)
    {
        COLS=6;
        ROWS=5;
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        screen=Toolkit.getDefaultToolkit().getScreenSize();
        img=new ImageIcon("src/youxi.png");
        SCRH=img.getIconHeight();
        SCRW=img.getIconWidth();
        this.setBounds(screen.width/2-SCRW/2,screen.height/2-SCRH/2,SCRW,SCRH);
        this.setTitle("lianliankna");
        label=new JLabel(img);
        label.setBounds(0,0,SCRW,SCRH);
        this.getLayeredPane().add(label,new Integer(Integer.MIN_VALUE));
        this.setLayout(null);
        panel=new JPanel();
        panel.setLayout(null);
        panel.setBounds(SCRH/2,SCRH/2,SCRW,SCRH/2);
        img=new ImageIcon("src/1.png");
        imgw=img.getIconWidth()+2;
        imgh=img.getIconHeight()+2;
        for(int cols = 1;cols < 6;cols++)
        { 
            for(int rows = 0;rows < 5;rows++ )
            {
                buttonCreated2("src/"+cols+".png",cols+"",cols*imgw,rows*imgh,imgw,imgh);
            }
        }
        panel.setOpaque(false);
        this.setContentPane(panel);
        this.setVisible(true);
    }
    public void buttonCreated(String file,String command,int y)
    {
        img=new ImageIcon(file);
        button=new JButton(img);
        button.setBounds(SCRW/2-img.getIconWidth()/2,SCRH/2+y*img.getIconHeight(),img.getIconWidth(),img.getIconHeight());
        button.setContentAreaFilled(false);
        button.addActionListener(this);
        button.setActionCommand(command);
        panel.add(button);
    }
    public void buttonCreated2(String file,String command,int x,int y,int w,int h)
    {
        img=new ImageIcon(file);
        button=new JButton(img);
        button.setBounds(x,y,imgw,imgh);
        button.setContentAreaFilled(false);
        button.addActionListener(this);
        button.setActionCommand(command);
        panel.add(button);
    }
    public void actionPerformed(ActionEvent e) 
    {
        // TODO Auto-generated method stub
        button=(JButton)e.getSource();
        if(button.getActionCommand().equals("start"))
        {
            this.dispose();
            //Lianliankan lianliankan=new Lianliankan(1);
            Game llk = new Game(); 
            llk.randomBuild(); 
            llk.init(); 
        }
        if(button.getActionCommand().equals("more"))
        {
            this.dispose();
            new Lianliankan(1);
            System.out.println("没有更多游戏");
        }
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new Lianliankan();
    }
    public void windowActivated(WindowEvent arg0) {
        // TODO Auto-generated method stub
        
    }
    public void windowClosed(WindowEvent arg0) {
        // TODO Auto-generated method stub
        
    }
    public void windowClosing(WindowEvent arg0) {
        // TODO Auto-generated method stub
        
    }
    public void windowDeactivated(WindowEvent arg0) {
        // TODO Auto-generated method stub
        
    }
    public void windowDeiconified(WindowEvent arg0) {
        // TODO Auto-generated method stub
        
    }
    public void windowIconified(WindowEvent arg0) {
        // TODO Auto-generated method stub
        
    }
    public void windowOpened(WindowEvent arg0) {
        // TODO Auto-generated method stub
        
    }

}

项目总结

开发一套系统,最重要的是细心,并不是一定要做到面面俱到,在准备工作中要正确分析社会需求了解现实应用,画出流程图,把大体框架做好,然后再逐一细化。我们不可能做到面面俱到,但一定要做到步步扎实,作为一个程序编程人员,要保持清醒的头脑,以现实为依据,让自己的每一行代码都能实现自己的意义。 通过这次课程设计,我收获的不仅仅是课程上的知识得到实际应用,还有编程的基本习惯和开发系统时应注意的流程。

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

计算机程序

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值