www.pudn.com > Russian.rar > GameFrm.java
import java.util.*;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
/*
* Created on 2004-10-21
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class GameFrm extends Canvas
{
private int iState;
private byte cell[][] = null;
private int iRows=18, iCols=10;
private Shape curShape = null;
public int curRow, curCol;
public MoveThread run = null;
/* (non-Javadoc)
* @see javax.microedition.lcdui.Displayable#paint(javax.microedition.lcdui.Graphics)
*/
protected GameFrm()
{
super();
init();
iState=0;
}
protected void paint(Graphics gs)
{
// TODO Auto-generated method stub
//清屏
gs.setColor(255, 255, 255);
gs.fillRect(0, 0, getWidth(), getHeight());
int iCellLen = 8;
int iFenceLen = 2;
int x0=(this.getWidth() - iFenceLen*2 - (iCols-2)*iCellLen) / 2;
int y0=(this.getHeight() - iFenceLen*2 - (iRows-2)*iCellLen) / 2;
int x=x0, y=y0;
//栅栏和背景
gs.setColor(140, 178, 100);
gs.fillRect(x, y, iFenceLen*2 + (iCols-2)*iCellLen, (iFenceLen*2) + (iRows-2)*iCellLen);
//显示已堆积的
if (cell != null)
{
x += iFenceLen;
y += iFenceLen;
for(int i=1; i iRows - 1)
return false;
if (curCol <= 0 || curCol + curShape.iSideLength > iCols - 1)
return false;
for (int i = 0; i < curShape.iSideLength; i++)
{
for (int j = 0; j < curShape.iSideLength; j++)
{
if (1 == cell[curRow + i][curCol + j] || 9 == cell[curRow + i][curCol + j])
{
return false;
}
}
}
return true;
}
protected boolean IsConflict(int r, int c)
{
for (int i = 0; i < curShape.iSideLength; i++)
{
for (int j = 0; j < curShape.iSideLength; j++)
{
if (1 == curShape.cell[i][j] &&
(1 == cell[r + i][c + j] || 9 == cell[r + i][c + j])) //冲突
{
return true;
}
}
}
return false;
}
//初始化
protected void init()
{
cell = null;
cell = new byte[iRows][iCols];
//初值
for (int i=1; i iRows - 1 - 1) //超过底行
return ;
bAll = true;
for (int j=1; j0; r--)
{
for (int j=1; j