⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ogamefield.java~94~

📁 俄罗斯方块游戏,大学时写的,支持单机及点对点网络对战!同时我还在里面加入了使用技能的功能!不过有一个缺点,呵呵好象代码写的不够严谨,所以现在性能很低,我一直也没有优化它!
💻 JAVA~94~
字号:
package ct;//包
//头文件
import java.awt.*;
import java.awt.event.*;
import java.util.*;
//游戏类
public class oGameField extends Panel implements Runnable//主游戏类
{ //每个小方块的大小:宽,高
   int m_nSqLength;
   //游戏区域内的列和行
   static int m_nCols;
   static int m_nRows;
  //游戏窗体大小
   public static int WIDTH=200;
   public static int HEIGHT=360;
   //当前的界面情况
  int m_nField[][];//本页游戏画面
  int m_nOldField[][];//上页游戏画面
  //对手的情况
  int m_nRivalField[][];

   final Color BAKCOLOR=new Color(112,171,151);//背景颜色
   final Color FORCOLOR=Color.black;//前景颜色
   int b;//标注游戏状态,0为游戏开始,1为暂停,-1为结束

   Graphics m_gOffGraph;//声名绘图变量

   Frame1 m_tFrame;//声名主窗体变量
   Tetrics otc;//

    public oGameField()
    {//构造游戏方法
        super();//将本窗体设置为容器
        setBackground(BAKCOLOR);//设置背景色
        initParam();//游戏初始化
    }

    public oGameField(Tetrics tc)
    {//重载构造游戏方法
        super();//将本窗体设置为容器
        otc=tc;
        m_tFrame=otc.m_tFrame;
        setBackground(BAKCOLOR);//设置背景色
        initParam();//游戏初始化
    }
 /*   public oGameField(Frame1 tFrame)
  {//重载构造游戏方法
      super();//将本窗体设置为容器
      m_tFrame=tFrame;
      setBackground(BAKCOLOR);//设置背景色
      initParam();//游戏初始化
  }*/

   public void initParam()
   {
     m_nField=new int [m_nCols][m_nRows+4];
       m_nOldField=new int[m_nCols][m_nRows+4];
       //对手的状态
    m_nRivalField=new int [m_nCols][m_nRows+4];

   //设置初始参数
        m_nSqLength=20;
        m_nCols=otc.nextPiece.m_nCols;
        m_nRows=otc.nextPiece.m_nRows;
   }

//线程开始
   public synchronized void start()
   {

   }

   public void sendStatus()
  {//若是连机把玩家游戏区域的信息发送给对手
   //   System.out.println("发送游戏状态呀!!!!!!!!!!!!!!!!");
      if (m_tFrame.m_nNetStatus == Frame1.NOCONNECT)
        return;
      String str = "Status:";
      for (int nCol = 0; nCol < m_nCols; nCol++)
        for (int nRow = 0; nRow < m_nRows; nRow++) {
          str +=m_nField[nCol][nRow] + "|";
         // System.out.println("wrong");
           m_tFrame.sendStr(str);
        //  System.out.println("right");
        } //连机时候使用
}



//更新游戏界面
   public void update(Graphics g)
   {
            paint(g);//绘制新游戏页面
   }

//绘制游戏界面
   public  void paint(Graphics g)
   {
       Image img1=createImage(m_nSqLength*10,m_nSqLength*18);
       //用来画自己的游戏区域
       Graphics g1=img1.getGraphics();
        for(int i=0;i<m_nCols;i++)
            for(int j=0;j<m_nRows;j++)
            {
               g1.setColor(otc.nextPiece.m_colors[m_nRivalField[i][m_nRows-1-j]]);//设置方块颜色
               g1.fill3DRect(m_nSqLength*i,m_nSqLength*j,m_nSqLength,m_nSqLength,true);//绘制立体效果方块
            }
           g.drawImage(img1,0,0,this);//绘制游戏画面
   }
   public void run()
   {while(otc.m_bGameInPlay)
       repaint();
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -