πŸ“‚ 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);
    }
}

μ‹€ν–‰ν•˜λ©΄ 자꾸 μ£½μ—ˆλŠ”λ°λ„ λ“±μž₯ν•΄μ„œ 였λ₯˜κ°€ λ§ŽμŠ΅λ‹ˆλ‹€...γ…œγ…œ