0
我正在編寫一個程序,將兩個坦克相互對齊。我寫了所有的方法,除了結束遊戲的火之外。到目前爲止Java坦克遊戲,創建消防方法
public class Tank {
Tank() {
int xPos, yPos;
char direction;
boolean loaded = 0;
}
public void move(Tank currentPlayer) {
if (yPos<=4 && yPos>=0) {
if (xPos<=4 && xPos>=0) {
if (currentPlayer.direction == 'u') {
currentPlayer.yPos--;
}
if (currentPlayer.direction == 'd') {
currentPlayer.yPos++;
}
if (currentPlayer.direction == 'l') {
currentPlayer.xPos--;
}
if (currentPlayer.direction == 'r') {
currentPlayer.xPos++;
}
}
}
}
public void turn(boolean bool, Tank currentPlayer) {
if (currentPlayer.direction == 'u') {
currentPlayer.direction ='r';
}
if (currentPlayer.direction == 'd') {
currentPlayer.direction = 'l';
}
if (currentPlayer.direction == 'l') {
currentPlayer.direction ='u';
}
if (currentPlayer.direction == 'r') {
currentPlayer.direction ='d';
}
}
public void load(Tank currentPlayer) {
currentPlayer.loaded=true;
}
public int fire(Tank currentPlayer, Tank jim) {
// ???
}
}
我該如何去完成我的程序?任何幫助,將不勝感激。
火做什麼?它會立即結束遊戲嗎?它是否發射了射彈? – Clark
你如何確定槍擊命中另一輛坦克?如果是這樣,結束遊戲。 –
如果坦克發射並擊中另一坦克,那麼是的,這是遊戲結束。我只是不確定如何檢查對方的位置。這有點太複雜了 – Bill