Skip to content

Commit c776ea0

Browse files
committed
clean
1 parent 70fc3b9 commit c776ea0

File tree

9 files changed

+30
-60
lines changed

9 files changed

+30
-60
lines changed

gui/src/main/java/com/github/kuangcp/tank/TankGame.java

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public static void main(String[] args) {
2323
MonitorExecutor.init();
2424
try {
2525
ResourceMgr.loadResource();
26-
RoundMapMgr.init();
2726
log.info("finish load resources");
2827

2928
startWsServer();

gui/src/main/java/com/github/kuangcp/tank/backup/v2/MainPanelV2.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import com.github.kuangcp.tank.domain.Hero;
77
import com.github.kuangcp.tank.domain.StageBorder;
88
import com.github.kuangcp.tank.mgr.PlayStageMgr;
9-
import com.github.kuangcp.tank.mgr.RoundMapMgr;
109
import com.github.kuangcp.tank.util.TankTool;
1110
import lombok.extern.slf4j.Slf4j;
1211

@@ -59,7 +58,7 @@ public MainPanelV2() {
5958
public void paint(Graphics g) {
6059
super.paint(g);
6160

62-
final StageBorder border = RoundMapMgr.instance.border;
61+
final StageBorder border = new StageBorder(20, 740, 20, 540);
6362
g.fillRect(0, 0, border.getMaxX() + border.getMinX(), border.getMaxY() + border.getMinY());
6463

6564
//调用函数绘画出主坦克

gui/src/main/java/com/github/kuangcp/tank/backup/v2/TankGameV2.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package com.github.kuangcp.tank.backup.v2;
22

33
import com.github.kuangcp.tank.domain.Hero;
4-
import com.github.kuangcp.tank.util.executor.MonitorExecutor;
5-
import com.github.kuangcp.tank.mgr.PlayStageMgr;
6-
import com.github.kuangcp.tank.mgr.RoundMapMgr;
74
import com.github.kuangcp.tank.domain.StageBorder;
5+
import com.github.kuangcp.tank.mgr.PlayStageMgr;
6+
import com.github.kuangcp.tank.util.executor.MonitorExecutor;
87

98
import javax.swing.*;
109
import java.util.Collections;
@@ -25,7 +24,6 @@ public static void main(String[] args) {
2524
//最外层JFrame的构造函数
2625
public TankGameV2() {
2726
MonitorExecutor.init();
28-
RoundMapMgr.init();
2927
PlayStageMgr.init(new Hero(50, 20, 5), Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
3028

3129
MainPanelV2 panel = new MainPanelV2();
@@ -35,7 +33,7 @@ public TankGameV2() {
3533
panelThread.start();
3634

3735

38-
final StageBorder border = RoundMapMgr.instance.border;
36+
final StageBorder border = new StageBorder(20, 740, 20, 540);
3937

4038
this.setLocation(200, 50);
4139
this.setSize(border.getMaxX() + border.getMinX(), border.getMaxY() + border.getMinY() * 2);

gui/src/main/java/com/github/kuangcp/tank/domain/Bullet.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.github.kuangcp.tank.domain.event.MoveLoopEvent;
44
import com.github.kuangcp.tank.mgr.PlayStageMgr;
5-
import com.github.kuangcp.tank.mgr.RoundMapMgr;
65
import lombok.extern.slf4j.Slf4j;
76

87
import java.awt.*;
@@ -39,7 +38,8 @@ public void run() {
3938
this.move();
4039

4140
//判断子弹是否碰到边缘 或者命中基地
42-
if (PlayStageMgr.instance.willInBorder(this) || RoundMapMgr.instance.border.hitHome(x, y)) {
41+
final PlayStageMgr stage = PlayStageMgr.instance;
42+
if (stage.willInBorder(this) || stage.border.hitHome(x, y)) {
4343
this.alive = false;
4444
this.stop();
4545
}

gui/src/main/java/com/github/kuangcp/tank/frame/MainFrame.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.github.kuangcp.tank.frame;
22

3-
import com.github.kuangcp.tank.mgr.RoundMapMgr;
43
import com.github.kuangcp.tank.panel.StageActionPanel;
54
import com.github.kuangcp.tank.panel.StarterPanel;
65
import com.github.kuangcp.tank.panel.TankGroundPanel;
@@ -48,7 +47,8 @@ public MainFrame() {
4847

4948
this.setTitle("Tank");
5049
this.setLocation(680, 290);
51-
this.setSize(RoundMapMgr.instance.border.getTotalX(), RoundMapMgr.instance.border.getTotalY());
50+
// TODO 启动panel 依据 stage resize
51+
this.setSize(760, 560);
5252

5353
this.setUndecorated(true);
5454
}

gui/src/main/java/com/github/kuangcp/tank/mgr/PlayStageMgr.java

+17-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import com.github.kuangcp.tank.domain.Hero;
88
import com.github.kuangcp.tank.domain.Hinder;
99
import com.github.kuangcp.tank.domain.Iron;
10+
import com.github.kuangcp.tank.domain.StageBorder;
1011
import com.github.kuangcp.tank.domain.Tank;
12+
import com.github.kuangcp.tank.resource.AvatarImgMgr;
1113
import com.github.kuangcp.tank.resource.DefeatImgMgr;
1214
import com.github.kuangcp.tank.resource.VictoryImgMgr;
1315
import com.github.kuangcp.tank.util.ExecutePool;
@@ -60,18 +62,16 @@ public class PlayStageMgr {
6062
public static volatile boolean newStage = true;
6163
public static volatile boolean invokeNewStage = false;
6264

63-
// 场景 上下文
64-
// public List<EnemyTank> enemyTanks;
65-
// public List<Brick> bricks; // 砖
66-
// public List<Iron> irons; // 铁
67-
6865
public Map<Integer, Hero> heroMap = new ConcurrentHashMap<>();
6966

7067
public static List<EnemyTank> enemyList;
7168
// todo 转移
7269
public static List<Brick> bricks;
7370
public static List<Iron> irons;
7471

72+
public StageBorder border = null;
73+
74+
7575
//所有按下键的code集合
7676
public static int[][] enemyTankMap = new int[12][2];
7777
public static int[] myself = new int[6];
@@ -98,6 +98,12 @@ public void markStartLogic() {
9898
*/
9999
public static void init(Hero hero, List<EnemyTank> enemyTanks, List<Brick> bricks, List<Iron> irons) {
100100
instance = new PlayStageMgr(hero, enemyTanks, bricks, irons);
101+
102+
instance.border = new StageBorder(20, 740, 20, 540);
103+
instance.border.setHomeX(380);
104+
instance.border.setHomeY(480);
105+
instance.border.setHomeW(AvatarImgMgr.instance.width);
106+
instance.border.setHomeH(AvatarImgMgr.instance.height);
101107
}
102108

103109
private PlayStageMgr(Hero hero, List<EnemyTank> enemyTanks, List<Brick> bricks, List<Iron> irons) {
@@ -347,13 +353,13 @@ public boolean willInBorder(Tank tank) {
347353
}
348354
switch (tank.direct) {
349355
case DirectType.UP:
350-
return tank.y - tank.getHalfHeight() - tank.getSpeed() > RoundMapMgr.instance.border.getMinY();
356+
return tank.y - tank.getHalfHeight() - tank.getSpeed() > border.getMinY();
351357
case DirectType.DOWN:
352-
return tank.y + tank.getHalfHeight() + tank.getSpeed() < RoundMapMgr.instance.border.getMaxY();
358+
return tank.y + tank.getHalfHeight() + tank.getSpeed() < border.getMaxY();
353359
case DirectType.LEFT:
354-
return tank.x - tank.getHalfHeight() - tank.getSpeed() > RoundMapMgr.instance.border.getMinX();
360+
return tank.x - tank.getHalfHeight() - tank.getSpeed() > border.getMinX();
355361
case DirectType.RIGHT:
356-
return tank.x + tank.getHalfHeight() + tank.getSpeed() < RoundMapMgr.instance.border.getMaxX();
362+
return tank.x + tank.getHalfHeight() + tank.getSpeed() < border.getMaxX();
357363
}
358364
return false;
359365
}
@@ -362,8 +368,8 @@ public boolean willInBorder(Bullet bullet) {
362368
if (Objects.isNull(bullet)) {
363369
return false;
364370
}
365-
return bullet.x <= RoundMapMgr.instance.border.getMinX() || bullet.x >= RoundMapMgr.instance.border.getMaxX()
366-
|| bullet.y <= RoundMapMgr.instance.border.getMinY() || bullet.y >= RoundMapMgr.instance.border.getMaxY();
371+
return bullet.x <= border.getMinX() || bullet.x >= border.getMaxX()
372+
|| bullet.y <= border.getMinY() || bullet.y >= border.getMaxY();
367373
}
368374

369375
public static void setEnemySize(int enemySize) {

gui/src/main/java/com/github/kuangcp/tank/mgr/RoundMapMgr.java

-31
This file was deleted.

gui/src/main/java/com/github/kuangcp/tank/panel/TankGroundPanel.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import com.github.kuangcp.tank.frame.SettingFrame;
1111
import com.github.kuangcp.tank.mgr.BombMgr;
1212
import com.github.kuangcp.tank.mgr.PlayStageMgr;
13-
import com.github.kuangcp.tank.mgr.RoundMapMgr;
1413
import com.github.kuangcp.tank.resource.AvatarImgMgr;
1514
import com.github.kuangcp.tank.resource.ColorMgr;
1615
import com.github.kuangcp.tank.util.HoldingKeyStateMgr;
@@ -29,7 +28,7 @@ public class TankGroundPanel extends JPanel implements java.awt.event.KeyListene
2928

3029
private void drawBg(Graphics g) {
3130
g.setColor(ColorMgr.instance.bgColor);
32-
final StageBorder border = RoundMapMgr.instance.border;
31+
final StageBorder border = PlayStageMgr.instance.border;
3332
g.fillRect(0, 0, border.getMinX() + border.getMaxX(), border.getMinY() + border.getMaxY());
3433
g.setColor(Color.green);
3534
g.drawRect(border.getMinX(), border.getMinY(),
@@ -41,13 +40,13 @@ private void drawHeroInfo(Graphics g) {
4140
final String lifeInfo = "Life:" + PlayStageMgr.hero.getLife()
4241
+ " Enemy: " + PlayStageMgr.instance.getLiveEnemy()
4342
+ " Prize: " + PlayStageMgr.hero.getPrize();
44-
g.drawString(lifeInfo, RoundMapMgr.instance.border.getMinX(), 15);
43+
g.drawString(lifeInfo, PlayStageMgr.instance.border.getMinX(), 15);
4544
}
4645

4746
private void drawMonitorInfo(Graphics g) {
4847
g.setColor(Color.LIGHT_GRAY);
4948
g.drawString(MonitorExecutor.info.toString(),
50-
RoundMapMgr.instance.border.getMinX(), RoundMapMgr.instance.border.getTotalY() - 3);
49+
PlayStageMgr.instance.border.getMinX(), PlayStageMgr.instance.border.getTotalY() - 3);
5150
}
5251

5352
@Override

gui/src/main/java/com/github/kuangcp/tank/resource/AvatarImgMgr.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.github.kuangcp.tank.domain.StageBorder;
44
import com.github.kuangcp.tank.domain.VisualImgItem;
5-
import com.github.kuangcp.tank.mgr.RoundMapMgr;
5+
import com.github.kuangcp.tank.mgr.PlayStageMgr;
66
import lombok.extern.slf4j.Slf4j;
77

88
import java.awt.*;
@@ -27,7 +27,7 @@ public String getConfigKey() {
2727

2828
@Override
2929
public void drawSelf(Graphics g, ImageObserver observer) {
30-
final StageBorder border = RoundMapMgr.instance.border;
30+
final StageBorder border = PlayStageMgr.instance.border;
3131
g.drawImage(instance.curImg, border.getHomeX(), border.getHomeY(), instance.width, instance.height, observer);
3232
}
3333
}

0 commit comments

Comments
 (0)