parent
eb89138e23
commit
91f4e9d149
Binary file not shown.
@ -0,0 +1,13 @@
|
||||
package com.demo.tank.course9;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public abstract class GODecorator extends GameObject {
|
||||
GameObject go;
|
||||
|
||||
public GODecorator(GameObject go) {
|
||||
this.go = go;
|
||||
}
|
||||
|
||||
public abstract void paint(Graphics g);
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.demo.tank.course9;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class RectDecorator extends GODecorator {
|
||||
|
||||
public RectDecorator(GameObject go) {
|
||||
super(go);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
//decorator x,y 也要跟随游戏物体 变化
|
||||
this.x = go.x;
|
||||
this.y = go.y;
|
||||
go.paint(g);
|
||||
Color c = g.getColor();
|
||||
g.setColor(Color.MAGENTA);
|
||||
g.drawRect(go.x, go.y, getWidth(), getHeight());
|
||||
g.setColor(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return super.go.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return super.go.getHeight();
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.demo.tank.course9;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class TailDecorator extends GODecorator {
|
||||
|
||||
public TailDecorator(GameObject go) {
|
||||
super(go);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
go.paint(g);
|
||||
this.x = go.x;
|
||||
this.y = go.y;
|
||||
Color c = g.getColor();
|
||||
g.setColor(Color.WHITE);
|
||||
g.drawLine(go.x, go.y, go.x + getWidth(), go.y + getHeight());
|
||||
g.setColor(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return super.go.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return super.go.getHeight();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue