J2ME游戏代码示例——俄罗斯方块(2)
时间:2011-01-11 陈跃峰
* 绘制当前下落的方块
* @param g 画笔
*/
public void paintBrick(Graphics g){
for(int row = 0;row < 4;row++){
for(int col = 0;col < 4;col++){
//判断是否绘制
if(brick[brickType][index][row][col] == 1){
int cx = (cCol + col) * CELLWIDTH;
int cy = (cRow + row) * CELLWIDTH;
paintCell(g,cx,cy);
}
}
}
}
/**下一个方块左上角的x坐标*/
int nextBrickX = 110;
/**下一个方块左上角的y坐标*/
int nextBrickY = 30;
/**下一个方块文字*/
String str = "下一个方块";
/**
* 绘制下一个方块
* @param g 画笔
*/
public void paintNextBrick(Graphics g){
//绘制文字
g.drawString(str, nextBrickX, nextBrickY,
Graphics.LEFT | Graphics.TOP);
//绘制方块
for(int row = 0;row < 4;row++){
for(int col = 0;col < 4;col++){
//判断是否绘制
if(brick[nextBrickType][0][row][col] == 1){
int cx =nextBrickX+ col * CELLWIDTH;
int cy =nextBrickY + 20 + row * CELLWIDTH;
paintCell(g,cx,cy);
}
}
}
}
String scoreStr = "当前得分:";
/**
J2ME游戏代码示例——俄罗斯方块(2)(2)
时间:2011-01-11 陈跃峰
* 绘制游戏得分和关卡
* @param g 画笔
*/
public void paintLevelAndScore(Graphics g){
//绘制得分
g.drawString(scoreStr,nextBrickX,100,
Graphics.TOP | Graphics.LEFT);
g.drawString(String.valueOf(score), nextBrickX, 115,
Graphics.LEFT | Graphics.TOP);
//绘制关卡
g.drawString("第" + level + "关", nextBrickX, 150,
Graphics.TOP | Graphics.LEFT);
}
/**
* 方块下落
*/
public void brickDown(){
//达到底部
if(reachBottom()){
addBrickToMap();
//System.out.println("添加到界面成功");
gernerateBrick();
//System.out.println(1);
//清除满行
clearAllFullRow();
}else{
cRow++;
//是否和地图数据重叠
if(collisWithMap()){
//后退一行
cRow--;
|