parent
98546b1759
commit
0092ad544e
@ -0,0 +1,83 @@
|
||||
package com.msb.model;/**
|
||||
* @Author bingor
|
||||
* @Date 2022/10/10 16:30
|
||||
* @Description: com.msb.model
|
||||
* @Version: 1.0
|
||||
*/
|
||||
|
||||
import com.msb.base.PropertyMgr;
|
||||
import com.msb.enums.DirEnum;
|
||||
import com.msb.enums.GroupEnum;
|
||||
import com.msb.factorys.CircleFactory;
|
||||
import com.msb.factorys.DefaultFactory;
|
||||
import com.msb.factorys.abstracts.GameFactory;
|
||||
import com.msb.model.abstracts.BaseExplode;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*@ClassName GameModel
|
||||
*@Description TODO
|
||||
*@Author bingor
|
||||
*@Date 2022/10/10 16:30
|
||||
*@Version 3.0
|
||||
*/
|
||||
public class GameModel {
|
||||
|
||||
Tank myTank = new Tank(100, 500, DirEnum.RIGHT, GroupEnum.GOOD, this);
|
||||
// Explode explode = new Explode(100, 100, this);
|
||||
// Bullet bullet = new Bullet(200, 200, DirEnum.DOWN);
|
||||
public List<Bullet> bullets = new ArrayList<>();
|
||||
public List<Tank> tanks = new ArrayList<>(); //敌方坦克
|
||||
public List<BaseExplode> explodes = new ArrayList<>(); //爆炸效果
|
||||
// public GameFactory gameFactory = new DefaultFactory();
|
||||
|
||||
public GameModel() {
|
||||
// Random random = new Random();
|
||||
int initTankCount = Integer.parseInt(PropertyMgr.getString("initTankCount"));
|
||||
|
||||
//创建5个敌方坦克
|
||||
for (int i=0; i<initTankCount; i++) {
|
||||
// tankFrame.tanks.add(new Tank(100 + i*80, 100, DirEnum.valueOf(random.nextInt(30)%4), GroupEnum.BAD, tankFrame));
|
||||
this.tanks.add(new Tank(100 + i*80, 100, DirEnum.DOWN, GroupEnum.BAD, this));
|
||||
}
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
Color color = g.getColor();
|
||||
g.setColor(Color.WHITE);
|
||||
g.drawString("子弹的数量:" + bullets.size(), 10, 60);
|
||||
g.drawString("敌方坦克数量:" + tanks.size(), 10, 90);
|
||||
g.drawString("爆炸的数量:" + explodes.size(), 10, 120);
|
||||
g.setColor(color);
|
||||
myTank.paint(g);
|
||||
|
||||
// explode.paint(g);
|
||||
|
||||
//画出敌方坦克
|
||||
for (int i=0; i<tanks.size(); i++) {
|
||||
tanks.get(i).paint(g);
|
||||
}
|
||||
|
||||
for (int i=0; i<bullets.size(); i++) {
|
||||
bullets.get(i).paint(g);
|
||||
}
|
||||
|
||||
for (int i=0; i<bullets.size(); i++) {
|
||||
for (int j=0; j<tanks.size(); j++) {
|
||||
bullets.get(i).collide(tanks.get(j));
|
||||
}
|
||||
}
|
||||
|
||||
//爆炸效果
|
||||
for (int i=0; i<explodes.size(); i++) {
|
||||
explodes.get(i).paint(g);
|
||||
}
|
||||
}
|
||||
|
||||
public Tank getMainTank() {
|
||||
return myTank;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue