挖金矿游戏java源代码 挖金矿小游戏在线玩手机版

急求JAVA源代码 , 小游戏或者别的//这是个聊天程序, 在ECLIPSE 运行 Client.java 就可以了 。连接是:localhost
//Server 代码,
package message;
import java.io.*;
import java.net.*;
import java.util.*;
public class Server {
public static void main(String[] args) throws Exception{
System.out.print("Server");
ServerSocket socket=new ServerSocket(8888);
Vector v=new Vector();
while(true){
Socket sk=socket.accept();
DataInputStream in=new DataInputStream(sk.getInputStream());
DataOutputStream out=new DataOutputStream(sk.getOutputStream());
v.add(sk);
new ServerThread(in,v).start();
}
}
}
//ServerThread.java 代码
package message;
import java.net.*;
import java.io.*;
import java.util.*;
public class ServerThread extends Thread{
DataInputStream in;
Vector all;
public ServerThread(DataInputStream in,Vector v){
this.in=in;
this.all=v;
}
public void run()
{
while(true)
{
try{
String s1=in.readUTF();
for(int i=0;iall.size();i)
{
Object obj=all.get(i);
Socket socket=(Socket)obj;
DataOutputStream out=new DataOutputStream(socket.getOutputStream());
out.writeUTF(s1);
System.out.print(i);
out.flush();
}
System.out.print("Message send over!");
}catch(Exception e){e.printStackTrace();};
}
}
}
//ClientFrame.java 代码
package message;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
import java.io.*;
public class ClientFrame extends JFrame implements ActionListener{
JButton b1=new JButton ("SendMessage");
JButton b2=new JButton("Link Server");
JTextField t1=new JTextField(20);
JTextField t2=new JTextField(20);
JLabel l=new JLabel("输入服务器名字:");
JTextArea area=new JTextArea(10,20);
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JPanel p3=new JPanel();
JPanel p4=new JPanel();
Socket socket;
public ClientFrame()
{
this.getContentPane().add(p1);
p2.add(new JScrollPane(area));
p3.add(t1);
p3.add(b1);
p4.add(l);
p4.add(t2);
p4.add(b2);
p2.setLayout(new FlowLayout());
p3.setLayout(new FlowLayout());
p4.setLayout(new FlowLayout());
p1.setLayout(new BorderLayout());
p1.add("North",p2);
p1.add("Center",p3);
p1.add("South",p4);
b1.addActionListener(this);
b2.addActionListener(this);
this.pack();
show();
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("Link Server"))
{
try{
socket=new Socket(t2.getText(),8888);
b2.setEnabled(false);
JOptionPane.showMessageDialog(this, "Connection Success");
DataInputStream in=new DataInputStream(socket.getInputStream());
new ClientThread(in,area).start();
}
catch(Exception e1){
JOptionPane.showMessageDialog(this, "Connection Error");
e1.printStackTrace();};
}
else if(e.getActionCommand().equals("SendMessage"))
{
try{
DataOutputStream out=new DataOutputStream(socket.getOutputStream());
out.writeUTF(t1.getText());
t1.setText("");
}catch(Exception e1){e1.printStackTrace();};
}
}
}
//ClientThread.java 代码
package message;
import java.net.*;
import java.io.*;
import javax.swing.*;
public class ClientThread extends Thread {
DataInputStream in;
JTextArea area;
public ClientThread(DataInputStream in,JTextArea area){
this.in=in;
this.area=area;
}
public void run()
{
while(true){
try{
String s=in.readUTF();
area.append(s);
}
catch(Exception e){e.printStackTrace();};
}
}
}
//Client.java代码
package message;
public class Client {
/**
* @param args
*/
public static void main(String[] args) {
new ClientFrame();
}
}
// 每段代码都是个类,不要弄在一个文件里 。运行 Client.java
good luck to you!
求一款java手机游戏,里面有骑士,有农民,农民会挖矿,有金矿,可以建兵营,可以建攻城车 , 可以建好像还有采石厂,没有的话村民会放到主城里 , 主城可以让村民升级有黑暗时代,封建时代 , 城堡时代等,还有哨塔,建筑都可以升级,可以增加人的数量,开始都是黑的,村民或其他兵种走过后才亮!以前一直玩,就是忘了名字!可能是帝国时代的手机版吧!那时还是按键手机
求一个JAVA游戏代码?。。〖保 。。?/h2>俄罗斯方块——java源代码提供
import java.awt.*;
import java.awt.event.*;
//俄罗斯方块类
public class ERS_Block extends Frame{
public static boolean isPlay=false;
public static int level=1,score=0;
public static TextField scoreField,levelField;
public static MyTimer timer;
GameCanvas gameScr;
public static void main(String[] argus){
ERS_Block ers = new ERS_Block("俄罗斯方块游戏 V1.0 Author:Vincent");
WindowListener win_listener = new WinListener();
ers.addWindowListener(win_listener);
}
//俄罗斯方块类的构造方法
ERS_Block(String title){
super(title);
setSize(600,480);
setLayout(new GridLayout(1,2));
gameScr = new GameCanvas();
gameScr.addKeyListener(gameScr);
timer = new MyTimer(gameScr);
timer.setDaemon(true);
timer.start();
timer.suspend();
add(gameScr);
Panel rightScr = new Panel();
rightScr.setLayout(new GridLayout(2,1,0,30));
rightScr.setSize(120,500);
add(rightScr);
//右边信息窗体的布局
MyPanel infoScr = new MyPanel();
infoScr.setLayout(new GridLayout(4,1,0,5));
infoScr.setSize(120,300);
rightScr.add(infoScr);
//定义标签和初始值
Label scorep = new Label("分数:",Label.LEFT);
Label levelp = new Label("级数:",Label.LEFT);
scoreField = new TextField(8);
levelField = new TextField(8);
scoreField.setEditable(false);
levelField.setEditable(false);
infoScr.add(scorep);
infoScr.add(scoreField);
infoScr.add(levelp);
infoScr.add(levelField);
scorep.setSize(new Dimension(20,60));
scoreField.setSize(new Dimension(20,60));
levelp.setSize(new Dimension(20,60));
levelField.setSize(new Dimension(20,60));
scoreField.setText("0");
levelField.setText("1");
//右边控制按钮窗体的布局
MyPanel controlScr = new MyPanel();
controlScr.setLayout(new GridLayout(5,1,0,5));
rightScr.add(controlScr);
//定义按钮play
Button play_b = new Button("开始游戏");
play_b.setSize(new Dimension(50,200));
play_b.addActionListener(new Command(Command.button_play,gameScr));
//定义按钮Level UP
Button level_up_b = new Button("提高级数");
level_up_b.setSize(new Dimension(50,200));
level_up_b.addActionListener(new Command(Command.button_levelup,gameScr));
//定义按钮Level Down
Button level_down_b =new Button("降低级数");
level_down_b.setSize(new Dimension(50,200));
level_down_b.addActionListener(new Command(Command.button_leveldown,gameScr));
//定义按钮Level Pause
Button pause_b =new Button("游戏暂停");
pause_b.setSize(new Dimension(50,200));
pause_b.addActionListener(new Command(Command.button_pause,gameScr));
//定义按钮Quit
Button quit_b = new Button("退出游戏");
quit_b.setSize(new Dimension(50,200));
quit_b.addActionListener(new Command(Command.button_quit,gameScr));
controlScr.add(play_b);
controlScr.add(level_up_b);
controlScr.add(level_down_b);
controlScr.add(pause_b);
controlScr.add(quit_b);
setVisible(true);
gameScr.requestFocus();
}
}
//重写MyPanel类,使Panel的四周留空间
class MyPanel extends Panel{
public Insets getInsets(){
return new Insets(30,50,30,50);
}
}
//游戏画布类
class GameCanvas extends Canvas implements KeyListener{
final int unitSize = 30; //小方块边长
int rowNum; //正方格的行数
int columnNum; //正方格的列数
int maxAllowRowNum; //允许有多少行未削
int blockInitRow; //新出现块的起始行坐标
int blockInitCol; //新出现块的起始列坐标
int [][] scrArr; //屏幕数组
Block b; //对方快的引用
//画布类的构造方法
GameCanvas(){
rowNum = 15;
columnNum = 10;
maxAllowRowNum = rowNum - 2;
b = new Block(this);
blockInitRow = rowNum - 1;
blockInitCol = columnNum/2 - 2;
scrArr = new int [32][32];
}
//初始化屏幕,并将屏幕数组清零的方法
void initScr(){
for(int i=0;irowNum;i)
for (int j=0; jcolumnNum;j)
scrArr[j]=0;
b.reset();
repaint();
}
//重新刷新画布方法
public void paint(Graphics g){
for(int i = 0; irowNum; i)
for(int j = 0; jcolumnNum; j)
drawUnit(i,j,scrArr[j]);
}
//画方块的方法
public void drawUnit(int row,int col,int type){
scrArr[row][col] = type;
Graphics g = getGraphics();
tch(type){ //表示画方快的方法
case 0: g.setColor(Color.black);break; //以背景为颜色画
case 1: g.setColor(Color.blue);break; //画正在下落的方块
case 2: g.setColor(Color.magenta);break; //画已经落下的方法
}
g.fill3DRect(col*unitSize,getSize().height-(row 1)*unitSize,unitSize,unitSize,true);
g.dispose();
}
public Block getBlock(){
return b; //返回block实例的引用
}
//返回屏幕数组中(row,col)位置的属性值
public int getScrArrXY(int row,int col){
if (row0 || row = rowNum || col0 || col = columnNum)
return(-1);
else
return(scrArr[row][col]);
}
//返回新块的初始行坐标方法
public int getInitRow(){
return(blockInitRow); //返回新块的初始行坐标
}
//返回新块的初始列坐标方法
public int getInitCol(){
return(blockInitCol); //返回新块的初始列坐标
}
//满行删除方法
void deleteFullLine(){
int full_line_num = 0;
int k = 0;
for (int i=0;irowNum;i){
boolean isfull = true;
L1:for(int j=0;jcolumnNum;j)
if(scrArr[j] == 0){
k;
isfull = false;
break L1;
}
if(isfull) full_line_num;
if(k!=0k-1!=i!isfull)
for(int j = 0; jcolumnNum; j){
if (scrArr[j] == 0)
drawUnit(k-1,j,0);
else
drawUnit(k-1,j,2);
scrArr[k-1][j] = scrArr[j];
}
}
for(int i = k-1 ;irowNum; i){
for(int j = 0; jcolumnNum; j){
drawUnit(i,j,0);
scrArr[j]=0;
}
}
ERS_Block.score= full_line_num;
ERS_Block.scoreField.setText("" ERS_Block.score);
}
//判断游戏是否结束方法
boolean isGameEnd(){
for (int col = 0 ; col columnNum; col){
if(scrArr[maxAllowRowNum][col] !=0)
return true;
}
return false;
}
public void keyTyped(KeyEvent e){
}
public void keyReleased(KeyEvent e){
}
//处理键盘输入的方法
public void keyPressed(KeyEvent e){
if(!ERS_Block.isPlay)
return;
tch(e.getKeyCode()){
case KeyEvent.VK_DOWN:b.fallDown();break;
case KeyEvent.VK_LEFT:b.leftMove();break;
case KeyEvent.VK_RIGHT:b.rightMove();break;
case KeyEvent.VK_SPACE:b.leftTurn();break;
}
}
}
//处理控制类
class Command implements ActionListener{
static final int button_play = 1; //给按钮分配编号
static final int button_levelup = 2;
static final int button_leveldown = 3;
static final int button_quit = 4;
static final int button_pause = 5;
static boolean pause_resume = true;
int curButton; //当前按钮
GameCanvas scr;
//控制按钮类的构造方法
Command(int button,GameCanvas scr){
curButton = button;
this.scr=scr;
}
//按钮执行方法
public void actionPerformed (ActionEvent e){
tch(curButton){
case button_play:if(!ERS_Block.isPlay){
scr.initScr();
ERS_Block.isPlay = true;
ERS_Block.score = 0;
ERS_Block.scoreField.setText("0");
ERS_Block.timer.resume();
}
scr.requestFocus();
break;
case button_levelup:if(ERS_Block.level10){
ERS_Block.level;
ERS_Block.levelField.setText("" ERS_Block.level);
ERS_Block.score = 0;
ERS_Block.scoreField.setText("" ERS_Block.score);
}
scr.requestFocus();
break;
case button_leveldown:if(ERS_Block.level1){
ERS_Block.level--;
ERS_Block.levelField.setText("" ERS_Block.level);
ERS_Block.score = 0;
ERS_Block.scoreField.setText("" ERS_Block.score);
}
scr.requestFocus();
break;
case button_pause:if(pause_resume){
ERS_Block.timer.suspend();
pause_resume = false;
}else{
ERS_Block.timer.resume();
pause_resume = true;
}
scr.requestFocus();
break;
case button_quit:System.exit(0);
}
}
}
//方块类
class Block {
static int[][] pattern = {
{0x0f00,0x4444,0x0f00,0x4444},//用十六进至表示,本行表示长条四种状态
{0x04e0,0x0464,0x00e4,0x04c4},
{0x4620,0x6c00,0x4620,0x6c00},
{0x2640,0xc600,0x2640,0xc600},
{0x6220,0x1700,0x2230,0x0740},
{0x6440,0x0e20,0x44c0,0x8e00},
{0x0660,0x0660,0x0660,0x0660}
};
int blockType; //块的模式号(0-6)
int turnState; //块的翻转状态(0-3)
int blockState; //快的下落状态
int row,col; //块在画布上的坐标
GameCanvas scr;
//块类的构造方法
Block(GameCanvas scr){
this.scr = scr;
blockType = (int)(Math.random() * 1000)%7;
turnState = (int)(Math.random() * 1000)%4;
blockState = 1;
row = scr.getInitRow();
col = scr.getInitCol();
}
//重新初始化块,并显示新块
public void reset(){
blockType = (int)(Math.random() * 1000)%7;
turnState = (int)(Math.random() * 1000)%4;
blockState = 1;
row = scr.getInitRow();
col = scr.getInitCol();
dispBlock(1);
}
//实现“块”翻转的方法
public void leftTurn(){
if(assertValid(blockType,(turnState1)%4,row,col)){
dispBlock(0);
turnState = (turnState1)%4;
dispBlock(1);
}
}
//实现“块”的左移的方法
public void leftMove(){
if(assertValid(blockType,turnState,row,col-1)){
dispBlock(0);
col--;
dispBlock(1);
}
}
//实现块的右移
public void rightMove(){
if(assertValid(blockType,turnState,row,col 1)){
dispBlock(0);
col;
dispBlock(1);
}
}
//实现块落下的操作的方法
public boolean fallDown(){
if(blockState == 2)
return(false);
if(assertValid(blockType,turnState,row-1,col)){
dispBlock(0);
row--;
dispBlock(1);
return(true);
}else{
blockState = 2;
dispBlock(2);
return(false);
}
}
//判断是否正确的方法
boolean assertValid(int t,int s,int row,int col){
int k = 0x8000;
for(int i = 0; i4; i){
for(int j = 0; j4; j){
if((int)(pattern[t][s]k) != 0){
int temp = scr.getScrArrXY(row-i,col j);
if (temp0||temp==2)
return false;
}
k = k1;
}
}
return true;
}
//同步显示的方法
public synchronized void dispBlock(int s){
int k = 0x8000;
for (int i = 0; i4; i){
for(int j = 0; j4; j){
if(((int)pattern[blockType][turnState]k) != 0){
scr.drawUnit(row-i,col j,s);
}
k=k1;
}
}
}
}
//定时线程
class MyTimer extends Thread{
GameCanvas scr;
public MyTimer(GameCanvas scr){
this.scr = scr;
}
public void run(){
while(true){
try{
sleep((10-ERS_Block.level1)*100);
}
catch(InterruptedException e){}
if(!scr.getBlock().fallDown()){
scr.deleteFullLine();
if(scr.isGameEnd()){
ERS_Block.isPlay = false;
suspend();
}else
scr.getBlock().reset();
}
}
}
class WinListener extends WindowAdapter{
public void windowClosing (WindowEvent l){
System.exit(0);
}
}
求java小游戏源代码import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioSystem;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Rectangle;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JSlider;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.File;
import java.util.Vector;
public class Frame extends JFrame implements Runnable {
JPanel contentPane;
JPanel jPanel1 = new JPanel();
JButton jButton1 = new JButton();
JSlider jSlider1 = new JSlider();
JLabel jLabel1 = new JLabel();
JButton jButton2 = new JButton();
JLabel jLabel2 = new JLabel();
int count = 1, rapidity = 80; // count 当前进行的个数, rapidity 游标的位置
int zhengque = 0, cuowu = 0;
int rush[] = { 10 ,20 ,30 };//游戏每关的个数 可以自由添加.列 { 10 ,20 ,30 ,40,50}
int rush_count = 0;//记录关数
char list[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9' };//随机出现的数字 可以自由添加
Vector number = new Vector();
String paiduan = "true";
AudioClip Musci_anjian, Music_shibai, Music_chenggong;
public Frame() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
//-----------------声音文件---------------------
Musci_anjian = Applet.newAudioClip(new File("sounds//anjian.wav")
.toURL());
Music_shibai = Applet.newAudioClip(new File("sounds//shibai.wav")
.toURL());
Music_chenggong = Applet.newAudioClip(new File(
"sounds//chenggong.wav").toURL());
//---------------------------------------
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(588, 530));
setTitle("Frame Title");
jPanel1.setBorder(BorderFactory.createEtchedBorder());
jPanel1.setBounds(new Rectangle(4, 4, 573, 419));
jPanel1.setLayout(null);
jButton1.setBounds(new Rectangle(277, 442, 89, 31));
jButton1.setText("开始");
jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
jSlider1.setBounds(new Rectangle(83, 448, 164, 21));
jSlider1.setMaximum(100);
jSlider1.setMinimum(1);
jSlider1.setValue(50);
jLabel1.setText("速度");
jLabel1.setBounds(new Rectangle(35, 451, 39, 18));
jButton2.setBounds(new Rectangle(408, 442, 89, 31));
jButton2.setText("结束");
jButton2.addActionListener(new Frame1_jButton2_actionAdapter(this));
jLabel2.setText("第一关:100个");
jLabel2.setBounds(new Rectangle(414, 473, 171, 21));
contentPane.add(jPanel1);
contentPane.add(jButton2);
contentPane.add(jButton1);
contentPane.add(jSlider1);
contentPane.add(jLabel1);
contentPane.add(jLabel2);
this.addKeyListener(new MyListener());
jButton1.addKeyListener(new MyListener());
jSlider1.addKeyListener(new MyListener());
jSlider1.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
rapidity = jSlider1.getValue();
}
});
}
public void run() {
number.clear();
zhengque = 0;
cuowu = 0;
paiduan = "true";
while (count = rush[rush_count]) {
try {
Thread t = new Thread(new Tthread());
t.start();
count= 1;
Thread.sleep(1000(int) (Math.random() * 2000)); // 生产下组停顿时间
// 最快1快.最慢2秒
} catch (InterruptedException e) {
e.printStackTrace();
}
}
while (true) { // 等待最后一个字符消失
if (number.size() == 0) {
break;
}
}
if (zhengque == 0) { // 为了以后相除..如果全部正确或者错误就会出现错误. 所以..
zhengque = 1;
}
if (cuowu == 0) {
cuowu = 1;
}
if (paiduan.equals("true")) { // 判断是否是自然结束
if (zhengque / cuowu = 2) {
JOptionPane.showMessageDialog(null, "恭喜你过关了");
rush_count= 1; // 自动加1关
if (rush_countrush.length) {
if (rapidity10) { // 当速度大于10的时候在-5提加速度.怕速度太快
rapidity -= 5; // 速度自动减10毫秒
jSlider1.setValue(rapidity); // 选择位置
}
Thread t = new Thread(this);
t.start();
} else {
JOptionPane.showMessageDialog(null, "牛B...你通关了..");
rush_count = 0;
count = 0;
}
} else {
JOptionPane.showMessageDialog(null, "请再接再励");
rush_count = 0;
count = 0;
}
} else {
rush_count = 0;
count = 0;
}
}
public void jButton1_actionPerformed(ActionEvent e) {
Thread t = new Thread(this);
t.start();
}
public void jButton2_actionPerformed(ActionEvent e) {
count = rush[rush_count]1;
paiduan = "flase";
}
class Tthread implements Runnable {
public void run() {
boolean fo = true;
int Y = 0, X = 0;
JLabel show = new JLabel();
show.setFont(new java.awt.Font("宋体", Font.PLAIN, 33));
jPanel1.add(show);
X = 10(int) (Math.random() * 400);
String parameter = list[(int) (Math.random() * list.length)]"";
Bean bean = new Bean();
bean.setParameter(parameter);
bean.setShow(show);
number.add(bean);
show.setText(parameter);
while (fo) {
// ---------------------数字下移--------------------
show.setBounds(new Rectangle(X, Y= 2, 33, 33));
try {
Thread.sleep(rapidity);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (Y = 419) {
fo = false;
for (int i = number.size() - 1; i = 0; i--) {
Bean bn = ((Bean) number.get(i));
if (parameter.equalsIgnoreCase(bn.getParameter())) {
cuowu= 1;
jLabel2.setText("正确:"zhengque"个,错误:"cuowu
"个");
number.removeElementAt(i);
Music_shibai.play();
break;
}
}
}
}
}
}
class MyListener extends KeyAdapter {
public void keyPressed(KeyEvent e) {
String uu = e.getKeyChar()"";
for (int i = 0; inumber.size(); i) {
Bean bean = ((Bean) number.get(i));
if (uu.equalsIgnoreCase(bean.getParameter())) {
zhengque= 1;
number.removeElementAt(i);
bean.getShow().setVisible(false);
jLabel2.setText("正确:"zhengque"个,错误:"cuowu"个");
Music_chenggong.play();
break;
}
}
Musci_anjian.play();
}
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception exception) {
exception.printStackTrace();
}
Frame frame = new Frame();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.heightscreenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.widthscreenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
}
}
class Frame1_jButton2_actionAdapter implements ActionListener {
private Frame adaptee;
Frame1_jButton2_actionAdapter(Frame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class Frame1_jButton1_actionAdapter implements ActionListener {
private Frame adaptee;
Frame1_jButton1_actionAdapter(Frame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class Bean {
String parameter = null;
JLabel show = null;
public JLabel getShow() {
return show;
}
public void setShow(JLabel show) {
this.show = show;
}
public String getParameter() {
return parameter;
}
public void setParameter(String parameter) {
this.parameter = parameter;
}
}
求一个简单的Java小游戏的代码连连看挖金矿游戏java源代码的小源码
package Lianliankan;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class lianliankan implements ActionListener
{
JFrame mainFrame; //主面板
Container thisContainer;
JPanel centerPanel,southPanel,northPanel; //子面板
JButton diamondsButton[][] = new JButton[6][5];//游戏按钮数组
JButton exitButton,resetButton,newlyButton; //退出挖金矿游戏java源代码 , 重列挖金矿游戏java源代码,重新开始按钮
JLabel fractionLable=new JLabel("0"); //分数标签
JButton firstButton,secondButton; //分别记录两次被选中挖金矿游戏java源代码的按钮
int grid[][] = new int[8][7];//储存游戏按钮位置
static boolean pressInformation=false; //判断是否有按钮被选中
int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戏按钮的位置坐标
int i,j,k,n;//消除方法控制
public void init(){
mainFrame=new JFrame("JKJ连连看");
thisContainer = mainFrame.getContentPane();
thisContainer.setLayout(new BorderLayout());
centerPanel=new JPanel();
southPanel=new JPanel();
northPanel=new JPanel();
thisContainer.add(centerPanel,"Center");
thisContainer.add(southPanel,"South");
thisContainer.add(northPanel,"North");
centerPanel.setLayout(new GridLayout(6,5));
for(int cols = 0;cols6;cols){
for(int rows = 0;rows5;rows){
diamondsButton[cols][rows]=new JButton(String.valueOf(grid[cols 1][rows 1]));
diamondsButton[cols][rows].addActionListener(this);
centerPanel.add(diamondsButton[cols][rows]);
}
}
exitButton=new JButton("退出");
exitButton.addActionListener(this);
resetButton=new JButton("重列");
resetButton.addActionListener(this);
newlyButton=new JButton("再来一局");
newlyButton.addActionListener(this);
southPanel.add(exitButton);
southPanel.add(resetButton);
southPanel.add(newlyButton);
fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())));
northPanel.add(fractionLable);
mainFrame.setBounds(280,100,500,450);
mainFrame.setVisible(true);
}
public void randomBuild() {
int randoms,cols,rows;
for(int twins=1;twins=15;twins) {
randoms=(int)(Math.random()*25 1);
for(int alike=1;alike=2;alike) {
cols=(int)(Math.random()*6 1);
rows=(int)(Math.random()*5 1);
while(grid[cols][rows]!=0) {
cols=(int)(Math.random()*6 1);
rows=(int)(Math.random()*5 1);
}
this.grid[cols][rows]=randoms;
}
}
}
public void fraction(){
fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText()) 100));
}
public void reload() {
int save[] = new int[30];
int n=0,cols,rows;
int grid[][]= new int[8][7];
for(int i=0;i=6;i) {
for(int j=0;j=5;j) {
if(this.grid[i][j]!=0) {
save[n]=this.grid[i][j];
n;
}
}
}
n=n-1;
this.grid=grid;
while(n=0) {
cols=(int)(Math.random()*6 1);
rows=(int)(Math.random()*5 1);
while(grid[cols][rows]!=0) {
cols=(int)(Math.random()*6 1);
rows=(int)(Math.random()*5 1);
}
this.grid[cols][rows]=save[n];
n--;
}
mainFrame.setVisible(false);
pressInformation=false; //这里一定要将按钮点击信息归为初始
init();
for(int i = 0;i6;i){
for(int j = 0;j5;j){
if(grid[i 1][j 1]==0)
diamondsButton[i][j].setVisible(false);
}
}
}
public void estimateEven(int placeX,int placeY,JButton bz) {
if(pressInformation==false) {
x=placeX;
y=placeY;
secondMsg=grid[x][y];
secondButton=bz;
pressInformation=true;
}
else {
x0=x;
y0=y;
fristMsg=secondMsg;
firstButton=secondButton;
x=placeX;
y=placeY;
secondMsg=grid[x][y];
secondButton=bz;
if(fristMsg==secondMsgsecondButton!=firstButton){
xiao();
}
}
}
public void xiao() { //相同的情况下能不能消去 。仔细分析挖金矿游戏java源代码 , 不一条条注释
if((x0==x (y0==y 1||y0==y-1)) || ((x0==x 1||x0==x-1)(y0==y))){ //判断是否相邻
remove();
}
else{
for (j=0;j7;j) {
if (grid[x0][j]==0){ //判断第一个按钮同行哪个按钮为空
if (yj) { //如果第二个按钮的Y坐标大于空按钮的Y坐标说明第一按钮在第二按钮左边
for (i=y-1;i=j;i-- ){ //判断第二按钮左侧直到第一按钮中间有没有按钮
if (grid[x][i]!=0) {
k=0;
break;
}
else{ k=1; } //K=1说明通过了第一次验证
}
if (k==1) {
linePassOne();
}
}
if (yj){ //如果第二个按钮的Y坐标小于空按钮的Y坐标说明第一按钮在第二按钮右边
for (i=y 1;i=j ;i){ //判断第二按钮左侧直到第一按钮中间有没有按钮
if (grid[x][i]!=0){
k=0;
break;
}
else { k=1; }
}
if (k==1){
linePassOne();
}
}
if (y==j ) {
linePassOne();
}
}
if (k==2) {
if (x0==x) {
remove();
}
if (x0x) {
for (n=x0;n=x-1;n) {
if (grid[n][j]!=0) {
k=0;
break;
}
if(grid[n][j]==0n==x-1) {
remove();
}
}
}
if (x0x) {
for (n=x0;n=x 1 ;n-- ) {
if (grid[n][j]!=0) {
k=0;
break;
}
if(grid[n][j]==0n==x 1) {
remove();
}
}
}
}
}
for (i=0;i8;i) { //列
if (grid[i][y0]==0) {
if (xi) {
for (j=x-1;j=i ;j-- ) {
if (grid[j][y]!=0) {
k=0;
break;
}
else { k=1; }
}
if (k==1) {
rowPassOne();
}
}
if (xi) {
for (j=x 1;j=i;j) {
if (grid[j][y]!=0) {
k=0;
break;
}
else { k=1; }
}
if (k==1) {
rowPassOne();
}
}
if (x==i) {
rowPassOne();
}
}
if (k==2){
if (y0==y) {
remove();
}
if (y0y) {
for (n=y0;n=y-1 ;n) {
if (grid[i][n]!=0) {
k=0;
break;
}
if(grid[i][n]==0n==y-1) {
remove();
}
}
}
if (y0y) {
for (n=y0;n=y 1 ;n--) {
if (grid[i][n]!=0) {
k=0;
break;
}
if(grid[i][n]==0n==y 1) {
remove();
}
}
}
}
}
}
}
public void linePassOne(){
if (y0j){ //第一按钮同行空按钮在左边
for (i=y0-1;i=j ;i-- ){ //判断第一按钮同左侧空按钮之间有没按钮
if (grid[x0][i]!=0) {
k=0;
break;
}
else { k=2; } //K=2说明通过了第二次验证
}
}
if (y0j){ //第一按钮同行空按钮在与第二按钮之间
for (i=y0 1;i=j ;i){
if (grid[x0][i]!=0) {
k=0;
break;
}
else{ k=2; }
}
}
}
public void rowPassOne(){
if (x0i) {
for (j=x0-1;j=i ;j-- ) {
if (grid[j][y0]!=0) {
k=0;
break;
}
else { k=2; }
}
}
if (x0i) {
for (j=x0 1;j=i ;j) {
if (grid[j][y0]!=0) {
k=0;
break;
}
else { k=2; }
}
}
}
public void remove(){
firstButton.setVisible(false);
secondButton.setVisible(false);
fraction();
pressInformation=false;
k=0;
grid[x0][y0]=0;
grid[x][y]=0;
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==newlyButton){
int grid[][] = new int[8][7];
this.grid = grid;
randomBuild();
mainFrame.setVisible(false);
pressInformation=false;
init();
}
if(e.getSource()==exitButton)
System.exit(0);
if(e.getSource()==resetButton)
reload();
for(int cols = 0;cols6;cols){
for(int rows = 0;rows5;rows){
if(e.getSource()==diamondsButton[cols][rows])
estimateEven(cols 1,rows 1,diamondsButton[cols][rows]);
}
}
}
public static void main(String[] args) {
lianliankan llk = new lianliankan();
llk.randomBuild();
llk.init();
}
}
//old 998 lines
//new 318 lines
【挖金矿游戏java源代码 挖金矿小游戏在线玩手机版】关于挖金矿游戏java源代码和挖金矿小游戏在线玩手机版的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读