parent
b4b9ac582b
commit
20198f66df
@ -0,0 +1,29 @@
|
||||
package com.msb.decorator;/**
|
||||
* @Author bingor
|
||||
* @Date 2022/10/13 10:19
|
||||
* @Description: com.msb.decorator
|
||||
* @Version: 1.0
|
||||
*/
|
||||
|
||||
import com.msb.model.abstracts.GameObject;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
*@ClassName GODecoratory
|
||||
*@Description TODO
|
||||
*@Author bingor
|
||||
*@Date 2022/10/13 10:19
|
||||
*@Version 3.0
|
||||
*/
|
||||
public abstract class GODecoratory extends GameObject {
|
||||
|
||||
protected GameObject gameObject;
|
||||
|
||||
public GODecoratory(GameObject gameObject) {
|
||||
this.gameObject = gameObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void paint(Graphics g);
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.msb.decorator;/**
|
||||
* @Author bingor
|
||||
* @Date 2022/10/13 10:23
|
||||
* @Description: com.msb.decorator
|
||||
* @Version: 1.0
|
||||
*/
|
||||
|
||||
import com.msb.model.abstracts.GameObject;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
*@ClassName RectDecorator
|
||||
*@Description TODO
|
||||
*@Author bingor
|
||||
*@Date 2022/10/13 10:23
|
||||
*@Version 3.0
|
||||
*/
|
||||
public class RectDecorator extends GODecoratory {
|
||||
|
||||
public RectDecorator(GameObject gameObject) {
|
||||
super(gameObject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
this.x = gameObject.x;
|
||||
this.y = gameObject.y;
|
||||
gameObject.paint(g); //原来的样式
|
||||
|
||||
//需要装饰的样式
|
||||
Color color = g.getColor();
|
||||
g.setColor(Color.WHITE);
|
||||
g.drawRect(super.gameObject.x, super.gameObject.y, super.gameObject.getWidth()+2, super.gameObject.getHeight()+2);
|
||||
// g.drawRect(this.x, this.y, getWidth()+2, getHeight()+2);
|
||||
g.setColor(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return super.gameObject.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return super.gameObject.getHeight();
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package com.msb.decorator;/**
|
||||
* @Author bingor
|
||||
* @Date 2022/10/13 10:23
|
||||
* @Description: com.msb.decorator
|
||||
* @Version: 1.0
|
||||
*/
|
||||
|
||||
import com.msb.model.abstracts.GameObject;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
*@ClassName RectDecorator
|
||||
*@Description TODO
|
||||
*@Author bingor
|
||||
*@Date 2022/10/13 10:23
|
||||
*@Version 3.0
|
||||
*/
|
||||
public class TailDecorator extends GODecoratory {
|
||||
|
||||
public TailDecorator(GameObject gameObject) {
|
||||
super(gameObject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
this.x = gameObject.x;
|
||||
this.y = gameObject.y;
|
||||
gameObject.paint(g); //原来的样式
|
||||
|
||||
//需要装饰的样式
|
||||
Color color = g.getColor();
|
||||
g.setColor(Color.YELLOW);
|
||||
// g.drawLine(super.gameObject.x, super.gameObject.y, super.gameObject.x+getWidth(), super.gameObject.y+getHeight());
|
||||
// g.drawLine(gameObject.x, gameObject.y, gameObject.x+getWidth(), gameObject.y+getHeight());
|
||||
g.drawLine(this.x, this.y, this.x+getWidth(), this.y+getHeight());
|
||||
g.setColor(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return super.gameObject.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return super.gameObject.getHeight();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue