Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions game/src/main/java/com/survivalcoding/Diagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
@startuml

class Hero {
- String name
- int hp
- int maxHp
+ getName() : String
+ setName(String) : void
+ getHp() : int
+ setHp(int) : void
+ getMaxHp() : int
+ setMaxHp(int) : void
}

class Cleric {
+ int mp
+ heal(Hero) : void
}
Comment on lines +15 to +18

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Cleric 클래스의 실제 구현에서 mp 필드 가시성과 접근자 확인
rg -A 10 'class Cleric' game/src/main/java/com/survivalcoding/

Repository: SurvivalCodingCampus/polytech_java2

Length of output: 1602


🏁 Script executed:

#!/bin/bash
# Read full Cleric.java to see complete field declarations
cat -n game/src/main/java/com/survivalcoding/Cleric.java | head -30

echo "---"
# Also check Hero.java and Wizard.java for comparison
echo "=== Hero.java fields ==="
rg -A 5 'public class Hero' game/src/main/java/com/survivalcoding/Hero.java | head -20

echo "=== Wizard.java fields ==="
rg -A 10 'public class Wizard' game/src/main/java/com/survivalcoding/Wizard.java | head -20

Repository: SurvivalCodingCampus/polytech_java2

Length of output: 1290


Cleric 필드 가시성 및 캡슐화 패턴 불일치 수정 필요.

다이어그램(Line 16)에서 + int mp로 표시되어 있으나, 실제 Cleric.java 구현에서는 default access(제한자 없음)로 선언되어 있습니다. 더 중요하게는, Hero와 Wizard 클래스는 private 필드와 getter/setter 메서드를 통해 캡슐화를 구현하고 있으므로, Cleric도 이 패턴을 따르도록 수정해야 합니다. 다이어그램의 mp, hp, name을 모두 private(-)로 변경하고, 해당 접근자 메서드를 추가하거나 기존 구현과 동기화하세요.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@game/src/main/java/com/survivalcoding/Diagram.puml` around lines 15 - 18, The
Cleric class diagram shows mp field with public visibility (+), but this does
not match the encapsulation pattern used by Hero and Wizard classes which use
private fields with accessor methods. Update the Cleric class in the diagram by
changing mp, hp, and name field visibility from public (+) to private (-), and
add the corresponding getter and setter methods to align with the encapsulation
pattern demonstrated in Hero and Wizard classes. Ensure all three fields (mp,
hp, name) follow consistent private visibility notation in the diagram.


class Wizard {
- int hp
- int mp
- String name
- Wand wand
+ getHp() : int
+ setHp(int) : void
+ getMp() : int
+ setMp(int) : void
+ getName() : String
+ setName(String) : void
+ getWand() : Wand
+ setWand(Wand) : void
+ heal(Hero) : void
}

class GreatWizard {
+ heal(Hero) : void
+ superHeal(Hero) : void
}

class Wand {
- String name
- double power
+ getName() : String
+ setName(String) : void
+ getPower() : double
+ setPower(double) : void
}

class Slime {
+ String suffix
+ int hp
+ attack(Hero) : void
}
Comment on lines +50 to +54

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Slime 클래스의 실제 구현에서 suffix, hp 필드 가시성 확인
rg -A 15 'class Slime' game/src/main/java/com/survivalcoding/Slime.java

Repository: SurvivalCodingCampus/polytech_java2

Length of output: 388


Slime 클래스 필드 가시성이 다이어그램과 일치하지 않음.

Diagram.puml의 51-52줄에서 suffix와 hp가 + (public)으로 표기되어 있으나, 실제 Slime.java 구현에서는 가시성 지정자가 없는 package-private 필드입니다. 다이어그램을 실제 구현(String suffix;, int hp;)과 일치하도록 수정하세요.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@game/src/main/java/com/survivalcoding/Diagram.puml` around lines 50 - 54, The
Slime class fields in Diagram.puml are marked with `+` (public visibility) on
lines 51-52 for suffix and hp, but the actual Slime.java implementation defines
these as package-private fields with no visibility modifier. Update the diagram
to match the implementation by changing the `+` prefix to `~` (package-private
notation in UML) for both the suffix and hp fields in the Slime class
definition.


