【发布时间】:2020-05-05 09:56:35
【问题描述】:
所以伙计们,我正在创建一个游戏,在一个特定的情况下,我有一个敌人和一个随机生成在 10x10 阵列上的玩家,然后敌人必须向玩家移动,直到他们在相邻的单元格上。玩家由用户控制,敌人必须朝他的方向移动才能抓住他。 我已经开始并进行了阵列边缘检查以及敌人可以移动的位置,但我不知道如何进行追逐。你能帮帮我吗?
public void enemyMovement()
{
if(enemyAlive) {
if( enemy.getCurrentLine() == 0 ) {
if( enemy.getCurrentColumn() == 0 ) {
// only moves to right and down
}
else if( enemy.getCurrentColumn() == 9 ) {
// only moves to left and down
}
else {
// moves to the sides or down
}
}
else if( enemy.getCurrentLine() == 9 ) {
if( enemy.getCurrentColumn() == 0 ) {
// only moves up or right
}
else if( enemy.getCurrentColumn() == 9 ) {
// only moves up or left
}
else {
// only moves to the sides and up
}
}
else if ( enemy.getCurrentColumn() == 0 ) {
if( enemy.getCurrentLine() != 0 && enemy.getCurrentLine() != 9) {
// can go anywhere excepts left
}
}
else if( enemy.getCurrentColumn() == 9 ) {
if( enemy.getCurrentLine() != 0 && enemy.getCurrentLine() != 9) {
// can go anywhere excepts right
}
}
else {
// can goes anywhere
}
}
}
【问题讨论】:
-
嘿!不幸的是,Stack Overflow 不是编码服务,您的问题意味着为您解决问题。我可以给你一个提示:当你知道用户的位置和敌人在二维空间中的位置时,如果你分开看每个维度,应该很容易找出敌人要去哪里。