You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.8 KiB
67 lines
1.8 KiB
package com.study.tank;
|
|
|
|
import com.study.tank.cor.BulletAndTankCollider;
|
|
import com.study.tank.cor.Collider;
|
|
import com.study.tank.cor.ColliderChain;
|
|
import com.study.tank.cor.TankTankCollider;
|
|
import com.study.tank.factory.BaseTank;
|
|
|
|
import java.awt.*;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* @author xsj
|
|
* @date 2022/10/27 14:30
|
|
*/
|
|
public class GameModel {
|
|
public static GameModel INSTANCE = new GameModel();
|
|
|
|
static {
|
|
INSTANCE.init();
|
|
}
|
|
|
|
Tank myTank;
|
|
List<GameObject> gameModelList = new ArrayList<>();
|
|
ColliderChain chain = new ColliderChain();
|
|
|
|
public GameModel() {
|
|
}
|
|
|
|
public void init() {
|
|
myTank = new Tank(150, 150, Dir.DOWN, Group.GOOD);
|
|
//初始化敌人坦克
|
|
int initCountTank = Integer.parseInt((String) PropertyMgr.get("initTankCount"));
|
|
for (int i = 0; i < initCountTank; i++) {
|
|
new Tank(80 + i * 100, 50, Dir.DOWN, Group.BAD);
|
|
}
|
|
new Wall(200, 200, 50, 100);
|
|
new Wall(500, 200, 100, 200);
|
|
}
|
|
|
|
public void add(GameObject object) {
|
|
this.gameModelList.add(object);
|
|
}
|
|
|
|
public void remove(GameObject object) {
|
|
this.gameModelList.remove(object);
|
|
}
|
|
|
|
public void paint(Graphics g) {
|
|
for (int i = 0; i < gameModelList.size(); i++) {
|
|
gameModelList.get(i).paint(g);
|
|
}
|
|
|
|
for (int i = 0; i < gameModelList.size(); i++) {
|
|
for (int j = i + 1; j < gameModelList.size(); j++) {
|
|
GameObject o1 = gameModelList.get(i);
|
|
GameObject o2 = gameModelList.get(j);
|
|
//collider1.collider(o1, o2, this);//
|
|
//collider2.collider(o1, o2, this);
|
|
if (chain.collider(o1, o2)) return;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|