-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package gof.dp.templatemethod; | ||
|
||
public class Player { | ||
|
||
private PlayerClass playerClass; | ||
|
||
public Player(){ | ||
playerClass = new WarriorClass(); | ||
playerClass.showClass(); | ||
} | ||
|
||
public PlayerClass getPlayerClass(){ | ||
return playerClass; | ||
} | ||
|
||
public void upgradeClass(PlayerClass level){ | ||
this.playerClass = level; | ||
playerClass.showClass(); | ||
} | ||
|
||
public void play(int count){ | ||
playerClass.act(count); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package gof.dp.templatemethod; | ||
|
||
public abstract class PlayerClass { | ||
|
||
public abstract void dash(); | ||
public abstract void hit(); | ||
public abstract void specialMove(); | ||
public abstract void showClass(); | ||
|
||
|
||
final public void act(int count){ | ||
dash(); | ||
for (int i = 0; i < count; i++) { | ||
hit(); | ||
} | ||
specialMove(); | ||
hiddenSkill(); | ||
} | ||
|
||
public void hiddenSkill(){}; //오퍼레이션 훅 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package gof.dp.templatemethod; | ||
|
||
public class SwordKingClass extends PlayerClass{ | ||
@Override | ||
public void dash() { | ||
System.out.println("번쩍 접근합니다."); | ||
} | ||
|
||
@Override | ||
public void hit() { | ||
System.out.println("어검술! 일반 공격합니다."); | ||
} | ||
|
||
@Override | ||
public void specialMove() { | ||
System.out.println("진백호령! 필살기로 공격합니다."); | ||
} | ||
|
||
@Override | ||
public void showClass() { | ||
System.out.println("<<<<< 제 직업은 검제입니다. >>>>>"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package gof.dp.templatemethod; | ||
|
||
public class SwordsEmperorClass extends PlayerClass { | ||
@Override | ||
public void dash() { | ||
System.out.println("쇄혼비무! 공격하며 접근합니다."); | ||
} | ||
|
||
@Override | ||
public void hit() { | ||
System.out.println("초혼비무! 적을 끌어당겨 공격합니다."); | ||
} | ||
|
||
@Override | ||
public void specialMove() { | ||
System.out.println("포효검황! 뿡! 필살기로 공격합니다."); | ||
} | ||
|
||
@Override | ||
public void showClass() { | ||
System.out.println("<<<<< 제 직업은 검황입니다. >>>>>"); | ||
} | ||
|
||
@Override | ||
public void hiddenSkill() { | ||
System.out.println("히든 스킬 발동! 적을 도발합니다!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package gof.dp.templatemethod; | ||
|
||
public class SwordsManClass extends PlayerClass { | ||
@Override | ||
public void dash() { | ||
System.out.println("달려서 접근합니다."); | ||
} | ||
|
||
@Override | ||
public void hit() { | ||
System.out.println("백호참! 일반 공격합니다."); | ||
} | ||
|
||
@Override | ||
public void specialMove() { | ||
double rate = Math.random()*100; | ||
if(rate < 10) System.out.println("체력이 부족합니다."); | ||
else System.out.println("백건! 필살기로 공격합니다."); | ||
} | ||
|
||
@Override | ||
public void showClass() { | ||
System.out.println("<<<<< 제 직업은 검객입니다. >>>>>"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package gof.dp.templatemethod; | ||
|
||
public class TemplateMethodTest { | ||
|
||
public static void main(String[] args){ | ||
Player player = new Player(); | ||
player.play(1); | ||
|
||
player.upgradeClass(new SwordsManClass()); | ||
player.play(2); | ||
|
||
player.upgradeClass(new SwordKingClass()); | ||
player.play(3); | ||
|
||
player.upgradeClass(new SwordsEmperorClass()); | ||
player.play(4); | ||
} | ||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package gof.dp.templatemethod; | ||
|
||
public class WarriorClass extends PlayerClass { | ||
|
||
@Override | ||
public void dash() { | ||
System.out.println("뚜벅 뚜벅 접근합니다."); | ||
} | ||
|
||
@Override | ||
public void hit() { | ||
System.out.println("건곤대나잇~! 일반 공격합니다."); | ||
} | ||
|
||
@Override | ||
public void specialMove() { | ||
double rate = Math.random()*100; | ||
if(rate < 30) System.out.println("허공난무~! 흐미~실패닷"); | ||
else System.out.println("동귀어진! 필살기로 공격합니다."); | ||
} | ||
|
||
@Override | ||
public void showClass() { | ||
System.out.println("<<<<< 제 직업은 전사입니다. >>>>>"); | ||
} | ||
} |