当前位置: &
资源说明:一些J***A小游戏的实现!
对J***A基础学习很有帮助。-
部分文件列表(点击文件名可查看文件内容)
最新本分类资源
一些J***A小游戏的实现!
对J***A基础学习很有帮助。-
连连看游戏的模拟,基本功能基本实现!好好玩啊!提高反应力!-Lianliankan game simulati ...
关于SWARM下的有关JHEATBUGs的源程序。可以非常清晰的看到仿真效果,一般用ECLIPSE编 ...
J***A实现经典停等协议的多线程方法,这个简单的但是经典的方法是多线程编程的入门材料- ...
这是本人做的一个纯J***A游戏小程序--弹球-
J2ME Jsr184 3D游戏开发碰撞的一个程序,可以用于很多游戏中-
这是一个打字的程序,给刚学打字的人计时.-
J***A的机器人比赛游戏,锻炼J***A编程能力的小程序。-
一个同学录系统,很不错的吧,适合初学者。相信对大家有帮助 ...
本类热门下载
一些J***A小游戏的实现!
对J***A基础学习很有帮助。-
一个同学录系统,很不错的吧,适合初学者。相信对大家有帮助 ...
netbean下开发的,头顶足球的游戏代码,可以模拟真实世界了,有重力等系统- ...
J***A的机器人比赛游戏,锻炼J***A编程能力的小程序。-
这是本人做的一个纯J***A游戏小程序--弹球-
连连看游戏的模拟,基本功能基本实现!好好玩啊!提高反应力!-Lianliankan game simulati ...
goldminer游戏,还不完善,只能在全屏模式下运行-
几个java编的实例小游戏,希望大家喜欢,多多指教。-
格斗类小游戏
没什么好说的了
真的真的-
可以在Linux文本界面下运行的华容道游戏(C+ ncurses库)。-
CopyRight & 2008- All Rights reserved. 苏ICP备
号 京公网安备:95java小游戏程序代码,65103小游戏大全 -
相关搜索:
3199推荐:
相关游戏 18 个
显示方式:
3199小游戏为您搜索匹配了一些“java小游戏程序代码”的小游戏,谢谢大家支持3199小游戏。
一只非常可爱的蓝色小怪baby,赶紧来喂养它,看看它会长成什么动物吧。类别:介绍:采用奥特曼小怪兽素材精心打造的一款好玩的连连看,里面包含***袖珍版小怪兽图集。本游戏有多种背景,音乐供玩家喜爱切换,游戏共30关,难度做了较好的调整,简单轻松快乐!大家快来体验下吧!类别:&&&你是一个小球,根据提示想尽办法使用小球通关,在游戏中你会遇到一些难题,不要着急,你一定会想出办法。操作方法:键盘方向键控制移动。类别:&&麻球游戏 这是世界上最难的游戏之一,你爱挑战吗?那么就解决它吧!操作方法:鼠标点击进行操作。类别:&&介绍:消灭小毛球加强选关版上线了,关卡全开。又是一款带来全新关卡的加强版游戏,游戏中紫色小毛球满世界捣乱,而玩家要利用物理的方法,杀死小毛球,可以利用气球让它们升到空中,气球破灭后摔下来掉落到钉板上,消灭它们,不管用什么方法千万可别让它们逃跑了。
史上最难游戏,十分具有挑战性,你不仅需要吃到所有物品,而且还要注意躲避高速移动的小球,小伙伴们来试试你能通过几关吧。
类别:&&&超级玛丽是许多小朋友的偶像,这不,小方块人也是马里奥的超级粉丝。它也要模仿马里奥,在经典的水管场景中来一场大冒险。操作方法:键盘方向键控制移动,Z跳跃,S加速。游戏提示:游戏画面较小,需点击缩小按钮才能正常显示。类别:&&&&蒂姆的冒险之路上出现了不少的游戏模式,有***,有打砖块,有弹球,有吃豆豆各种模式让你感受丰富的挑战之旅,同学们快来挑战吧。类别:介绍:小方块在小的时候有个梦想,那就是环游这个世界。可是当他从家里走出来的时候却发现世界并不像他想象的那么美好,反而到处充满了尔虞我诈的状况。为此小方块伤心透了,他想要回到家以后就在也不出来了。可是当他返回的时候却发现回家的道路也是障碍重重,我们快去帮他安全的回到家中吧!!类别:&狂热迷你小汽车,一款好玩的汽车类游戏。游戏中,我们驾驶着迷你小汽车,在一个微观的世界里极速行驶,小心驾驶,安全第一,不断闯关,解锁更多好玩的关卡和汽车,喜欢这款游戏的小伙伴们,快来一起玩吧!类别:&&&&&日本军队发动了侵略战争!拿起武器看谁消灭的鬼子最多!注意不断购买新的***械和军装。操作方法:WASD键控制移动,点击左键射击,空格键购买装备。类别:&&介绍:元芳此游戏你有何见解?回禀大人:这是一款非常可爱的小怪泡泡龙类型游戏,你要使用弹弓里面的小怪来消灭其他小怪。这么可爱的小怪有点舍不得消掉,可是时间紧迫,小怪会越来越多哦!
类别:小黑球球想要收集很多的宝物,但是好危险,一不小心就会被踩到~操作方法:方向键←→左右移动,方向键+空格键可以飞快冲向前趴在地上。类别:&
他们的梦想是当一名快乐的小海军,我们先为他们挑选一套漂亮的海军服吧。
类别:&&&&
这是一场糖果之间的战争,红黑糖果爆发了领地争夺战,黑色的邪恶糖果侵入了红色糖果的快乐国度,还企图想吞并红色糖果,红色糖果由于人手不够,不能反击,只能利......&&类别:&&&&
女孩今天和小伙伴们去游戏厅,本来挺高兴的一件事情,但是女孩对这里面的游戏一点都不感兴趣。她喜欢玩别的有意思的,但是她不能光明正大玩哦~因为这样会扫朋友们的兴致的。
类别:&&&&&你将在美丽的沙滩边上开一家售卖热狗的小摊,快来满足所有顾客的需求吧!操作方法:游戏中使用鼠标操作,点击鼠标左键来满足顾客的需求。类别:&&小新斗恶龙,帮帮他吧,很简单!类别:
网站为您提供在线小游戏、双人小游戏、小游戏大全等深受广大网友喜爱的小游戏
作品版权归作者所有 &合作:、、Java 俄罗斯方块,作者:江怡顺,操作提示:上键是变换物块。学习Java的好范例,一些小游戏通常可学习到很多的Java技巧,比如java.awt、javax.swing等。
用到了一个小图片,&下载后请命名为:Block.jpg,放在resource文件夹内:下面是具体的俄罗斯方块游戏代码:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
import java.lang.String.*;
import java.lang.*;
import java.io.*;
public class Block extends JPanel implements ActionListener,KeyListener//应该是继承JPanel
static Button but[] = new Button[6];
static Button noStop = new Button(&取 消 暂 停&);
static Label scoreLab = new Label(&分数:&);
static Label infoLab = new Label(&提示:&);
static Label speedLab = new Label(&级数:&);
static Label scoreTex = new Label(&0&);
static Label infoTex = new Label(& &);
static Label speedTex = new Label(&1&);
static JFrame jf = new JFrame();
static MyT
static ImageIcon icon=new ImageIcon(&resource/Block.jpg&);
static JMenuBar mb = new JMenuBar();
static JMenu menu0 = new JMenu(&游
static JMenu menu1 = new JMenu(&帮
static JMenuItem mi0 = new JMenuItem(&新 游 戏&);
static JMenuItem mi1 = new JMenuItem(&退
static JMenuItem mi1_0 = new JMenuItem(&关
static JDialog dlg_1;
static JTextArea dlg_1_text = new JTextArea();
static int startSign = 0;//游戏开始标志 0 未开始 1 开始 2 暂停
static String butLab[] = {&开 始 游 戏&,&重 新 开 始&,&降 低 级 数&,&提 高 级 数&,&游 戏 暂 停&,&退 出 游 戏&};
static int game_body[][] = new int[19][10];
static int game_sign_x[] = new int[4];//用于记录4个方格的水平位置
static int game_sign_y[] = new int[4];//用于记录4个方格的垂直位置
static boolean downSign =//是否落下
static int blockNumber = 1;//砖块的编号
static int gameScore = 0;//游戏分数
static int speedMark = 1;
public static void main(String args[])
Block myBlock = new Block();
mb.add(menu0);
mb.add(menu1);
menu0.add(mi0);
menu0.add(mi1);
menu1.add(mi1_0);
jf.setJMenuBar(mb);
myBlock.init();
jf.add(myBlock);
jf.setSize(565,501);
jf.setResizable(false);
jf.setTitle(&俄罗斯方块&);
jf.setIconImage(icon.getImage());
jf.setLocation(200,100);
jf.show();
timer = new MyTimer(myBlock); //启动线程
timer.setDaemon(true);
timer.start();
timer.suspend();
public void init()
setLayout(null);
for(int i = 0;i & 6;i++)
but[i] = new Button(butLab[i]);
add(but[i]);
but[i].addActionListener(this);
but[i].addKeyListener(this);
but[i].setBounds(360,(240 + 30 * i),160,25);
add(scoreLab);
add(scoreTex);
add(speedLab);
add(speedTex);
add(infoLab);
add(infoTex);
add(scoreLab);
scoreLab.setBounds(320,15,30,20);
scoreTex.setBounds(360,15,160,20);
scoreTex.setBackground(Color.white);
speedLab.setBounds(320,45,30,20);
speedTex.setBounds(360,45,160,20);
speedTex.setBackground(Color.white);
but[1].setEnabled(false);
but[4].setEnabled(false);
infoLab.setBounds(320,75,30,20);
infoTex.setBounds(360,75,160,20);
infoTex.setBackground(Color.white);
noStop.setBounds(360,360,160,25);
noStop.addActionListener(this);
noStop.addKeyListener(this);
mi0.addActionListener(this);
mi1.addActionListener(this);
mi1_0.addActionListener(this);
num_csh_game();
rand_block();
public void actionPerformed(ActionEvent e)
if(e.getSource() == but[0])//开始游戏
startSign = 1;
infoTex.setText(&游戏已经开始!&);
but[0].setEnabled(false);
but[1].setEnabled(true);
but[4].setEnabled(true);
timer.resume();
if(e.getSource() == but[1]||e.getSource() == mi0)//重新开始游戏
startSign = 0;
gameScore = 0;
timer.suspend();
num_csh_restart();
repaint();
rand_block();
scoreTex.setText(&0&);
infoTex.setText(&新游戏!&);
but[0].setEnabled(true);
but[1].setEnabled(false);
but[4].setEnabled(false);
if(e.getSource() == but[2])//降低级数
infoTex.setText(&降低级数!&);
speedMark--;
if(speedMark &= 1)
speedMark = 1;
infoTex.setText(&已经是最低级数!&);
speedTex.setText(speedMark + &&);
if(e.getSource() == but[3])//提高级数
infoTex.setText(&提高级数!&);
speedMark++;
if(speedMark &= 9)
speedMark = 9;
infoTex.setText(&已经是最高级数!&);
speedTex.setText(speedMark + &&);
if(e.getSource() == but[4])//游戏暂停
this.add(noStop);
this.remove(but[4]);
infoTex.setText(&游戏暂停!&);
timer.suspend();
if(e.getSource() == noStop)//取消暂停
this.remove(noStop);
this.add(but[4]);
infoTex.setText(&继续游戏!&);
timer.resume();
if(e.getSource() == but[5]||e.getSource() == mi1)//退出游戏
jf.dispose();
if(e.getSource() == mi1_0)//退出游戏
dlg_1 = new JDialog(jf,&关 于&);
FileInputStream io = new FileInputStream(&resource/guanyu.txt&);//得到路径
byte a[] = new byte[io.available()];
io.read(a);
io.close();
String str = new String(a);
dlg_1_text.setText(str);
catch(Exception g){}
dlg_1_text.setEditable(false);
dlg_1.add(dlg_1_text);
dlg_1.pack();
dlg_1.setResizable(false);
dlg_1.setSize(200, 120);
dlg_1.setLocation(400, 240);
dlg_1.show();
public void rand_block()//随机产生砖块
num = (int)(Math.random() * 6) + 1;//产生0~6之间的随机数
blockNumber =
switch(blockNumber)
case 1: block1(); blockNumber = 1;
case 2: block2(); blockNumber = 2;
case 3: block3(); blockNumber = 3;
case 4: block4(); blockNumber = 4;
case 5: block5(); blockNumber = 5;
case 6: block6(); blockNumber = 6;
case 7: block7(); blockNumber = 7;
public void change_body(int blockNumber)//改变砖块状态
dingwei();
if(blockNumber == 1&&downSign == false)//变换长条2种情况
if(game_sign_y[0] == game_sign_y[1]&&game_sign_y[3] &= 16)//说明长条是横着的
if(game_body[game_sign_y[0] - 1][game_sign_x[0] + 1] != 2&&game_body[game_sign_y[3] + 2][game_sign_x[3] - 2] != 2)
num_csh_game();
game_body[game_sign_y[0] - 1][game_sign_x[0] + 1] = 1;
game_body[game_sign_y[1]][game_sign_x[1]] = 1;
game_body[game_sign_y[2] + 1][game_sign_x[2] - 1] = 1;
game_body[game_sign_y[3] + 2][game_sign_x[3] - 2] = 1;
infoTex.setText(&游戏进行中!&);
repaint();
if(game_sign_x[0] == game_sign_x[1]&&game_sign_x[0] &= 1&&game_sign_x[3] &= 7)//说明长条是竖着的
if(game_body[game_sign_y[0] + 1][game_sign_x[0]-1] != 2&&game_body[game_sign_y[3] - 2][game_sign_x[3] + 2] != 2)
num_csh_game();
game_body[game_sign_y[0] + 1][game_sign_x[0] - 1] = 1;
game_body[game_sign_y[1]][game_sign_x[1]]=1;
game_body[game_sign_y[2] - 1][game_sign_x[2] + 1] = 1;
game_body[game_sign_y[3] - 2][game_sign_x[3] + 2] = 1;
infoTex.setText(&游戏进行中!&);
repaint();
if(blockNumber == 3&&downSign == false)//变换转弯1有4种情况
if(game_sign_x[0] == game_sign_x[1]&&game_sign_x[0] == game_sign_x[2]&&game_sign_y[2] == game_sign_y[3]&&game_sign_x[0] &= 1)
if(game_body[game_sign_y[0] + 1][game_sign_x[0] - 1] != 2&&game_body[game_sign_y[2] - 1][game_sign_x[2] + 1] != 2&&game_body[game_sign_y[3] - 2][game_sign_x[3]] != 2)
num_csh_game();
game_body[game_sign_y[0] + 1][game_sign_x[0] - 1] = 1;
game_body[game_sign_y[1]][game_sign_x[1]] = 1;
game_body[game_sign_y[2] - 1][game_sign_x[2] + 1] = 1;
game_body[game_sign_y[3] - 2][game_sign_x[3]] = 1;
infoTex.setText(&游戏进行中!&);
repaint();
if(game_sign_y[1] == game_sign_y[2]&&game_sign_y[2] == game_sign_y[3]&&game_sign_x[0] == game_sign_x[3]&&game_sign_y[1] &= 17)
if(game_body[game_sign_y[0]][game_sign_x[0] - 2] != 2&&game_body[game_sign_y[1] + 1][game_sign_x[1] + 1] != 2&&game_body[game_sign_y[3] - 1][game_sign_x[3] - 1] != 2)
num_csh_game();
game_body[game_sign_y[0]][game_sign_x[0] - 2] = 1;
game_body[game_sign_y[1] + 1][game_sign_x[1] + 1] = 1;
game_body[game_sign_y[2]][game_sign_x[2]] = 1;
game_body[game_sign_y[3] - 1][game_sign_x[3] - 1] = 1;
infoTex.setText(&游戏进行中!&);
repaint();
if(game_sign_x[1] == game_sign_x[2]&&game_sign_x[1] == game_sign_x[3]&&game_sign_y[0] == game_sign_y[1]&&game_sign_x[3] &= 8)
if(game_body[game_sign_y[0] + 2][game_sign_x[0]] != 2&&game_body[game_sign_y[1] + 1][game_sign_x[1] - 1] != 2&&game_body[game_sign_y[3] - 1][game_sign_x[3] + 1] != 2)
num_csh_game();
game_body[game_sign_y[0] + 2][game_sign_x[0]] = 1;
game_body[game_sign_y[1] + 1][game_sign_x[1] - 1] = 1;
game_body[game_sign_y[2]][game_sign_x[2]] = 1;
game_body[game_sign_y[3] - 1][game_sign_x[3] + 1] = 1;
infoTex.setText(&游戏进行中!&);
repaint();
if(game_sign_y[0] == game_sign_y[1]&&game_sign_y[1] == game_sign_y[2]&&game_sign_x[0] == game_sign_x[3])
if(game_body[game_sign_y[0] + 1][game_sign_x[0] + 1] != 2&&game_body[game_sign_y[2] - 1][game_sign_x[2] - 1] != 2&&game_body[game_sign_y[3]][game_sign_x[3] + 2] != 2)
num_csh_game();
game_body[game_sign_y[0] + 1][game_sign_x[0] + 1] = 1;
game_body[game_sign_y[1]][game_sign_x[1]] = 1;
game_body[game_sign_y[2] - 1][game_sign_x[2] - 1] = 1;
game_body[game_sign_y[3]][game_sign_x[3] + 2] = 1;
infoTex.setText(&游戏进行中!&);
repaint();
if(blockNumber == 4&&downSign == false)//变换转弯2有4种情况
if(game_sign_x[0] == game_sign_x[1]&&game_sign_x[0] == game_sign_x[3]&&game_sign_y[1] == game_sign_y[2]&&game_sign_x[3] &= 7)
if(game_body[game_sign_y[0] + 2][game_sign_x[0]] != 2&&game_body[game_sign_y[1] + 1][game_sign_x[1] + 1] != 2&&game_body[game_sign_y[3]][game_sign_x[3] + 2] != 2)
num_csh_game();
game_body[game_sign_y[0] + 2][game_sign_x[0]] = 1;
game_body[game_sign_y[1] + 1][game_sign_x[1] + 1] = 1;
game_body[game_sign_y[2]][game_sign_x[2]] = 1;
game_body[game_sign_y[3]][game_sign_x[3] + 2] = 1;
infoTex.setText(&游戏进行中!&);
repaint();
if(game_sign_y[1] == game_sign_y[2]&&game_sign_y[1] == game_sign_y[3]&&game_sign_x[0] == game_sign_x[2])
if(game_body[game_sign_y[1]][game_sign_x[1] + 2] != 2&&game_body[game_sign_y[2] - 1][game_sign_x[2] + 1] != 2&&game_body[game_sign_y[3] - 2][game_sign_x[3]] != 2)
num_csh_game();
game_body[game_sign_y[0]][game_sign_x[0]] = 1;
game_body[game_sign_y[1]][game_sign_x[1] + 2] = 1;
game_body[game_sign_y[2] - 1][game_sign_x[2] + 1] = 1;
game_body[game_sign_y[3] - 2][game_sign_x[3]] = 1;
infoTex.setText(&游戏进行中!&);
repaint();
if(game_sign_x[0] == game_sign_x[2]&&game_sign_x[0] == game_sign_x[3]&&game_sign_y[1] == game_sign_y[2]&&game_sign_x[0] &= 2)
if(game_body[game_sign_y[0]][game_sign_x[0] - 2] != 2&&game_body[game_sign_y[2] - 1][game_sign_x[2] - 1] != 2&&game_body[game_sign_y[3] - 2][game_sign_x[3]] != 2)
num_csh_game();
game_body[game_sign_y[0]][game_sign_x[0] - 2] = 1;
game_body[game_sign_y[1]][game_sign_x[1]] = 1;
game_body[game_sign_y[2] - 1][game_sign_x[2] - 1] = 1;
game_body[game_sign_y[3] - 2][game_sign_x[3]] = 1;
infoTex.setText(&游戏进行中!&);
repaint();
if(game_sign_y[0] == game_sign_y[1]&&game_sign_y[0] == game_sign_y[2]&&game_sign_x[1] == game_sign_x[3]&&game_sign_y[0] &= 16)
if(game_body[game_sign_y[0] + 2][game_sign_x[0]] != 2&&game_body[game_sign_y[1] + 1][game_sign_x[1] - 1] != 2&&game_body[game_sign_y[2]][game_sign_x[2] - 2] != 2)
num_csh_game();
game_body[game_sign_y[0] + 2][game_sign_x[0]] = 1;
game_body[game_sign_y[1] + 1][game_sign_x[1] - 1] = 1;
game_body[game_sign_y[2]][game_sign_x[2] - 2] = 1;
game_body[game_sign_y[3]][game_sign_x[3]] = 1;
infoTex.setText(&游戏进行中!&);
repaint();
if(blockNumber == 5&&downSign == false)//变换转弯3有4种情况
if(game_sign_x[0] == game_sign_x[2]&&game_sign_x[2] == game_sign_x[3]&&game_sign_y[0] == game_sign_y[1]&&game_sign_x[1] &= 2)
if(game_body[game_sign_y[0] + 1][game_sign_x[0] - 1] != 2&&game_body[game_sign_y[1]][game_sign_x[1] - 2] != 2&&game_body[game_sign_y[3] - 1][game_sign_x[3] + 1] != 2)
num_csh_game();
game_body[game_sign_y[0] + 1][game_sign_x[0] - 1] = 1;
game_body[game_sign_y[1]][game_sign_x[1] - 2] = 1;
game_body[game_sign_y[2]][game_sign_x[2]] = 1;
game_body[game_sign_y[3] - 1][game_sign_x[3] + 1] = 1;
infoTex.setText(&游戏进行中!&);
repaint();
if(game_sign_y[1] == game_sign_y[2]&&game_sign_y[2] == game_sign_y[3]&&game_sign_x[0] == game_sign_x[1]&&game_sign_y[0] &= 16)
if(game_body[game_sign_y[0] + 2][game_sign_x[0]] != 2&&game_body[game_sign_y[1] + 1][game_sign_x[1] + 1] != 2&&game_body[game_sign_y[3] - 1][game_sign_x[3] - 1] != 2)
num_csh_game();
game_body[game_sign_y[0] + 2][game_sign_x[0]] = 1;
game_body[game_sign_y[1] + 1][game_sign_x[1] + 1] = 1;
game_body[game_sign_y[2]][game_sign_x[2]] = 1;
game_body[game_sign_y[3] - 1][game_sign_x[3] - 1] = 1;
infoTex.setText(&游戏进行中!&);
repaint();
if(game_sign_x[0] == game_sign_x[1]&&game_sign_x[1] == game_sign_x[3]&&game_sign_y[2] == game_sign_y[3])
if(game_body[game_sign_y[0] + 1][game_sign_x[0] - 1] != 2&&game_body[game_sign_y[2]][game_sign_x[2] + 2] != 2&&game_body[game_sign_y[3] - 1][game_sign_x[3] + 1] != 2)
num_csh_game();
game_body[game_sign_y[0] + 1][game_sign_x[0] - 1] = 1;
game_body[game_sign_y[1]][game_sign_x[1]] = 1;
game_body[game_sign_y[2]][game_sign_x[2] + 2] = 1;
game_body[game_sign_y[3] - 1][game_sign_x[3] + 1] = 1;
infoTex.setText(&游戏进行中!&);
repaint();
if(game_sign_y[0] == game_sign_y[1]&&game_sign_y[1] == game_sign_y[2]&&game_sign_x[2] == game_sign_x[3])
if(game_body[game_sign_y[0] + 1][game_sign_x[0] + 1] != 2&&game_body[game_sign_y[2] - 1][game_sign_x[2] - 1] != 2&&game_body[game_sign_y[3] - 2][game_sign_x[3]] != 2)
num_csh_game();
game_body[game_sign_y[0] + 1][game_sign_x[0] + 1] = 1;
game_body[game_sign_y[1]][game_sign_x[1]] = 1;
game_body[game_sign_y[2] - 1][game_sign_x[2] - 1] = 1;
game_body[game_sign_y[3] - 2][game_sign_x[3]] = 1;
infoTex.setText(&游戏进行中!&);
repaint();
if(blockNumber == 6&&downSign == false)//变换两层砖块1的2种情况
if(game_sign_x[0] == game_sign_x[2]&&game_sign_x[0] &= 2)
if(game_body[game_sign_y[0]][game_sign_x[0] - 2] != 2&&game_body[game_sign_y[2] - 1][game_sign_x[2] -1 ] != 2&&game_body[game_sign_y[3] - 1][game_sign_x[3] + 1] != 2)
num_csh_game();
game_body[game_sign_y[0]][game_sign_x[0] - 2] = 1;
game_body[game_sign_y[1]][game_sign_x[1]] = 1;
game_body[game_sign_y[2] - 1][game_sign_x[2] - 1] = 1;
game_body[game_sign_y[3] - 1][game_sign_x[3] + 1] = 1;
infoTex.setText(&游戏进行中!&);
repaint();
if(game_sign_y[0] == game_sign_y[1]&&game_sign_y[3] &= 17)
if(game_body[game_sign_y[0]][game_sign_x[0] + 2] != 2&&game_body[game_sign_y[1] + 1][game_sign_x[1] + 1] != 2&&game_body[game_sign_y[3] + 1][game_sign_x[3] - 1] != 2)
num_csh_game();
game_body[game_sign_y[0]][game_sign_x[0] + 2] = 1;
game_body[game_sign_y[1] + 1][game_sign_x[1] + 1] = 1;
game_body[game_sign_y[2]][game_sign_x[2]] = 1;
game_body[game_sign_y[3] + 1][game_sign_x[3] - 1] = 1;
infoTex.setText(&游戏进行中!&);
repaint();
if(blockNumber == 7&&downSign == false)//变换两层砖块2的2种情况
if(game_sign_x[0] == game_sign_x[1]&&game_sign_x[0] &= 16)
if(game_body[game_sign_y[0]][game_sign_x[0] + 2] != 2&&game_body[game_sign_y[1] - 1][game_sign_x[1] + 1] != 2&&game_body[game_sign_y[3] - 1][game_sign_x[3] - 1] != 2)
num_csh_game();
game_body[game_sign_y[0]][game_sign_x[0] + 2] = 1;
game_body[game_sign_y[1] - 1][game_sign_x[1] + 1] = 1;
game_body[game_sign_y[2]][game_sign_x[2]] = 1;
game_body[game_sign_y[3] - 1][game_sign_x[3] - 1] = 1;
infoTex.setText(&游戏进行中!&);
repaint();
if(game_sign_y[0] == game_sign_y[1]&&game_sign_y[2] &= 17)
if(game_body[game_sign_y[0] + 1][game_sign_x[0] - 1] != 2&&game_body[game_sign_y[1]][game_sign_x[1] - 2] != 2&&game_body[game_sign_y[2] + 1][game_sign_x[2] + 1] != 2)
num_csh_game();
game_body[game_sign_y[0] + 1][game_sign_x[0] - 1] = 1;
game_body[game_sign_y[1]][game_sign_x[1] - 2] = 1;
game_body[game_sign_y[2] + 1][game_sign_x[2] + 1] = 1;
game_body[game_sign_y[3]][game_sign_x[3]] = 1;
infoTex.setText(&游戏进行中!&);
repaint();
public void num_csh_game()//数组清零
for(int i = 0;i & 19;i++)
for(int j = 0;j & 10;j++)
if(game_body[i][j] == 2)
game_body[i][j] = 2;
game_body[i][j] = 0;
public void num_csh_restart()//重新开始时数组清零
for(int i = 0;i & 19;i++)
for(int j = 0;j & 10;j++)
game_body[i][j] = 0;
public void keyTyped(KeyEvent e){}
public void keyPressed(KeyEvent e)
if(e.getKeyCode() == KeyEvent.VK_DOWN&&startSign == 1)//处理下键
this.down();
if(e.getKeyCode() == KeyEvent.VK_LEFT&&startSign == 1)//处理左键
this.left();
if(e.getKeyCode() == KeyEvent.VK_RIGHT&&startSign == 1)//处理右键
this.right();
if(e.getKeyCode() == KeyEvent.VK_UP&&startSign == 1)//处理上键转换
this.change_body(blockNumber);
if(startSign == 0)
infoTex.setText(&游戏未开始或已结束!&);
public void keyReleased(KeyEvent e){}
public void paint(Graphics g)
g.setColor(Color.black);
g.fill3DRect(0,0,300,450,true);
for(int i = 0;i & 19;i++)
for(int j = 0;j & 10;j++)
if(game_body[i][j] == 1)
g.setColor(Color.blue);
g.fill3DRect(30*j,30*(i-4),30,30,true);
if(game_body[i][j] == 2)
g.setColor(Color.magenta);
g.fill3DRect(30*j,30*(i-4),30,30,true);
public void left()//向左移动
int sign = 0;
dingwei();
for(int k = 0;k & 4;k++)
if(game_sign_x[k] == 0||game_body[game_sign_y[k]][game_sign_x[k] - 1] == 2)
if(sign == 0&&downSign == false)
num_csh_game();
for(int k = 0;k & 4;k++)
game_body[game_sign_y[k]][game_sign_x[k] - 1] = 1;
infoTex.setText(&向左移动!&);
repaint();
public void right()//向右移动
int sign = 0;
dingwei();
for(int k = 0;k & 4;k++)
if(game_sign_x[k] == 9||game_body[game_sign_y[k]][game_sign_x[k] + 1] == 2)
if(sign == 0&&downSign == false)
num_csh_game();
for(int k = 0;k & 4;k++)
game_body[game_sign_y[k]][game_sign_x[k] + 1] = 1;
infoTex.setText(&向右移动!&);
repaint();
public void down()//下落
int sign = 0;
dingwei();
for(int k = 0;k & 4;k++)
if(game_sign_y[k] == 18||game_body[game_sign_y[k] + 1][game_sign_x[k]] == 2)
downSign =
changeColor();
cancelDW();
getScore();
if(game_over() == false)
rand_block();
repaint();
if(sign == 0)
num_csh_game();
for(int k = 0;k & 4;k++)
game_body[game_sign_y[k] + 1][game_sign_x[k]] = 1;
infoTex.setText(&游戏进行中!&);
repaint();
public boolean game_over()//判断游戏是否结束
int sign=0;
for(int i = 0;i & 10;i++)
if(game_body[4][i] == 2)
if(sign == 1)
infoTex.setText(&游戏结束!&);
changeColor();
repaint();
startSign = 0;
timer.suspend();
public void getScore()//满行消除方法
for(int i = 0;i & 19;i++)
int sign = 0;
for(int j = 0;j & 10;j++)
if(game_body[i][j] == 2)
if(sign == 10)
gameScore += 100;
scoreTex.setText(gameScore+&&);
infoTex.setText(&恭喜得分!&);
for(int j =j &= 1;j--)
for(int k = 0;k & 10;k++)
game_body[j][k] = game_body[j - 1][k];
public void changeColor()//给已经落下的块换色
downSign =
for(int k = 0;k & 4;k++)
game_body[game_sign_y[k]][game_sign_x[k]] = 2;
public void dingwei()//确定其位置
int k = 0;
cancelDW();
for(int i = 0;i & 19;i++)
for(int j = 0;j & 10;j++)
if(game_body[i][j] == 1)
game_sign_x[k] =
game_sign_y[k] =
public void cancelDW()//将定位数组初始化
for(int k = 0;k & 4;k++)
game_sign_x[k] = 0;
game_sign_y[k] = 0;
public void block1()//长条
game_body[0][4] = 1;
game_body[1][4] = 1;
game_body[2][4] = 1;
game_body[3][4] = 1;
public void block2()//正方形
game_body[3][4] = 1;
game_body[2][4] = 1;
game_body[3][5] = 1;
game_body[2][5] = 1;
public void block3()//3加1(下)
game_body[1][4] = 1;
game_body[2][4] = 1;
game_body[3][4] = 1;
game_body[3][5] = 1;
public void block4()//3加1(中)
game_body[1][4] = 1;
game_body[2][4] = 1;
game_body[3][4] = 1;
game_body[2][5] = 1;
public void block5()//3加1(上)
game_body[1][4] = 1;
game_body[2][4] = 1;
game_body[3][4] = 1;
game_body[1][5] = 1;
public void block6()//转折1
game_body[1][5] = 1;
game_body[2][5] = 1;
game_body[2][4] = 1;
game_body[3][4] = 1;
public void block7()//转折2
game_body[1][4] = 1;
game_body[2][4] = 1;
game_body[2][5] = 1;
game_body[3][5] = 1;
//定时线程
class MyTimer extends Thread
public MyTimer(Block myBlock)
this.myBlock = myB
public void run()
while(myBlock.startSign == 1)
sleep((10-myBlock.speedMark + 1)*100);
myBlock.down();
catch(InterruptedException e){}
本类推荐文章
本类最新更新
最新源码下载