坦克大战(一期)-设计模式-装饰者模式应用到子弹上-有bug版1.1

DesignPatterns
bingor 2 years ago
parent 20198f66df
commit 32b0fa6c52

@ -13,7 +13,7 @@ public class TankDemo {
//现实当中,虽然可以过按键来改变方块的坐标并且重新刷新画板来实现移动,但是敌方的坦克应该是自动在跑 //现实当中,虽然可以过按键来改变方块的坐标并且重新刷新画板来实现移动,但是敌方的坦克应该是自动在跑
while (true) { while (true) {
// Thread.sleep(50); // Thread.sleep(50);
Thread.sleep(1000); Thread.sleep(500);
tankFrame.repaint(); tankFrame.repaint();
} }
} }

@ -24,8 +24,10 @@ public class RectDecorator extends GODecoratory {
@Override @Override
public void paint(Graphics g) { public void paint(Graphics g) {
this.x = gameObject.x; /*this.x = gameObject.x;
this.y = gameObject.y; this.y = gameObject.y;*/
this.x = super.gameObject.x;
this.y = super.gameObject.y;
gameObject.paint(g); //原来的样式 gameObject.paint(g); //原来的样式
//需要装饰的样式 //需要装饰的样式
@ -45,4 +47,5 @@ public class RectDecorator extends GODecoratory {
public int getHeight() { public int getHeight() {
return super.gameObject.getHeight(); return super.gameObject.getHeight();
} }
} }

@ -24,8 +24,10 @@ public class TailDecorator extends GODecoratory {
@Override @Override
public void paint(Graphics g) { public void paint(Graphics g) {
this.x = gameObject.x; /*this.x = gameObject.x;
this.y = gameObject.y; this.y = gameObject.y;*/
this.x = super.gameObject.x;
this.y = super.gameObject.y;
gameObject.paint(g); //原来的样式 gameObject.paint(g); //原来的样式
//需要装饰的样式 //需要装饰的样式
@ -46,4 +48,5 @@ public class TailDecorator extends GODecoratory {
public int getHeight() { public int getHeight() {
return super.gameObject.getHeight(); return super.gameObject.getHeight();
} }
} }

@ -6,6 +6,7 @@ package com.msb.inter.impl;/**
*/ */
import com.msb.model.Bullet; import com.msb.model.Bullet;
import com.msb.model.GameModel;
import com.msb.model.Tank; import com.msb.model.Tank;
import com.msb.enums.DirEnum; import com.msb.enums.DirEnum;
import com.msb.inter.FireStrategy; import com.msb.inter.FireStrategy;
@ -25,6 +26,7 @@ public class FourFireStrategy implements FireStrategy {
for (DirEnum value : DirEnum.values()) { for (DirEnum value : DirEnum.values()) {
// new Bullet(bX, bY, value, tank.getGroup(), tank.getGameModel()); // new Bullet(bX, bY, value, tank.getGroup(), tank.getGameModel());
new Bullet(bX, bY, value, tank.getGroup()); new Bullet(bX, bY, value, tank.getGroup());
// GameModel.INSTANCE.add(new Bullet(bX, bY, value, tank.getGroup()));
} }
} }
} }

Loading…
Cancel
Save