์๋ ํ์ธ์~ ์ฆ๊ฑฐ์ด ์ฃผ๋ง์ ๋๋ค. ์ฃผ๋ง์ด๊ธด ํ๋ฐ ์ผ์์ผ์ด๋ค์ ๋ฒ์จ ใ ใ
์ฃผ๋ง์ ๋๋ฌด ํ ๊ฐ๋ ๊ฒ ๊ฐ์์ ๋ ์์ฌ์์.
์ค๋์ ์ ๋ฒ์ ๋ง๋ค์๋ ํฌ์ผ๋ชฌ ๊ฒ์(?)์ ์กฐ๊ธ ์์ ํ์ฌ ๊ฐ์ ธ์์ต๋๋ค.
๋ฉํฐ์ค๋ ๋๋ฅผ ์ด์ฉํ์ฌ [ํผ์นด์ธ + ๊ผฌ๋ถ๊ธฐ VS ํฌํ ] ์ ๋ง๋ค์์ต๋๋ค.
์ง์ง ์์ฑ๋๊ฐ ๋ง์์ ์๋ค์ด์ ์ฌ๋ฆด๊น ๋ง๊น ๊ณ ๋ฏผํ๋๋ฐ
๊ทธ๋๋ ์ด๊ฒ ๋ํ ํ๋์ ๊ณผ์ ์ด๋ผ๊ณ ์๊ฐํด์ ์ฌ๋ ค๋ด ๋๋น..๐คฃ
abstract public class Unit {
protected String name;
protected int hp;
protected int power;
protected double pHit;
protected int specialPower;
protected boolean isDead;
}
public interface Action {
int pAttack();
int specialPower();
boolean setDamage(double damage);
}
public class Pokemon extends Unit implements Action {
public Pokemon(String name, int hp, int p, double pHit, int specialP, boolean isDead) {
this.name = name;
this.hp = hp;
this.power = p;
this.pHit = pHit;
this.specialPower = specialP;
this.isDead = isDead;
}
public int pAttack() {
return (int)(power * pHit);
}
public int specialPower() {
return specialPower;
}
public boolean setDamage(double damage) {
if(hp > damage) {
hp -= damage;
System.out.println("[" + name + "] ํ์ฌ ์ฒด๋ ฅ : " + hp);
return false;
} else {
System.err.println("[" + name + "] DEAD!!");
return true;
}
}
}
public class GameThread1 extends Thread{
private Pokemon pikachu;
private Pokemon squirtle;
private Pokemon pantom;
public GameThread1(Pokemon pikachu, Pokemon squirtle, Pokemon pantom) {
this.pikachu = pikachu;
this.squirtle = squirtle;
this.pantom = pantom;
}
@Override
public void run() {
int normal = (int)(Math.random() * 2);
int special = (int)(Math.random() * 10);
while(pikachu.isDead == false) {
try {
sleep(2000);
if(normal == 0) {
System.out.println("## [" + pikachu.name + "] [๊ณต๊ฒฉ] ์ฑ๊ณต!! ## " + pikachu.pAttack() + " ๋ฐ๋ฏธ์ง๋ฅผ ์
ํ์ต๋๋ค.");
pantom.isDead = pantom.setDamage(pikachu.pAttack());
}
if(special == 1) {
System.out.println("## [" + pikachu.name + "] [ํ์ด๊ธฐ] ๋ฐ๋!! ## " + pikachu.specialPower() + " ๋ฐ๋ฏธ์ง๋ฅผ ์
ํ์ต๋๋ค.");
pantom.isDead = pantom.setDamage(pikachu.specialPower());
}
if(pantom.isDead) System.exit(0);
} catch (InterruptedException e) {}
}
}
}
public class GameThread2 extends Thread {
private Pokemon pikachu;
private Pokemon squirtle;
private Pokemon pantom;
public GameThread2(Pokemon pikachu, Pokemon squirtle, Pokemon pantom) {
this.pikachu = pikachu;
this.squirtle = squirtle;
this.pantom = pantom;
}
@Override
public void run() {
int normal = (int)(Math.random() * 2);
int special = (int)(Math.random() * 10);
while(squirtle.isDead == false) {
try {
sleep(2000);
if(normal == 0) {
System.out.println("## [" + squirtle.name + "] [๊ณต๊ฒฉ] ์ฑ๊ณต!! ## " + squirtle.pAttack() + " ๋ฐ๋ฏธ์ง๋ฅผ ์
ํ์ต๋๋ค.");
pantom.isDead = pantom.setDamage(squirtle.pAttack());
}
if(special == 2) {
System.out.println("## [" + squirtle.name + "] [ํ์ด๊ธฐ] ๋ฐ๋!! ## " + squirtle.specialPower() + " ๋ฐ๋ฏธ์ง๋ฅผ ์
ํ์ต๋๋ค.");
pantom.isDead = pantom.setDamage(squirtle.specialPower());
}
if(pantom.isDead) System.exit(0);
} catch (InterruptedException e) {}
}
}
}
public class GameThread3 extends Thread {
private Pokemon pikachu;
private Pokemon squirtle;
private Pokemon pantom;
public GameThread3(Pokemon pikachu, Pokemon squirtle, Pokemon pantom) {
this.pikachu = pikachu;
this.squirtle = squirtle;
this.pantom = pantom;
}
@Override
public void run() {
int normal;
int special;
while(true) {
try {
sleep(2000);
normal = (int)(Math.random() * 2);
special = (int)(Math.random() * 20);
if(normal == 0) {
if(pikachu.isDead == true) {
System.out.println("## [" + pantom.name + "] [๊ณต๊ฒฉ] ์ฑ๊ณต!! ## " + squirtle.name + "์๊ฒ " + pantom.pAttack() + " ๋ฐ๋ฏธ์ง๋ฅผ ์
ํ์ต๋๋ค.");
squirtle.isDead = squirtle.setDamage(pantom.pAttack());
} else {
System.out.println("## [" + pantom.name + "] [๊ณต๊ฒฉ] ์ฑ๊ณต!! ## " + pikachu.name + "์๊ฒ " + pantom.pAttack() + " ๋ฐ๋ฏธ์ง๋ฅผ ์
ํ์ต๋๋ค.");
pikachu.isDead = pikachu.setDamage(pantom.pAttack());
}
}
if(normal == 1) {
if(squirtle.isDead == true) {
System.out.println("## [" + pantom.name + "] [๊ณต๊ฒฉ] ์ฑ๊ณต!! ## " + pikachu.name + "์๊ฒ " + pantom.pAttack() + " ๋ฐ๋ฏธ์ง๋ฅผ ์
ํ์ต๋๋ค.");
pikachu.isDead = pikachu.setDamage(pantom.pAttack());
}
else {
System.out.println("## [" + pantom.name + "] [๊ณต๊ฒฉ] ์ฑ๊ณต!! ## " + squirtle.name + "์๊ฒ " + pantom.pAttack() + " ๋ฐ๋ฏธ์ง๋ฅผ ์
ํ์ต๋๋ค.");
squirtle.isDead = squirtle.setDamage(pantom.pAttack());
}
}
if(special == 1) {
if(pikachu.isDead == true) {
System.out.println("## [" + pantom.name + "] [ํ์ด๊ธฐ] ๋ฐ๋!! ## " + squirtle.name + "์๊ฒ " + pantom.specialPower() + " ๋ฐ๋ฏธ์ง๋ฅผ ์
ํ์ต๋๋ค.");
squirtle.isDead = squirtle.setDamage(pantom.specialPower());
} else {
System.out.println("## [" + pantom.name + "] [ํ์ด๊ธฐ] ๋ฐ๋!! ## " + pikachu.name + "์๊ฒ " + pantom.specialPower() + " ๋ฐ๋ฏธ์ง๋ฅผ ์
ํ์ต๋๋ค.");
pikachu.isDead = pikachu.setDamage(pantom.specialPower());
}
}
if(special == 2) {
if(squirtle.isDead == true) {
System.out.println("## [" + pantom.name + "] [ํ์ด๊ธฐ] ๋ฐ๋!! ## " + pikachu.name + "์๊ฒ " + pantom.specialPower() + " ๋ฐ๋ฏธ์ง๋ฅผ ์
ํ์ต๋๋ค.");
pikachu.isDead = pikachu.setDamage(pantom.specialPower());
} else {
System.out.println("## [" + pantom.name + "] [ํ์ด๊ธฐ] ๋ฐ๋!! ## " + squirtle.name + "์๊ฒ " + pantom.specialPower() + " ๋ฐ๋ฏธ์ง๋ฅผ ์
ํ์ต๋๋ค.");
squirtle.isDead = squirtle.setDamage(pantom.specialPower());
}
}
if(pikachu.isDead && squirtle.isDead) System.exit(0);
} catch (InterruptedException e) {}
}
}
}
์ฝ๋๋ฅผ ์ ๋ฆฌํ ์ ์์ ๊ฒ ๊ฐ์๋ฐ.. ๋ญ๊ฐ ์์ฌ์์.
public class Main {
public static void main(String[] args) throws InterruptedException {
Pokemon pikachu = new Pokemon("ํผ์นด์ธ",120,15,0.7,22,false);
Pokemon squirtle = new Pokemon("๊ผฌ๋ถ๊ธฐ",100,8,0.6,18,false);
Pokemon pantom = new Pokemon("ํฌํ
", 180, 22, 0.6, 50,false);
GameThread1 gameThread1 = new GameThread1(pikachu, squirtle, pantom);
GameThread2 gameThread2 = new GameThread2(pikachu, squirtle, pantom);
GameThread3 gameThread3 = new GameThread3(pikachu, squirtle, pantom);
gameThread1.start();
gameThread2.start();
gameThread3.start();
System.out.println(pikachu.name + " & " + squirtle.name + " VS " + pantom.name);
}
}
์คํํ๋ฉด ์๊พธ ์ฃฝ์๋๋ฐ๋ ๋ฑ์ฅํด์ ์ค๋ฅ๊ฐ ๋ง์ต๋๋ค...ใ ใ