泡泡堂代码 JAVA_Java手机游戏泡泡堂源码

package game;

import java.util.Random;

/**

*

Title:

*

Description:

*

Copyright: Copyright (c) 2005

*

Company:

* @author not attributable

* @version 1.0

*/

public class ComAI{

Role role;

Random m_Random;

int nWay;

int nSetp;

int nTargetRow =-1, nTargetCol =-1 ;

final static int GOEST_RANDOM = 0;

final static int GOEST_ATTACK = 1;

public static int GOEST_STATE = GOEST_RANDOM;

ComAI(){

//if(role.RoleType==Role.COMPUTTER_2){

m_Random = new Random(222);

nSetp = 0;

nWay = -1;

//}

}

public void getData(Role r,Map m,GameHandle h){//获得数据并作处反应

if(role.RoleType==Role.COMPUTTER){//电脑1,即求救者智能

if(!GameManage.bIsRescue){return;}

followAction(r,m);//跟随动作

return;

}else if(role.RoleType==Role.COMPUTTER_2){//电脑II,即幽灵的智能

if(role.nCurrentMsg >= Role.MSG_DEAD){return;}

checkTarget(r,m,h);//检测目标人物

switch(GOEST_STATE){

case GOEST_RANDOM:{//随机动作

randomAction();

}break;

case GOEST_ATTACK:{//进攻动作

attackAction(r,m,h);

}break;

}

return;

}

}

public void followAction(Role r,Map m){

if(role.touchPoint[1].x+role.velocity < r.touchPoint[0].x){//右边跟踪

role.nCurrentMsg = Role.MSG_RIGHT_MOVE;

}else if (role.touchPoint[0].x-role.velocity > r.touchPoint[1].x){//左边跟踪

role.nCurrentMsg = Role.MSG_LEFT_MOVE;

}else if (role.touchPoint[2].y+role.velocity < r.touchPoint[0].y){//下边跟踪

role.nCurrentMsg = Role.MSG_DOWN_MOVE;

}else if (role.touchPoint[0].y-role.velocity > r.touchPoint[2].y){//上边跟踪

role.nCurrentMsg = Role.MSG_UP_MOVE;

}else{

role.nCurrentMsg = -1;//无动作

}

}

public void checkTarget(Role r, Map m,GameHandle h){

int gRow = h.getPutPaopRow(role,m);

int gCol = h.getPutPaopCol(role,m);

int rRow = h.getPutPaopRow(r,m);

int rCol = h.getPutPaopCol(r,m);

boolean bCanAttack = true;

//发现出击

if(gRow == rRow){//同行

if(gCol>=rCol){//目标在左边

for(int i=gCol;i>=rCol;i--){

if(m.byBuild[gRow][i]>0)

{bCanAttack = false; break;}

}

}else{//目标在右边

for(int i=gCol;i<=rCol;i++){

System.out.println("b="+m.byBuild[gRow][i]);

if(m.byBuild[gRow][i]>0)

{bCanAttack = false; break;}

}

}

if(bCanAttack){//无阻拦

GOEST_STATE= GOEST_ATTACK;

nTargetCol = h.getPutPaopCol(r,m);

nTargetRow = -1;

role.velocity = 5;

}

}elseif(gCol == rCol){//同列

if(gRow>=rRow){//目标在左边

for(int i=gRow;i>=rRow;i--){

if(m.byBuild[i][gCol]>0)

{bCanAttack = false; break;}

}

}else{//目标在右边

for(int i=gRow;i<=rRow;i++){

if(m.byBuild[i][gCol]>0)

{bCanAttack = false; break;}

}

}

if(bCanAttack){//无阻拦

GOEST_STATE= GOEST_ATTACK;

nTargetRow = h.getPutPaopRow(r,m);

nTargetCol = -1;

role.velocity = 5;

}

}

}

public void attackAction(Role r,Map m,GameHandle h){

if(nTargetCol>0){

if(h.getPutPaopCol(role,m)>h.getPutPaopCol(r,m)){

role.nCurrentMsg = Role.MSG_LEFT_MOVE;

}else if(h.getPutPaopCol(role,m)

role.nCurrentMsg = Role.MSG_RIGHT_MOVE;

}elseif(h.getPutPaopCol(role,m)==h.getPutPaopCol(r,m)){

GOEST_STATE =GOEST_RANDOM;

role.velocity = 1;

}

}else if(nTargetRow>0){

if(h.getPutPaopRow(role,m)>h.getPutPaopRow(r,m)){

role.nCurrentMsg = Role.MSG_UP_MOVE;

}else if(h.getPutPaopRow(role,m)

role.nCurrentMsg = Role.MSG_DOWN_MOVE;

}else if(h.getPutPaopRow(role,m)==h.getPutPaopRow(r,m)){

GOEST_STATE =GOEST_RANDOM;

role.velocity = 1;

}

}

}

public void randomAction(){

//随机移动

if(nSetp<=0){

nWay = (int)Math.abs(m_Random.nextInt()%4);//随机方向0~3

nSetp =(int)Math.abs(m_Random.nextInt()%8)+1;//随机步数1~9

}

switch(nWay){

case 0:{

role.nCurrentMsg = Role.MSG_UP_MOVE;

nSetp--;

}break;

case 1:{

role.nCurrentMsg = Role.MSG_LEFT_MOVE;

nSetp--;

}break;

case 2:{

role.nCurrentMsg = Role.MSG_DOWN_MOVE;

nSetp--;

}break;

case 3:{

role.nCurrentMsg = Role.MSG_RIGHT_MOVE;

nSetp--;

}break;

}

}//end fun

public void scout(){

}

}



更多源码 | 好库简介 | 网站地图 | 帮助中心 | 版权说明

Copyright© 2009-2012 OKBASE.NET All Rights Reserved 好库网 版权所有

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值