📄 chuangti.java~5~
字号:
for (int i=0;i<to.length;i++)
{
if (to[i].InBounds()==false) return false ;
//如果不在可玩区域,则返回假
if(mine[to[i].m_nColumn][to[i].m_nRow]!=0)
{
for (int j=0;j<from.length;j++)
if (to[i].IsEqual(from[j]))
continue outerlable;
return false;
}
}
//移动
for(int i=0;i<from.length;i++)
{
if(from[i].InBounds())
mine[from[i].m_nColumn][from[i].m_nRow]=0;
Mine.SetIcon(from[i].m_nColumn,from[i].m_nRow,tukuai[0]);
}
for(int i=0;i<to.length;i++)
mine[to[i].m_nColumn][to[i].m_nRow]=to[i].m_ntupian;
return true;
}
/**********************************************************************/
private void removelines()
{
outerlabel:
for(int j=0;j<Mine.Row;j++)
{
for (int i=0;i<Mine.Comln;i++)
if (mine[i][j]==0)
continue outerlabel;
for (int k=j;k<Mine.Row-1;k++)
for (int i=0;i<Mine.Comln;i++)
{ mine[i][k]=mine[i][k+1];
Mine.SetIcon(i,k,tukuai[mine[i][k+1]]);
}
j-=1;
}
}//****************************************************************消行
/* public synchronized void addRandomLine()//添加随即行
{
int nRandom[]=new int[Mine.Comln];//20个整形的数组
for(int i=0;i<Mine.Comln;i++)
{
nRandom[i] = (int) (7 * Math.random());
}
nRandom[(int)(7 * Math.random())] = 0;
for(int nRow=Mine.Row-1;nRow>=0;nRow--)
for(int nCol=0; nCol<Mine.Comln; nCol++)
{
mine[nCol][nRow]=mine[nCol][nRow-1];
// Mine.SetIcon(nCol,nRow,tukuai[mine[nCol][nRow]]);
}
for(int i=0;i<Mine.Comln;i++)
{
mine[i][0] = nRandom[i];
//Mine.SetIcon(i,0,tukuai[nRandom[i]]);
}
for(int nRow=Mine.Row;nRow>0;nRow--)
for(int nCol=0; nCol<Mine.Comln; nCol++)
{
//mine[nCol][nRow]=mine[nCol][nRow-1];
Mine.SetIcon(nCol,nRow,tukuai[mine[nCol][nRow]]);
}
/* for(int i = 0 ; i<4;i++)
{
m_curPiece[i].m_nRow++;
//Mine.setIcon(m_curPiece[i].m_nColumn,m_curPiece[i].m_nRow,kuai[m_curPiece[i].m_ntupian]);
Mine.SetIcon( m_curPiece[i].m_nColumn, m_curPiece[i].m_nRow, tukuai[m_curPiece[i].m_ntupian]);
}
*/
/* boolean bAllZero=true;
boolean bNoZero=true;
for(int i=0;i<Mine.Comln;i++)
{
nRandom[i] = (int) (7 * Math.random());
if (nRandom[i] != 0)
bAllZero = false; //如果nRandom不是0(空) 那么bNoZero为真
else
bNoZero = false; //如果nRandom是 0(空)
}
if (bAllZero)
{ //如果bAllZero为真 那么岁机行中的一个就岁机成不是0(空)的方块
nRandom[ (int) (Mine.Comln * Math.random())] = (int) (Math.random() * 6 + 1);
}
else if (bNoZero)
{ //如果bNoZero为真 那么随即行中的一个就变成0(空)
nRandom[ (int) (Mine.Comln * Math.random())] = 0;
}
for(int nCol=0;nCol<Mine.Comln;nCol++)
for(int nRow=Mine.Row;Mine.Row>0;Mine.Row--)
{
mine[nCol][nRow]=mine[nCol][nRow+1];
Mine.SetIcon(nCol,nRow,tukuai[mine[nCol][nRow]]);
}
for(int nCol=0;nCol<Mine.Comln;nCol++)
{
mine[nCol][0]=nRandom[nCol];
Mine.SetIcon(nCol,0,tukuai[nRandom[nCol]]);
}
for(int i=0;i<4;i++)
{
m_curPiece[i].m_nRow--;
Mine.SetIcon( m_curPiece[i].m_nColumn, m_curPiece[i].m_nRow, tukuai[m_curPiece[i].m_ntupian]);
}
}
*/
/************************************************************加行*/
public void SetSpeed(int speed)
{
this.thespeed = speed;
}
public int GetSpeed()
{
return this.thespeed;
}
/***************************************************停止*/
public synchronized void stop()//线层处理
{
if(theThread!=null)//如果线层不为空
theThread.stop();
theThread=null;
}
/****************************************************暂停*/
public synchronized void pause()//游戏暂停
{
if(theThread!=null)//如果线层不为空
{
try
{
theThread.suspend();//线层暂停
Paused=true;//暂停为真
}
catch(Exception e){e.printStackTrace();}
}
}
//***********************************************************启动线程
public synchronized void start()
{
if(theThread!=null)
{
Paused=false;//暂停为假
theThread.resume();//继续执行线层以前执行的线层
return;
}
for(int j = 0; j<Mine.Row;j++)
for(int i = 0 ;i<Mine.Comln;i++ )
{
mine[i][j]=0;
Mine.SetIcon(i,j,tukuai[0]);
}
theThread = new Thread(this);
IsNeedNewPiece = true;
IsGameInPlay=true;
Mine.requestFocus();
theThread.start();
}
/******************************************run*/
public void run()
{
int sudu;
int l = 0;
while (IsGameInPlay) {
try {
sudu = this.thespeed;
Thread.sleep(DelayMap[sudu]);
}
catch (InterruptedException e) {
e.printStackTrace();
}
if (IsNeedNewPiece) {
removelines();
newPrePiece();
transferPreToCur();
IsNeedNewPiece = false;
}
else {
IsNeedNewPiece = !moveCurPiece(0, -1, false);
//addRandomLine();
}
// l+=1;
//if(l%10==0)addRandomLine();
}
theThread = null;
}
/* while (true)
{
try
{
in = client.getInputStream();
out =client.getOutputStream();
byte [] buf =new byte[256];
in.read(buf);
String str= new String(buf);
jTextArea1.append("客户机说:"+str);
jTextArea1.append("\n");
}
catch (IOException e ){}
}
*/
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void jButton1_actionPerformed(ActionEvent e) {
// Server server = new Server (this);
this.start();
}
void jButton2_actionPerformed(ActionEvent e) {
System.exit(0);
}
public boolean Mine_keyPressed(KeyEvent e) {
int Key;
Key = e.getKeyCode();
if(!IsGameInPlay)return true;
if(Paused)return true;
if( moveCurPiece(0,-1,false)==false)return false;
if(Key == KeyEvent.VK_RIGHT)
{
moveCurPiece(1,0,false);
repaint();
}
if(Key == KeyEvent.VK_LEFT)
{ moveCurPiece(-1,0,false);
repaint();
}
if(Key == KeyEvent.VK_UP)
{ moveCurPiece(0,0,true);
repaint();
}
if (Key == KeyEvent.VK_DOWN)
{ while(moveCurPiece(0,-1,false));
repaint();
}
return true;
}
void jButton3_actionPerformed(ActionEvent e) {
stop();
}
void jButton4_actionPerformed(ActionEvent e) {
//Clinet clinet = new Clinet(this);
pause();
}
void jSlider1_mouseReleased(MouseEvent e) {
value = jSlider1.getValue();
SetSpeed(value);
valuestr = String.valueOf(value);
//jLabel3.setText("您的级别为"+valuestr);
KeyFocus.getPermanentFocusOwner( );
//KeyFocus.focusPreviousComponent(this);
//Mine.requestFocus();
}
void jButton5_actionPerformed(ActionEvent e) {
Server server = new Server(this);
Server.start();
}
void jButton6_actionPerformed(ActionEvent e) {
Clinet cline = new Clinet(this);
Clinet.start(); Server.start();
}
void jTextField1_actionPerformed(ActionEvent e) {
try
{
String str = jTextField1.getText();
byte[] buf = str.getBytes();
jTextField1.setText(null);
out.write(buf);
jTextArea1.append("我说:"+str);
jTextArea1.append("\n");
}
catch(IOException ioe){}
}
}
class CHUANGTI_jButton1_actionAdapter implements java.awt.event.ActionListener {
CHUANGTI adaptee;
CHUANGTI_jButton1_actionAdapter(CHUANGTI adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class CHUANGTI_jButton2_actionAdapter implements java.awt.event.ActionListener {
CHUANGTI adaptee;
CHUANGTI_jButton2_actionAdapter(CHUANGTI adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class CHUANGTI_Mine_keyAdapter extends java.awt.event.KeyAdapter {
CHUANGTI adaptee;
CHUANGTI_Mine_keyAdapter(CHUANGTI adaptee) {
this.adaptee = adaptee;
}
public void keyPressed(KeyEvent e) {
adaptee.Mine_keyPressed(e);
}
}
class CHUANGTI_jButton3_actionAdapter implements java.awt.event.ActionListener {
CHUANGTI adaptee;
CHUANGTI_jButton3_actionAdapter(CHUANGTI adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton3_actionPerformed(e);
}
}
class CHUANGTI_jButton4_actionAdapter implements java.awt.event.ActionListener {
CHUANGTI adaptee;
CHUANGTI_jButton4_actionAdapter(CHUANGTI adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton4_actionPerformed(e);
}
}
class CHUANGTI_jSlider1_mouseAdapter extends java.awt.event.MouseAdapter {
CHUANGTI adaptee;
CHUANGTI_jSlider1_mouseAdapter(CHUANGTI adaptee) {
this.adaptee = adaptee;
}
public void mouseReleased(MouseEvent e) {
adaptee.jSlider1_mouseReleased(e);
}
}
class CHUANGTI_jButton5_actionAdapter implements java.awt.event.ActionListener {
CHUANGTI adaptee;
CHUANGTI_jButton5_actionAdapter(CHUANGTI adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton5_actionPerformed(e);
}
}
class CHUANGTI_jButton6_actionAdapter implements java.awt.event.ActionListener {
CHUANGTI adaptee;
CHUANGTI_jButton6_actionAdapter(CHUANGTI adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton6_actionPerformed(e);
}
}
class CHUANGTI_jTextField1_actionAdapter implements java.awt.event.ActionListener {
CHUANGTI adaptee;
CHUANGTI_jTextField1_actionAdapter(CHUANGTI adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jTextField1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -