import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class oppGame extends Applet implements KeyListener,Runnable
{
Button but1=new Button("连接");
Button but2=new Button("暂停/继续");
panel panel1=new panel(20,10); //自己游戏操作界面
panel panel2=new panel(20,10); //对方游戏画面
panel panel3=new panel(4,4); //对方游戏画面
TextField text; //显示游戏时间
boolean tempx=false; //临时变量
boolean candown=false; //是否可以下降
boolean connect=false; //是否连接成功
boolean canscore=false; //是否可以计算得分
boolean cangain=false; //是否可以从下加行
boolean ifpause=false; //是否暂停游戏
boolean ifend=false; //游戏是否结束
boolean diFlag=false; //如果方块到达底部时被移动了,
//此方块还能下落,则不转移对象,diFlag=true;
boolean pp=true; //控制提示框
boolean aa=true;
Thread thread;
comGame comgame;
gameClientThread gameclientthread;
private int count=1; //累计
private int delay=100; //线程暂停时间
private int speed=0; //游戏速度
private int my_delete=0; //我消掉的行数
private int opp_delete=0; //对手消掉的行数
private long score=0; //我的得分
private int colorx; //颜色的临时变量
private char marksend='a'; //重复相同消行判断
private long markscore=0; //重复相同消行判断
private char markreceive='a';
Label message1;//显示当前游戏速度
Label message2;//显示当前得分
Label message3;//显示双方游戏信息
Label message4;//显示双方游戏信息,操作提示
Label message5=new Label("俄罗斯方块局域网对战版 v1.0 Beta DT小组倾力打造");
Image BufferImage; //创建用于消除闪烁的图像
Graphics BufferGraphics;
private int mm=0;//声音标志
private AudioClip sound1; //声音类
private AudioClip sound2;
private AudioClip sound3;
private AudioClip sound4;
public void init()
{
sound1=getAudioClip(getDocumentBase(),"声音文件/SOUND8.WAV"); //旋转,
sound2=getAudioClip(getDocumentBase(),"声音文件/SOUND8.WAV"); //左移与右移 声音
sound3=getAudioClip(getDocumentBase(),"声音文件/SOUND104.WAV"); //到达底部 声音
sound4=getAudioClip(getDocumentBase(),"声音文件/SOUND53.WAV"); //得分 声音
comgame=new comGame();
this.setLayout(null);
setSize(500,500);
message2=new Label();
this.add(message2);
message2.setBounds(255,180,100,20);
message3=new Label();
this.add(message3);
message3.setBounds(320,100,160,20);
message4=new Label();
this.add(message4);
message4.setBounds(320,120,160,20);
this.add(message5);
message5.setBounds(40,457,400,20);
text=new TextField("用时:");
this.add(text);
text.setBounds(250,15,100,20);
text.setBackground(Color.YELLOW);
add(but1);
but1.setBounds(55,15,40,20);
but1.setBackground(Color.GRAY);
but1.addKeyListener(this);
but1.requestFocus();
but1.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
if(connect==false)
{
gameclientthread=new gameClientThread();
gameclientthread.start();
initgame();
connect=true;
but1.setBackground(Color.green);
initgame();
}
}
}
);
add(but2);
but2.setBounds(255,250,65,40);
but2.setBackground(Color.yellow);
but2.addKeyListener(this);
but2.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
if(ifpause==true)
{
ifpause=false;
but2.setBackground(Color.yellow);
}
else
{
ifpause=true;
but2.setBackground(Color.gray);
}
if(ifend==true)
{
initgame();
ifend=false;
message3.setText(null);
message4.setText(null);
}
}
}
);
this.add(panel1);
panel1.setBounds(50,50,200,400);
this.add(panel2);
panel2.setBounds(350,250,100,200);
this.add(panel3);
panel3.setBounds(260,50,60,60);
BufferImage=createImage(getSize().width,getSize().height);
BufferGraphics=BufferImage.getGraphics();
}
public void paint(Graphics g)
{
BufferGraphics.setColor(Color.white);
BufferGraphics.fillRect(0,0,getSize().width,getSize().height);
text.setText("得分:"+score);
message2.setText("当前速度:"+speed);
if(my_delete>1)
{
message3.setText(my_delete+"连击!");
if(connect==true)
{
int n=my_delete-1;
message4.setText("吕布方块加"+n+"速度加"+my_delete);
}
}
if(opp_delete>1)
{
message3.setText("吕布"+opp_delete+"连击!");
int a=my_delete-1;
message4.setText("方块加"+a+"速度+"+opp_delete);
}
Font f=new Font("宋体",Font.PLAIN,34);
Font f2=new Font("宋体",Font.PLAIN,18);
BufferGraphics.setFont(f);
Color c=Color.PINK;
BufferGraphics.setColor(c);
BufferGraphics.drawRect(48,48,202,402);
if(connect==false)
{
BufferGraphics.drawString("吕布",110,40);
BufferGraphics.drawString("赵云",350,236);
BufferGraphics.setFont(f2);
BufferGraphics.setColor(Color.gray);
BufferGraphics.drawString("(离线)",420,236);
}
else
{
BufferGraphics.drawString("吕布",110,40);
BufferGraphics.drawString("赵云",350,236);
}
if(ifend==true)
{
message3.setText("游戏结束,得分:"+score);
message4.setText("按暂停键重新开始");
}
BufferGraphics.setFont(f2);
g.drawImage(BufferImage,0,0,this);
}
public void soundStart()
{
if(mm==1){ //旋转 播放
mm=0;
sound1.play();
}
else if(mm==2){ //左移与右移 播放
mm=0;
sound2.play();
}
else if(mm==3){//到达底部 播放
mm=0;
sound3.play();
}
else if(mm==4){ //得分 播放
mm=0;
sound4.play();
}
else{
mm=0;
}
}
public void initgame()
{
for(int i=0;i<24;i++)
{
for(int j=0;j<10;j++)
{
comgame.position[i][j]=false;
speed=0;
score=0;
}
}
}
public void initgame2()//显示提示框
{
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
comgame.position2[i][j]=false;
}
}
comgame.creat();
comgame.computePos2();
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
if(comgame.position2[i][j]==true)
{
panel3.showBox(i,j);
//System.out.println(comgame.position2[i][j]);
}
else
{
panel3.hideBox(i,j);
}
}
}
}
public void start(){
if(thread==null)
thread=new Thread(this);
thread.start();
}
public void stop(){
thread=null;
}
public void update(Graphics g)
{
paint(g);
}
public void run() //线程开始
{
while(thread!=null)
{
repaint();
try
{
Thread.sleep(delay);
}
catch(InterruptedException e){}
if(pp==true)
{
//System.out.println("aaaaaaaaaaaa");
initgame2();
pp=false;
}
if(candown==false&&ifpause==false&&count==1&&diFlag==false) //方块到底,产生新的方块
{
//comgame.creat();
comgame.computePos();
aa=true;
}
for(int i=0;i<20;i++) //显示图形矩阵
{
for(int j=0;j<10;j++)
{
if(comgame.position[i+4][j]==true)
{
cogame.x=comgame.color[i+4][j];
panel1.showBox(i,j);
}
else
{
panel1.hideBox(i,j);
}
}
}
if(aa==true&&count==5)
{
initgame2();
aa=false;
}
if(ifpause==false&&count==5)
candown=comgame.moveDown(); //下降一格
if(candown==false&&count==5) //方块到底 计算消行数 判断是否结束
{
mm=3; //播放到达底部的音乐
this.soundStart();
my_delete=comgame.delete();
if(my_delete>0)
{
canscore=true;
mm=4; //播放得分声音
this.soundStart();
没有合适的资源?快使用搜索试试~ 我知道了~
JAVA 俄罗斯方块局域网对战版java源码
共27个文件
class:12个
java:8个
wav:3个
4星 · 超过85%的资源 需积分: 10 31 下载量 144 浏览量
2010-11-16
15:42:29
上传
评论 1
收藏 43KB RAR 举报
温馨提示
这是一个 很小的游戏代码俄罗斯方块局域网对战版java源码
资源推荐
资源详情
资源评论
收起资源包目录
俄罗斯方块局域网对战版java源码.rar (27个子文件)
俄罗斯方块局域网对战版java源码
龙腾教程网 软件教程 电脑教程 设计教程.url 54B
俄罗斯方块
.project 391B
panel.class 1016B
Game.class 9KB
java.policy.applet 141B
Box.java 818B
Game.java 11KB
gameServerSocket.java 2KB
Box.class 1KB
gameClientThread.java 2KB
oppGame.java 11KB
Game$2.class 1KB
comGame.class 8KB
gameClientThread.class 2KB
panel.java 617B
oppGame$2.class 1KB
oppGame$1.class 970B
Game$1.class 952B
gameServerSocket.class 2KB
comGame.java 9KB
声音文件
SOUND53.WAV 9KB
SOUND8.WAV 2KB
SOUND104.WAV 1KB
cogame.java 58B
.classpath 226B
oppGame.class 9KB
cogame.class 259B
共 27 条
- 1
资源评论
- yda4924041312014-01-17代码写的不错,可以学习
- u0110640222013-06-18这个一般可以叫任务
- qq_366456142016-11-08全是乱码。。慎重
- lycongcong12142015-08-01可以用,挺好的资源~
asdfsooy
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功