GiantStepDEV

์•ˆ๋…•ํ•˜์„ธ์š”~ ์ฆ๊ฑฐ์šด ์ฃผ๋ง์ž…๋‹ˆ๋‹ค. ์ฃผ๋ง์ด๊ธด ํ•œ๋ฐ ์ผ์š”์ผ์ด๋„ค์š” ๋ฒŒ์จ ใ…œใ…œ

์ฃผ๋ง์€ ๋„ˆ๋ฌด ํ›… ๊ฐ€๋Š” ๊ฒƒ ๊ฐ™์•„์„œ ๋Š˜ ์•„์‰ฌ์›Œ์š”.

 

์˜ค๋Š˜์€ ์ €๋ฒˆ์— ๋งŒ๋“ค์—ˆ๋˜ ํฌ์ผ“๋ชฌ ๊ฒŒ์ž„(?)์„ ์กฐ๊ธˆ ์ˆ˜์ •ํ•˜์—ฌ ๊ฐ€์ ธ์™”์Šต๋‹ˆ๋‹ค.

๋ฉ€ํ‹ฐ์Šค๋ ˆ๋“œ๋ฅผ ์ด์šฉํ•˜์—ฌ [ํ”ผ์นด์ธ„ + ๊ผฌ๋ถ€๊ธฐ 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);
    }
}

์‹คํ–‰ํ•˜๋ฉด ์ž๊พธ ์ฃฝ์—ˆ๋Š”๋ฐ๋„ ๋“ฑ์žฅํ•ด์„œ ์˜ค๋ฅ˜๊ฐ€ ๋งŽ์Šต๋‹ˆ๋‹ค...ใ…œใ…œ

profile

GiantStepDEV

@kongmi

ํฌ์ŠคํŒ…์ด ์ข‹์•˜๋‹ค๋ฉด "์ข‹์•„์š”โค๏ธ" ๋˜๋Š” "๊ตฌ๋…๐Ÿ‘๐Ÿป" ํ•ด์ฃผ์„ธ์š”!