Repository navigation
Expand file tree
/
Copy pathStage.java
More file actions
57 lines (47 loc) · 2.11 KB
/
Copy pathStage.java
File metadata and controls
57 lines (47 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.util.Scanner;
// monsters.txt 한 줄: 주제|스테이지번호|보스이름|HP비율(%)|이미지경로
public class Stage implements Manageable {
String topic;
int stageNo;
String bossName;
int hpPercent; // 문제 수 대비 보스 HP 비율 (예: 50 → 문제 10개면 HP 5)
String imagePath; // 보스 이미지 파일 경로
public Stage() {}
public Stage(String topic, int stageNo, String bossName, int hpPercent, String imagePath) {
this.topic = topic;
this.stageNo = stageNo;
this.bossName = bossName;
this.hpPercent = hpPercent;
this.imagePath = imagePath;
}
@Override
public void read(Scanner scan) {
topic = scan.next().trim();
stageNo = Integer.parseInt(scan.next().trim());
bossName = scan.next().trim();
hpPercent = Integer.parseInt(scan.next().trim());
if (hpPercent <= 0 || hpPercent > 100) throw new IllegalArgumentException("HP비율은 1~100");
// 경로 칸이 없을 경우를 대비해 hasNext()로 있을 때만 안전하게 읽음
imagePath = scan.hasNext() ? scan.next().trim() : null;
}
@Override
public void print() {
System.out.printf("[%s %d] %s HP %d%%%n", topic, stageNo, bossName, hpPercent);
}
@Override
public boolean matches(String kwd) {
return topic.equalsIgnoreCase(kwd) || bossName.contains(kwd);
}
public boolean is(String topic, int stageNo) {
return this.topic.equalsIgnoreCase(topic) && this.stageNo == stageNo;
}
public String getTopic() { return topic; }
public int getStageNo() { return stageNo; }
public String getBossName() { return bossName; }
public int getHpPercent() { return hpPercent; }
public String getImagePath() { return imagePath; } // 이미지 경로 반환 메서드 추가
// 보스 HP = 문제 수 × 비율 (반올림, 최소 1). 공격 횟수는 문제 수이므로 (문제 수 - HP)번까지 틀려도 됨
public int getBossHp(int questionCount) {
return Math.max(1, (int) Math.round(questionCount * hpPercent / 100.0));
}
}