首页 > 专栏

java连连看小游戏代码大全_连连看小游戏java源代码(1)

更新时间:2023-12-11 19:05:11 阅读: 评论:0

2023年12月11日发(作者:啤酒几度)

-

java连连看小游戏代码大全_连连看小游戏java源代码(1)

java连连看小游戏代码大全_连连看小游戏java源代码(1)

//MainView 主界面

import Layout;

import ;

import yout;

import Event;

import Listener;

import Adapter;

import Event;

import .*;

public class MainView extends JFrame implements ActionListener{

private static final long rialVersionUID = -87730570L;

public static JLabel fractionLable=new JLabel("0"); //分数标签

public static int count =0;

private JMenuBar menuBar;

private JMenu menu;

private JMenuItem MenuItem1;

private JMenuItem MenuItem2;

private JMenuItem MenuItem3;

private JButton exitButton,newlyButton; //退出,重列,重新开始按钮

private JPanel centerPanel,pane5;

private JPanel northPanel;

private int row = 7;

private int col = 8;

private MyThread myThread;

private int time = 100; //单位为秒

private JProgressBar aJProgressBar;

public MainView(){

initView();

}

private void initView(){

centerPanel = new JPanel();

out(new BorderLayout());

pane5 =new CenterPanel(row,col);(pane5,);

JPanel mainPanel=new JPanel();

tNorthPanel();

(northPanel,);

(centerPanel,);

myThread = new MyThread(){

protected void runPersonelLogic(){

int minimum = imum();

if(ue() != minimum){

int value = ue();

n(value);

try {

(1000);

ue(ue() - 1);

} catch (InterruptedException e){

tackTrace();

}

if(count ==row*col/2){

pend(true);

int i= nfirmDialog

(null,"恭喜过关了,是否继续?", "游戏提示", _NO_OPTION,

ON_MESSAGE);

if(i==0){

pend(fal);

(pane5);

pane5 =new CenterPanel(row,col);

(pane5);

count = 0;

ue(time);

date();

}

}

}el{

pend(true);int i =tionDialog

(null,"大侠,时间到了!","游戏提示",_CANCEL_OPTION,

ATION_MESSAGE,null,

new String[]{"重来","取消"},"重来");

if(i==0){

restart();

}

}

}

};

();

dowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e){

(0);

}

});

tentPane().add(mainPanel);

nuBar();

le("连连看");

ible(true);

nds(280,100,600,650);

izable(fal);

}

private void tJMenuBar() {

MenuItem1 = new JMenuItem("重新开始");

ionListener(this);

MenuItem2 = new JMenuItem("关于");

ionListener(this);

MenuItem3 = new JMenuItem("退出");

ionListener(this);

menu = new JMenu("菜单");

menuBar = new JMenuBar();

(MenuItem1);

(MenuItem2);(MenuItem3);

(menu);

nuBar(menuBar);

}

private void tNorthPanel(){

northPanel=new JPanel();

out(new FlowLayout());

(new JLabel("分数:"));

(fractionLable);

(new JLabel("时间:"));

aJProgressBar = new JProgressBar(0,time);

ue(time);

ingPainted(true);

kground();

eground();

(aJProgressBar);

exitButton=new JButton("退出");

ionListener(this);

newlyButton=new JButton("再来一局");

ionListener(this);

(exitButton);

(newlyButton);

}

public static void main(String args[]){

new MainView();

}

public void actionPerformed(ActionEvent e) {

if(rce()==exitButton||ionCommand().equals("退出")){

(0);

}

if(rce()==newlyButton||ionCommand().equals("重新开始")){

restart();

}

}private void restart() {

t("0");

if(pane5 != null){

(pane5);

}

pane5 =new CenterPanel(row,col);

(pane5);

count = 0;

ue(time);

pend(fal);

date();

}

}

//自写的button按钮

import ;

import n;

public class MyButton extends JButton {

private static final long rialVersionUID = -76564578L;

private int row;

private int col;

private int pictrueId;

private boolean isBlank;

private boolean isCleaned = fal;

public MyButton(int row,int col,int pictrueId){

=row;

=col;

eId = pictrueId;

gin(new Ints(0,0,0,0));

}

public MyButton() {

}

public int getRow() {

return row;

}public void tRow(int row) {

= row;

}

public int getCol() {

return col;

}

public void tCol(int col) {

= col;

}

public int getPictrueId() {

return pictrueId;

}

public void tPictrueId(int pictrueId) {

eId = pictrueId;

}

public boolean isBlank() {

return isBlank;

}

public void tBlank(boolean isBlank) {

k = isBlank;

}

public boolean isCleaned() {

return isCleaned;

}

public void tCleaned(boolean isCleaned) {

ned = isCleaned;

}

}

//

public abstract class MyThread extends Thread {

private boolean suspend = fal;

private String control = ""; //只是需要一个对象而已,这个对象没有实际意义

public void tSuspend(boolean suspend) {

if(!suspend) {synchronized(control) {

All();

}

}

d = suspend;

}

public boolean isSuspend() {

return d;

}

public void run() {

while(true) {

synchronized(control){

if(suspend) {

try {

();

} catch (InterruptedException e) {

tackTrace();

}

}

}sonelLogic();

}

}

protected abstract void runPersonelLogic();

}

分两页篇写,以上都是基础。还有主功能模块。一般不想写什么评论,这些东西很多人做过,至于连连看算法,网上都有,不过细节很重

要,也就是你知道算法,还不一定能一次搞定,为此我也是检查检查在检查,终于主功能OK了。接下篇。。。

-

java连连看小游戏代码大全_连连看小游戏java源代码(1)

本文发布于:2023-12-11 19:05:10,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/zhishi/a/1702292711243251.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:java连连看小游戏代码大全_连连看小游戏java源代码(1).doc

本文 PDF 下载地址:java连连看小游戏代码大全_连连看小游戏java源代码(1).pdf

标签:对象   小游戏   重列
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 实用文体写作网旗下知识大全大全栏目是一个全百科类宝库! 优秀范文|法律文书|专利查询|