class PoisonSlime {
- int poisonCount
+ attack(Hero) : void
}

' 상속 관계
Hero <|-- Cleric
Wizard <|-- GreatWizard
Slime <|-- PoisonSlime

' 연관 관계
Wizard --> Wand : has
PoisonSlime ..> Hero : attacks
Slime ..> Hero : attacks
Cleric ..> Hero : heals
Wizard ..> Hero : heals
GreatWizard ..> Hero : superHeals

@enduml
29 changes: 29 additions & 0 deletions game/src/main/java/com/survivalcoding/GreatWizard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.survivalcoding;

public class GreatWizard extends Wizard {

public GreatWizard() {
setMp(150);
}

@Override
void heal(Hero hero) {
if (getMp() < 5) {
System.out.println("Not enough MP");
return;
}
hero.setHp(hero.getHp() + 25);
setMp(getMp() - 5);
System.out.println("Cast heal. Character HP: " + hero.getHp());
}

void superHeal(Hero hero) {
if (getMp() < 50) {
System.out.println("Not enough MP");
return;
}
hero.setHp(hero.getMaxHp()); // hp를 최대로
setMp(getMp() - 50);
System.out.println("Cast super heal. Character HP: " + hero.getHp());
}
}
11 changes: 10 additions & 1 deletion game/src/main/java/com/survivalcoding/Hero.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public class Hero {
private String name;
private int hp;
private int maxHp = 100;

public String getName() {
return name;
Expand All @@ -19,4 +20,12 @@ public int getHp() {
public void setHp(int hp) {
this.hp = hp;
}
}

public int getMaxHp() {
return maxHp;
}

public void setMaxHp(int maxHp) {
this.maxHp = maxHp;
}
Comment on lines +24 to +30

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

hp/maxHp 상태 불변식이 보장되지 않습니다.

setMaxHp가 유효성(음수/0)과 현재 hp 보정을 처리하지 않아 hp > maxHp 같은 모순 상태가 생길 수 있습니다. 치유 로직이 여러 클래스로 확장된 만큼 Hero에서 상한/하한을 강제해야 합니다.

제안 수정안
 public void setHp(int hp) {
-    this.hp = hp;
+    if (hp < 0) {
+        hp = 0;
+    }
+    if (hp > this.maxHp) {
+        hp = this.maxHp;
+    }
+    this.hp = hp;
 }
 
 public void setMaxHp(int maxHp) {
-    this.maxHp = maxHp;
+    if (maxHp < 0) {
+        throw new IllegalArgumentException("maxHp must be over 0.");
+    }
+    this.maxHp = maxHp;
+    if (this.hp > maxHp) {
+        this.hp = maxHp;
+    }
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@game/src/main/java/com/survivalcoding/Hero.java` around lines 24 - 30, The
setMaxHp method in the Hero class does not enforce the invariant that hp should
never exceed maxHp, and it does not validate that maxHp is a positive value.
Modify the setMaxHp method to first validate that the input value is greater
than zero, then adjust the current hp if it exceeds the new maxHp (by clamping
hp to the new maximum). This ensures the state invariant hp <= maxHp is always
maintained and prevents invalid states where hp exceeds maxHp.

}
25 changes: 25 additions & 0 deletions game/src/main/java/com/survivalcoding/PoisonSlime.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.survivalcoding;

public class PoisonSlime extends Slime {
private int poisonCount = 5;

public PoisonSlime(String suffix) {
super(suffix);
this.suffix = suffix;
}
Comment on lines +6 to +9

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

생성자에서 중복 할당 제거 필요

Line 8에서 this.suffix = suffix를 할당하고 있지만, Line 7의 super(suffix)가 이미 부모 클래스의 생성자에서 suffix를 설정합니다. 이 할당은 불필요하며 제거해야 합니다.

🐛 제안된 수정
     public PoisonSlime(String suffix) {
         super(suffix);
-        this.suffix = suffix;
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@game/src/main/java/com/survivalcoding/PoisonSlime.java` around lines 6 - 9,
The PoisonSlime constructor is performing a redundant assignment of the suffix
field. The super(suffix) call on line 7 already initializes the suffix field
through the parent class constructor, making the this.suffix = suffix assignment
on line 8 unnecessary. Remove the duplicate assignment statement to eliminate
the redundant code and keep only the super() call in the PoisonSlime
constructor.


@Override
void attack(Hero hero) {
super.attack(hero);

if (poisonCount != 0) {
System.out.println("Poison attack!");

int poisonDamage = hero.getHp() / 5;
hero.setHp(hero.getHp() - poisonDamage);
System.out.println(poisonDamage + "point damage");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

출력 문자열의 띄어쓰기 누락

poisonDamage"point damage" 사이에 공백이 없어 "10point damage" 대신 올바른 형식으로 출력되지 않습니다.

🐛 제안된 수정
-            System.out.println(poisonDamage + "point damage");
+            System.out.println(poisonDamage + " point damage");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
System.out.println(poisonDamage + "point damage");
System.out.println(poisonDamage + " point damage");
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@game/src/main/java/com/survivalcoding/PoisonSlime.java` at line 20, The
System.out.println statement in PoisonSlime.java is missing a space between the
poisonDamage variable and the string literal "point damage". Add a space at the
beginning of the string literal so that the output displays properly (e.g., "10
point damage" instead of "10point damage").


poisonCount--;
}
}
}
15 changes: 15 additions & 0 deletions game/src/main/java/com/survivalcoding/Question0102.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.survivalcoding;

// 01
// 1. student is person (o)
// 2. Engine is car (x)
// 3. Child is father (x)
// 4. Sushi is Food (o)
// 5. Man is SuperMan (x)


// 02
// 1. i_phone17 --|> Phone --|> Device
// 2. Avante --|> Car --|> Vehicle
// 3. En/Kr Dictionary --|> Dictionary --|> Book

19 changes: 19 additions & 0 deletions game/src/main/java/com/survivalcoding/Slime.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.survivalcoding;

public class Slime {
String suffix;
int hp;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

사용되지 않는 필드 제거 또는 초기화 필요

hp 필드가 선언되었지만 생성자에서 초기화되지 않고 어떤 메서드에서도 사용되지 않습니다. 필드가 필요하다면 생성자에서 초기화하고 사용하거나, 불필요하다면 제거해야 합니다.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@game/src/main/java/com/survivalcoding/Slime.java` at line 5, The `hp` field
in the Slime class is declared but never initialized in the constructor and is
not used anywhere in the class methods. Either remove the unused `hp` field
entirely if it is not needed, or if the field should be part of the Slime class
functionality, initialize it in the Slime constructor with an appropriate
default value and ensure it is actually used in relevant methods.


public Slime(String suffix) {
this.suffix = suffix;
}


void attack(Hero hero) {
System.out.println("Slime " + suffix + "attacked");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

출력 문자열의 띄어쓰기 누락

suffix"attacked" 사이에 공백이 없어 "Slime A attacked" 대신 "Slime Aattacked"로 출력됩니다.

🐛 제안된 수정
-        System.out.println("Slime " + suffix + "attacked");
+        System.out.println("Slime " + suffix + " attacked");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
System.out.println("Slime " + suffix + "attacked");
System.out.println("Slime " + suffix + " attacked");
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@game/src/main/java/com/survivalcoding/Slime.java` at line 13, The
System.out.println statement in the Slime class is missing a space between the
suffix variable and the "attacked" string literal, causing output like "Slime
Aattacked" instead of "Slime A attacked". Add a space before "attacked" in the
concatenated string to fix the formatting issue.

System.out.println("10 point damage");

hero.setHp(hero.getHp() - 10);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Hero HP가 음수가 될 수 있는 공통 경계 조건 미검증

두 파일 모두에서 Hero의 HP를 감소시킬 때 하한선(0) 검증이 없어 HP가 음수가 될 수 있습니다. 이는 게임 상태의 무결성을 해칠 수 있으므로 모든 데미지 적용 지점에서 HP를 최소 0으로 제한해야 합니다.

  • game/src/main/java/com/survivalcoding/Slime.java#L16-L16: 기본 공격 데미지(10) 적용 시 Math.max(0, newHp) 추가
  • game/src/main/java/com/survivalcoding/PoisonSlime.java#L19-L19: 독 데미지 적용 시 Math.max(0, newHp) 추가
📍 Affects 2 files
  • game/src/main/java/com/survivalcoding/Slime.java#L16-L16 (this comment)
  • game/src/main/java/com/survivalcoding/PoisonSlime.java#L19-L19
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@game/src/main/java/com/survivalcoding/Slime.java` at line 16, The Hero's HP
can become negative when damage is applied, compromising game state integrity.
In game/src/main/java/com/survivalcoding/Slime.java at line 16, modify the
damage calculation in the basic attack (10 damage) by storing the new HP in a
variable and use Math.max(0, newHp) before setting it on the hero to ensure HP
never goes below zero. Apply the same fix in
game/src/main/java/com/survivalcoding/PoisonSlime.java at line 19 for the poison
damage application, using Math.max(0, newHp) to prevent HP from becoming
negative when poison damage is applied.

}
}

15 changes: 9 additions & 6 deletions game/src/main/java/com/survivalcoding/Wizard.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class Wizard {
private int hp;
private int mp;
private int mp = 100; // 초기값 100 추가
private String name;
private Wand wand;

Expand Down Expand Up @@ -51,9 +51,12 @@ public void setWand(Wand wand) {
}

void heal(Hero hero) {
int basePoint = 10;
int recovPoint = (int) (basePoint * this.wand.getPower());
hero.setHp(hero.getHp() + recovPoint);
if (mp < 10) {
System.out.println("Not enough MP");
return;
}
hero.setHp(hero.getHp() + 20);
mp -= 10;
System.out.println("Cast heal. Character HP: " + hero.getHp());
}

}
}
15 changes: 15 additions & 0 deletions game/src/test/java/com/survivalcoding/WizardTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,19 @@ void setWand_normal() {

assertEquals(wand, wizard.getWand());
}

@Test
@DisplayName("heal prints mana insufficient message when mp is under 10")
void heal_prints_insufficient_message_when_mp_under_10() {

Wizard wizard = new Wizard();
wizard.setMp(5);
Hero hero = new Hero();
hero.setHp(50);

wizard.heal(hero);

assertEquals(50, hero.getHp()); // hp 변화 없음
assertEquals(5, wizard.getMp()); // mp 변화 없음
}
Comment on lines +81 to +93

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

테스트 이름/설명과 실제 검증이 불일치합니다.

현재 테스트는 출력 메시지가 아니라 HP/MP 상태만 검증합니다. DisplayName을 상태 검증 중심으로 바꾸거나, 실제로 stdout 캡처 assertion을 추가해 테스트 의도를 맞춰주세요.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@game/src/test/java/com/survivalcoding/WizardTest.java` around lines 81 - 93,
The test method heal_prints_insufficient_message_when_mp_under_10 has a
DisplayName that indicates it verifies a message is printed, but the actual test
only checks that HP and MP remain unchanged without capturing or asserting any
output. Either update the `@DisplayName` annotation to accurately describe what
the test actually verifies (state preservation when MP is insufficient) or add
stdout capture and assertion to verify that the mana insufficient message is
actually printed to match the test's declared intent.

}