π My Project
μλ°(Java) - κ°μΈ λ―Έλ νλ‘μ νΈ 3 (ν¬μΌλͺ¬ κ²μ) v2 - λ©ν° μ€λ λλ₯Ό μ΄μ©ν μ€μκ° μ ν¬ κ΅¬ν
kongmi
2023. 2. 12. 09:38
μλ νμΈμ~ μ¦κ±°μ΄ μ£Όλ§μ λλ€. μ£Όλ§μ΄κΈ΄ νλ° μΌμμΌμ΄λ€μ λ²μ¨ γ γ
μ£Όλ§μ λ무 ν κ°λ κ² κ°μμ λ μμ¬μμ.
μ€λμ μ λ²μ λ§λ€μλ ν¬μΌλͺ¬ κ²μ(?)μ μ‘°κΈ μμ νμ¬ κ°μ Έμμ΅λλ€.
λ©ν°μ€λ λλ₯Ό μ΄μ©νμ¬ [νΌμΉ΄μΈ + κΌ¬λΆκΈ° 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);
}
}
μ€ννλ©΄ μκΎΈ μ£½μλλ°λ λ±μ₯ν΄μ μ€λ₯κ° λ§μ΅λλ€...γ γ