package game;
import javax.microedition.lcdui.*;
import java.lang.Math;
import java.util.*;
/*
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class GameHandle extends Canvas {
public int affairsMsg=0;//行为消息
public int behaviorMsg=0;//事件消息
public int nTouchWay = -1;
public boolean bIsPopMove = false;
Canvas canvas;
public boolean bIsOverlap = false;
Bomb.Pop temp = new Bomb.Pop();
public GameHandle() {
}
protected void paint(Graphics g){
}
public void DrawLine(){
for(int i=0;i<11;i++)
for(int j = 0;j<13;j++)
GameManage.g.drawRect(i*16,j*16,16,16) ;
}
public class Posit{
int rIndex,cIndex;
Posit(int c,int r){
cIndex =c;
rIndex =r;
}
}
public Posit[] boobPosit={
new Posit(0,0),
new Posit(-1,0),
new Posit(0,-1),
new Posit(1,0),
new Posit(0,1)
};
public void InitBoobPosit(){
}
/*---------------------------------检测通用类--------------------------------------------*/
/*---------------------------------------------------------
//重叠检测通用模块,如果和其它人物图片重叠需要重绘其它人物图片
----------------------------------------------------------*/
public boolean isOverlap(Role role1,Role role2,Map map){
for(int i = 0;i<4;i++){
//role1的其中一个点,是否在role2图象内部
if( role1.imagePoint[i].x > role2.imagePoint[0].x-5 && // 50
role1.imagePoint[i].y > role2.imagePoint[0].y-5 && // 42
role1.imagePoint[i].x < role2.imagePoint[2].x+5 && // 66
role1.imagePoint[i].y < role2.imagePoint[2].y+5){ // 60
return true;
}
}
return false;
}
/*------------------------------------------
//排序算法通用类,简单地实现,以后需要改进
--------------------------------------------*/
public void paintRank(Role role1,Role role2,Map map,boolean flag){
//一定要更新数据,否则判断的依据是旧的坐标数据
role1.UpdataAll();
role2.UpdataAll();
if(isOverlap(role1,role2,map)){//有重叠要画两个人物
if(role2.y<role1.y){
if( role2.nCurrentMsg >= Role.MSG_DEAD ){
role2.paintImage(GameManage.g,
role2.x,
role2.y,
role2.imgDeath,//绘制死亡
role2.btDeathTotalCol,//role.btDeathTotalRow,
role2.btDeathTotalRow,//role.btDeathTotalCol,
role2.btDeathCurrentIndex);
}else{
role2.paint(GameManage.g);//先画其它人
}
role1.paint(GameManage.g);//再画自己
}else{
role1.paint(GameManage.g);//先画自己
if(role2.nCurrentMsg >= Role.MSG_DEAD ){
role2.paintImage(GameManage.g,
role2.x,
role2.y,
role2.imgDeath,//绘制死亡
role2.btDeathTotalCol,//role.btDeathTotalRow,
role2.btDeathTotalRow,//role.btDeathTotalCol,
role2.btDeathCurrentIndex);
}else{
role2.paint(GameManage.g);//再画其它人
}
}
}else{//无重叠只画一个人物
if(flag)
role1.paint(GameManage.g);
}
}
/*-----------------------
//绘背景地图通用模块,但以后得改进
------------------------*/
public void drawBackground(Role role,Role role2,Map map){//画人物当前所在的背景地图
role.UpdataAll();
//左上角一定要绘。
map.paintFloor(GameManage.g,
role.imagePoint[0].row,
role.imagePoint[0].col);
map.paintBuild(GameManage.g,
role.imagePoint[0].row,
role.imagePoint[0].col);
//若人物图片占了两行以上,则画同列下一行的地图
if(role.imagePoint[0].row != role.imagePoint[3].row){
map.paintFloor(GameManage.g,
role.imagePoint[3].row,
role.imagePoint[3].col);
map.paintBuild(GameManage.g,
role.imagePoint[3].row,
role.imagePoint[3].col);
if( role.imagePoint[3].row - role.imagePoint[0].row == 2 ){//人物图占了三行
map.paintFloor(GameManage.g,
role.imagePoint[3].row-1,
role.imagePoint[3].col);
map.paintBuild(GameManage.g,
role.imagePoint[3].row-1,
role.imagePoint[3].col);
}
}
//若人物图片占了两列以上,则画同行下一列的地图
if(role.imagePoint[0].col != role.imagePoint[1].col){
map.paintFloor(GameManage.g,
role.imagePoint[1].row,
role.imagePoint[1].col);
map.paintBuild(GameManage.g,
role.imagePoint[1].row,
role.imagePoint[1].col);
}
//若人物图片同占了两行两列以上,则画下一列下一行的地图
if(role.imagePoint[0].row != role.imagePoint[3].row &&
role.imagePoint[0].col != role.imagePoint[1].col){
map.paintFloor(GameManage.g,
role.imagePoint[2].row,
role.imagePoint[2].col);
map.paintBuild(GameManage.g,
role.imagePoint[2].row,
role.imagePoint[2].col);
if( role.imagePoint[3].row - role.imagePoint[0].row == 2 ){//人物图占了三行
map.paintFloor(GameManage.g,
role.imagePoint[2].row-1,
role.imagePoint[2].col);
map.paintBuild(GameManage.g,
role.imagePoint[2].row-1,
role.imagePoint[2].col);
}
}
}
/*---------------------
//通用函数,移植较高
//0表示左上,1表示右上,2表示右下,3表示左下.
//nTouchWay 表示碰撞方向,可被nearlyMove引用
----------------------*/
public boolean TouchCheck(int msg,Role r,Map m){//碰撞函数
switch(msg){//GameCheck.behaviorMsg ){
case Role.MSG_UP_MOVE:{
if(m.byBuild[r.touchPoint[0].row][r.touchPoint[0].col]>0||
m.byBuild[r.touchPoint[1].row][r.touchPoint[1].col]>0){//上边有碰撞
if((m.byBuild[r.touchPoint[1].row][r.touchPoint[1].col] == 9 ||
m.byBuild[r.touchPoint[1].row][r.touchPoint[1].col] == 9 ) &&
bIsPopMove == false){
//if(r.RoleType ==Role.PLAYER){
bIsPopMove = true;
nTouchWay = 0;
//}
}
return true;
}
}break;
case Role.MSG_LEFT_MOVE:{
if(m.byBuild[r.touchPoint[0].row][r.touchPoint[0].col]>0||
m.byBuild[r.touchPoint[3].row][r.touchPoint[3].col]>0){//左边有碰撞
if((m.byBuild[r.touchPoint[0].row][r.touchPoint[0].col] == 9 ||
m.byBuild[r.touchPoint[3].row][r.touchPoint[3].col] == 9) &&
bIsPopMove == false ){
//if(r.RoleType ==Role.PLAYER){
bIsPopMove = true;
nTouchWay = 1;
//}
}
return true;
}
}break;
case Role.MSG_DOWN_MOVE:{
if(m.byBuild[r.touchPoint[2].row][r.touchPoint[2].col]>0||
m.byBuild[r.touchPoint[3].row][r.touchPoint[3].col]>0){//下边有碰撞
if((m.byBuild[r.touchPoint[2].row][r.touchPoint[2].col] == 9 ||
m.byBuild[r.touchPoint[3].row][r.touchPoint[3].col] == 9 ) &&
bIsPopMove == false){
//if(r.RoleType ==Role.PLAYER){