1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
| // 게임 캐릭터 Flyweight
public class CharacterType {
private final String name;
private final Sprite sprite;
private final int health;
private final int damage;
public CharacterType(String name, Sprite sprite, int health, int damage) {
this.name = name;
this.sprite = sprite;
this.health = health;
this.damage = damage;
}
public void render(Graphics g, int x, int y, int level) {
// TODO: 렌더링 로직 구현
// 외재적 상태(x, y, level)를 사용하여 렌더링
}
public int getEffectiveDamage(int level) {
// TODO: 레벨에 따른 데미지 계산
return damage + (level * 2);
}
}
// Factory
public class CharacterTypeFactory {
private static final Map<String, CharacterType> characterTypes = new HashMap<>();
public static CharacterType getCharacterType(String typeName) {
// TODO: 캐시된 CharacterType 반환 또는 새로 생성
return characterTypes.computeIfAbsent(typeName, name -> {
// TODO: 캐릭터 타입별 기본 속성 설정
return createCharacterType(name);
});
}
private static CharacterType createCharacterType(String name) {
// TODO: 구현
return null;
}
}
// 게임 캐릭터 (Context)
public class GameCharacter {
private final CharacterType type;
private int x, y; // 외재적 상태
private int level; // 외재적 상태
private int currentHealth; // 외재적 상태
public GameCharacter(String typeName, int x, int y) {
this.type = CharacterTypeFactory.getCharacterType(typeName);
this.x = x;
this.y = y;
this.level = 1;
// TODO: 초기 체력 설정
}
public void render(Graphics g) {
type.render(g, x, y, level);
}
}
|