📄 ogamefield.java~1~
字号:
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; int m_nOldScore;//存放分数,供每个等级累加使用 //游戏窗体大小 public static int WIDTH=200; public static int HEIGHT=360; //当前的界面情况 int m_nField[][];//本页游戏画面 Thread m_theThread=null;//游戏线程 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();//将本窗体设置为容器 // m_tFrame=tFrame;//将游戏状态传给主窗体 otc=tc; // setBackground(BAKCOLOR);//设置背景色 initParam();//游戏初始化 } public void initParam() { //设置初始参数 m_nSqLength=20; m_nCols=10; m_nRows=18; m_nField=new int [m_nCols][m_nRows+4]; }//线程开始 public synchronized void start() { }//更新游戏界面 public void update(Graphics g) { paint(g);//绘制新游戏页面 }//绘制游戏界面 public synchronized 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.m_colors[m_nField[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() { } //结束游戏 public synchronized void stop() { }//暂停游戏 public synchronized void pause() { }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -