📄 gamemediator.java
字号:
package com.bjsxt.tank.core;
import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.List;
public class GameMediator {
Tank myTank;
private static GameMediator gamemediator ;
static {
gamemediator = new GameMediator();
}
List<GameObject> gameobjects = new ArrayList<GameObject>();
Collider collider = new ColliderChain();
private GameMediator(){
}
public static GameMediator getInstance(){
return gamemediator;
}
public void addGameObject(GameObject obj) {
this.gameobjects.add(obj);
}
public void removeGameObject(GameObject obj) {
this.gameobjects.remove(obj);
}
public void checkCollide() {
for (int i = 0; i < this.gameobjects.size(); i++) {
GameObject go1 = this.gameobjects.get(i);
for (int j = i + 1; j < this.gameobjects.size(); j++) {
GameObject go2 = this.gameobjects.get(j);
this.collider.collides(go1, go2);
}
}
}
public void drawGameObjects(Graphics g) {
for (int i = 0; i < this.gameobjects.size(); i++) {
GameObject obj = this.gameobjects.get(i);
if (obj != null && obj.isLive()) {
obj.draw(g);
}
}
}
public void drawString(Graphics g) {
Color c = g.getColor();
g.setColor(Color.BLACK);
g.drawString("missile count : " + Missile.count, 10, 50);
g.drawString("explode count : " + Explode.count, 10, 80);
g.drawString("tank count : " + Tank.count, 10, 110);
g.setColor(c);
}
void initWalls() {
this.addGameObject(GameFactoryMgr.getFactory().createWall(100, 300,
300, 50));
this.addGameObject(GameFactoryMgr.getFactory().createWall(300, 150, 50,
300));
}
void initTanks() {
for (int i = 0; i < PropertyMgr.getPropsInt("tank.initCount"); i++) {
this.addGameObject(GameFactoryMgr.getFactory().createTank(
100 + 80 * i, 100, false));
}
this.myTank = GameFactoryMgr.getFactory().createTank(
PropertyMgr.getPropsInt("myTank.initPos.x"),
PropertyMgr.getPropsInt("myTank.initPos.y"), true);
this.addGameObject(this.myTank);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -