package ex01_๊ฐ์ฒด๋ฐฐ์ด;
public class Pokemon {
// ํฌ์ผ๋ชฌ ์๋ฃํ
// 1. ํ๋
public static final Pokemon pikachu = null;
// ์ด๋ฆ
private String name;
// ํ์
private String type;
// ๊ณต๊ฒฉ๋ ฅ
private int atk;
// ์ฒด๋ ฅ
private int hp;
// ์คํฌ
private String skill;
// 2. ๋ฉ์๋
// ๋ชจ๋ ํ๋๋ฅผ ์ด๊ธฐํ์ํฌ ์ ์๋ ์์ฑ์
public Pokemon(String name, String type, int atk, int hp, String skill) {
this.name = name;
this.type = type;
this.atk = atk;
this.hp = hp;
this.skill = skill;
}
// ๋ชจ๋ ํ๋์ ๋ํ getter, setter ๋ฉ์๋ ์์ฑ
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public int getAtk() {
return atk;
}
public void setAtk(int atk) {
this.atk = atk;
}
public int getHp() {
return hp;
}
public void setHp(int hp) {
this.hp = hp;
}
public String getSkill() {
return skill;
}
public void setSkill(String skill) {
this.skill = skill;
}
}
.
package ex01_๊ฐ์ฒด๋ฐฐ์ด;
import java.util.Scanner;
public class PokemonMain {
// ์คํํ๋ ํ๊ฒฝ
public static void main(String[] args) {
// 1. ๊ฒ์์์ ์ฌ์ฉํ ํฌ์ผ๋ชฌ ๋ ๋ง๋ฆฌ ์์ฑ
Pokemon pairi = new Pokemon("ํ์ด๋ฆฌ", "๋ถ", 300, 1000, "๋ถ๊ฝ์ธ๋ก~!");
Pokemon kkobuk = new Pokemon("๊ผฌ๋ถ๊ธฐ", "๋ฌผ", 350, 2000, "๋ฌผ๋ํฌ~!");
Scanner sc = new Scanner(System.in);
while (pairi.getHp() > 0 && kkobuk.getHp() > 0) {
// 2. ์ฌ์ฉ์๋ก๋ถํฐ ํฌ์ผ๋ชฌ ์ ํํ๊ฒ๋ ๋ง๋ค๊ธฐ
System.out.print("ํฌ์ผ๋ชฌ์ ์ ํํ์ธ์. >> 1.ํ์ด๋ฆฌ 2.๊ผฌ๋ถ๊ธฐ >> ");
int choosePokemon = sc.nextInt();
// 3. ๊ณต๊ฒฉ ํน์ ์คํฌ ๊ณต๊ฒฉ ๋ ์ค ํ๋๋ฅผ ์ ํํ๊ฒ ํ๋ค.
// 4. ์ ํํ ํฌ์ผ๋ชฌ์ด ๋ค๋ฅธ ํฌ์ผ๋ชฌ์ ๊ณต๊ฒฉํ๋ค.
// ๊ณต๊ฒฉ์ ํฌ์ผ๋ชฌ hp - ๊ณต๊ฒฉ๋ ฅ
// ์คํฌ ๊ณต๊ฒฉ ์ ๊ณต๊ฒฉ๋ ฅ์ 1.5๋ฐฐ ์ฆ๊ฐํ๋ค.
if (choosePokemon == 1) {
System.out.print("๊ณต๊ฒฉ ํน์ ์คํฌ ๊ณต๊ฒฉ์ ์ ํํ์ธ์. >> 1.๊ณต๊ฒฉ 2.์คํฌ๊ณต๊ฒฉ >> ");
int attackOrSkill = sc.nextInt();
if (attackOrSkill == 1) {
System.out.println("[ํ์ด๋ฆฌ]๋์ด [๊ผฌ๋ถ๊ธฐ]๋๊ป [์ผ๋ฐ๊ณต๊ฒฉ]์ ์์ ํ์ต๋๋ค.");
int hp = kkobuk.getHp() - pairi.getAtk();
kkobuk.setHp(hp);
System.out.println("[๊ผฌ๋ถ๊ธฐ] hp : " + kkobuk.getHp());
} else {
System.out.println("[ํ์ด๋ฆฌ]๋์ด [๊ผฌ๋ถ๊ธฐ]๋๊ป [์คํฌ๊ณต๊ฒฉ]์ ์์ ํ์ต๋๋ค.");
System.out.println(pairi.getSkill());
int hp = kkobuk.getHp() - (pairi.getAtk()) * 3 / 2;
kkobuk.setHp(hp);
System.out.println("[๊ผฌ๋ถ๊ธฐ] hp : " + kkobuk.getHp());
}
} else {
System.out.print("๊ณต๊ฒฉ ํน์ ์คํฌ ๊ณต๊ฒฉ์ ์ ํํ์ธ์. >> 1.๊ณต๊ฒฉ 2.์คํฌ๊ณต๊ฒฉ >>");
int attackOrSkill = sc.nextInt();
if (attackOrSkill == 1) {
System.out.print("[๊ผฌ๋ถ๊ธฐ]๋์ด [ํ์ด๋ฆฌ]๋๊ป [์ผ๋ฐ๊ณต๊ฒฉ]์ ์์ ํ์ต๋๋ค.");
int hp = pairi.getHp() - kkobuk.getAtk();
pairi.setHp(hp);
System.out.println("[ํ์ด๋ฆฌ] hp : " + pairi.getHp());
} else {
System.out.print("[๊ผฌ๋ถ๊ธฐ]๋์ด [ํ์ด๋ฆฌ]๋๊ป [์คํฌ๊ณต๊ฒฉ]์ ์์ ํ์ต๋๋ค.");
System.out.println(kkobuk.getSkill());
int hp = pairi.getHp() - (kkobuk.getAtk()) * 3 / 2;
pairi.setHp(hp);
System.out.println("[ํ์ด๋ฆฌ] hp : " + pairi.getHp());
}
}
}
if (pairi.getHp() <= 0) {
System.out.println("[๊ผฌ๋ถ๊ธฐ]๋์ ์น๋ฆฌ! ");
}
if (kkobuk.getHp() <= 0) {
System.out.println("[ํ์ด๋ฆฌ]๋์ ์น๋ฆฌ!");
}
// ํ ๋ง๋ฆฌ์ ํฌ์ผ๋ชฌ์ด ์ฃฝ์ ๋๊น์ง ๊ฒ์์ ๋ฐ๋ณตํ๋ค.
}
}