From 189ad9c0496ee8d6fb0946503a39c9bdd82e325d Mon Sep 17 00:00:00 2001 From: "Sunjin.Kim" Date: Tue, 16 Jun 2026 11:24:24 +0900 Subject: [PATCH 01/20] =?UTF-8?q?=EC=9D=B4=EB=A6=84=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../260615_\354\227\260\354\212\265\353\254\270\354\240\2341" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "game2/src/main/java/com/survivalcoding/\354\227\260\354\212\265\353\254\270\354\240\2341" => "game2/src/main/java/com/survivalcoding/260615_\354\227\260\354\212\265\353\254\270\354\240\2341" (100%) diff --git "a/game2/src/main/java/com/survivalcoding/\354\227\260\354\212\265\353\254\270\354\240\2341" "b/game2/src/main/java/com/survivalcoding/260615_\354\227\260\354\212\265\353\254\270\354\240\2341" similarity index 100% rename from "game2/src/main/java/com/survivalcoding/\354\227\260\354\212\265\353\254\270\354\240\2341" rename to "game2/src/main/java/com/survivalcoding/260615_\354\227\260\354\212\265\353\254\270\354\240\2341" From ec2d35dc049a9ea1736d3d4a6a90255f2f396bd6 Mon Sep 17 00:00:00 2001 From: "Sunjin.Kim" Date: Tue, 16 Jun 2026 11:24:32 +0900 Subject: [PATCH 02/20] =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/survivalcoding/ListExam.java | 37 ------------------- 1 file changed, 37 deletions(-) delete mode 100644 game2/src/main/java/com/survivalcoding/ListExam.java diff --git a/game2/src/main/java/com/survivalcoding/ListExam.java b/game2/src/main/java/com/survivalcoding/ListExam.java deleted file mode 100644 index 14ccca6..0000000 --- a/game2/src/main/java/com/survivalcoding/ListExam.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.survivalcoding; - -import java.util.ArrayList; -import java.util.HashSet; - -public class ListExam { - public static void main(String[] args) { - Hero hero1 = new Hero(); - Hero hero2 = new Hero(); - Hero hero3 = new Hero(); - - ArrayList heroes = new ArrayList<>(); - heroes.add(hero1); - heroes.add(hero2); - heroes.add(hero3); - - System.out.println(heroes.size()); - System.out.println(hero1.getName()); - System.out.println(heroes.get(0).getName()); - - ArrayList numbers = new ArrayList<>(); - numbers.add(1); - numbers.add(1); - numbers.add(1); - - - System.out.println(numbers); - System.out.println(numbers.contains(1)); - HashSet numberSet = new HashSet<>(); - numbers.add(1); - numbers.add(1); - numbers.add(1); - System.out.println(numberSet); - System.out.println(numberSet.contains(2)); - - } -} From 95cc5e23f283ebea6ede4e56c64db71c2d406cca Mon Sep 17 00:00:00 2001 From: "Sunjin.Kim" Date: Tue, 16 Jun 2026 11:24:45 +0900 Subject: [PATCH 03/20] =?UTF-8?q?=EB=AC=B8=EC=9E=A5=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game2/src/main/java/com/survivalcoding/Wizard.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game2/src/main/java/com/survivalcoding/Wizard.java b/game2/src/main/java/com/survivalcoding/Wizard.java index bf72d04..adc4bf0 100644 --- a/game2/src/main/java/com/survivalcoding/Wizard.java +++ b/game2/src/main/java/com/survivalcoding/Wizard.java @@ -37,7 +37,7 @@ public void setName(String name) { throw new IllegalArgumentException("이름은 null이 아니어야 함"); } if (name.length() < 3) { - throw new IllegalArgumentException("이름이 3단어 이상이여야 함"); + throw new IllegalArgumentException("이름이 3문장 이상이여야 함"); } From 3bc0b351235846d065204f6f1b5981fa8aff19ca Mon Sep 17 00:00:00 2001 From: "Sunjin.Kim" Date: Tue, 16 Jun 2026 11:24:56 +0900 Subject: [PATCH 04/20] =?UTF-8?q?=EB=82=98=EC=9D=B4=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game2/src/main/java/com/survivalcoding/Person.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game2/src/main/java/com/survivalcoding/Person.java b/game2/src/main/java/com/survivalcoding/Person.java index 84b1be2..7d7df57 100644 --- a/game2/src/main/java/com/survivalcoding/Person.java +++ b/game2/src/main/java/com/survivalcoding/Person.java @@ -1,7 +1,7 @@ package com.survivalcoding; public class Person { - final int age; + int age; private String name; private int birthYear; From 2263fc3d0e2969c678da637371db819d40ab7116 Mon Sep 17 00:00:00 2001 From: "Sunjin.Kim" Date: Tue, 16 Jun 2026 11:25:11 +0900 Subject: [PATCH 05/20] =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/com/survivalcoding/HeroTest.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/game2/src/test/java/com/survivalcoding/HeroTest.java b/game2/src/test/java/com/survivalcoding/HeroTest.java index ad4f24c..78cd18c 100644 --- a/game2/src/test/java/com/survivalcoding/HeroTest.java +++ b/game2/src/test/java/com/survivalcoding/HeroTest.java @@ -1,22 +1,4 @@ package com.survivalcoding; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - class HeroTest { - - @Test - @DisplayName("공격하면 내 hp가 줄어든다") - void attack() { - Hero hero = new Hero(); - - hero.getHp(); - hero.attack(); - hero.attack(); - - assertEquals(8, hero.getHp()); - } - } \ No newline at end of file From a81f00f7f0701535674689af14bebf9b3e12e45d Mon Sep 17 00:00:00 2001 From: "Sunjin.Kim" Date: Tue, 16 Jun 2026 11:25:19 +0900 Subject: [PATCH 06/20] =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...20\355\231\224, \354\273\254\353\240\211\354\205\230.md" | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git "a/TIL/2026-06-10-\354\272\241\354\212\220\355\231\224, \354\273\254\353\240\211\354\205\230.md" "b/TIL/2026-06-10-\354\272\241\354\212\220\355\231\224, \354\273\254\353\240\211\354\205\230.md" index 95a1468..e5bfbfc 100644 --- "a/TIL/2026-06-10-\354\272\241\354\212\220\355\231\224, \354\273\254\353\240\211\354\205\230.md" +++ "b/TIL/2026-06-10-\354\272\241\354\212\220\355\231\224, \354\273\254\353\240\211\354\205\230.md" @@ -35,9 +35,9 @@ public class ListExam { System.out.println(numbers); System.out.println(numbers.contains(1)); HashSet numberSet = new HashSet<>(); - numbers.add(1); - numbers.add(1); - numbers.add(1); + numberSet.add(1); + numberSet.add(1); + numberSet.add(1); System.out.println(numberSet); System.out.println(numberSet.contains(2)); From 4e20d4276af9e54e70841229651343b6fdd3de2b Mon Sep 17 00:00:00 2001 From: "Sunjin.Kim" Date: Tue, 16 Jun 2026 15:06:35 +0900 Subject: [PATCH 07/20] =?UTF-8?q?=EC=97=B0=EC=8A=B5=EB=AC=B8=EC=A0=9C4=20?= =?UTF-8?q?=EB=A7=88=EB=B2=95=EC=82=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/survivalcoding/Wizard.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/game2/src/main/java/com/survivalcoding/Wizard.java b/game2/src/main/java/com/survivalcoding/Wizard.java index adc4bf0..63d20bf 100644 --- a/game2/src/main/java/com/survivalcoding/Wizard.java +++ b/game2/src/main/java/com/survivalcoding/Wizard.java @@ -2,10 +2,11 @@ public class Wizard { private int hp; - private int mp; + private int mp = 100; private String name; private Wand wand; + public int getHp() { return hp; } @@ -55,9 +56,20 @@ public void setWand(Wand wand) { this.wand = wand; } + void heal(Hero hero) { - int basePoint = 10; - int recovPoint = (int) (basePoint * this.wand.getPower()); - hero.setHp(hero.getHp() + recovPoint); + + + int basePoint = 20; + int baseMp = 10; + + if (this.getMp() < 10) { + System.out.println("마나가 부족합니다"); + } else { + hero.setHp(hero.getHp() + basePoint); + this.setMp(this.getMp() - baseMp); + System.out.println("힐을 시전했습니다."); + System.out.println(hero + "HP :" + hero.getHp()); + } } } From 8ed8a9cdb073c18cdfe4b1f07fa8371be8f09a66 Mon Sep 17 00:00:00 2001 From: "Sunjin.Kim" Date: Tue, 16 Jun 2026 15:06:54 +0900 Subject: [PATCH 08/20] =?UTF-8?q?=EC=97=B0=EC=8A=B5=EB=AC=B8=EC=A0=9C4=20?= =?UTF-8?q?=EB=A7=88=EB=B2=95=EC=82=AC=20=EC=88=98=EC=A0=95=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/survivalcoding/WizardTest.java | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/game2/src/test/java/com/survivalcoding/WizardTest.java b/game2/src/test/java/com/survivalcoding/WizardTest.java index a96bd52..a8aa488 100644 --- a/game2/src/test/java/com/survivalcoding/WizardTest.java +++ b/game2/src/test/java/com/survivalcoding/WizardTest.java @@ -70,26 +70,38 @@ void setWand() { } @Test - @DisplayName("heal 쓰면 지팡이의 마력만큼 HP가 회복되어야 한다") + @DisplayName("초기 마나는 100이 되어야 한다") + void baseMp() { + Wizard wizard = new Wizard(); + + assertEquals(100, wizard.getMp()); + } + + @Test + @DisplayName("heal 쓰면 mp10을 소모하고 hp가 20을 회복시켜야 한다") void heal() { - double test = 1.5; - int test2 = 10; - int test3 = 30; + int baseHp = 30; + int baseMp1 = 10; + int baseMp2 = 9; + int testMp = 10; + int baseHeal = 20; //Given Wizard wizard = new Wizard(); - Wand wand = new Wand(); Hero hero = new Hero(); - wand.setPower(test); - int basePoint = test2; - hero.setHp(test3); - wizard.setWand(wand); + hero.setHp(baseHp); + //When + wizard.setMp(baseMp1); wizard.heal(hero); //Then - assertEquals(test * test2 + test3, hero.getHp()); + assertEquals(baseHp + baseHeal, hero.getHp()); + assertEquals(baseMp1 - testMp, wizard.getMp(), "힐을 시전했습니다."); + + wizard.setMp(baseMp2); + wizard.heal(hero); } } \ No newline at end of file From c5afc6ad90845f884b18fded7ec1731d8d48a08f Mon Sep 17 00:00:00 2001 From: "Sunjin.Kim" Date: Tue, 16 Jun 2026 15:07:04 +0900 Subject: [PATCH 09/20] =?UTF-8?q?=EC=83=81=EC=86=8D=EC=97=B0=EC=8A=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/survivalcoding/SuperHero.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 game2/src/main/java/com/survivalcoding/SuperHero.java diff --git a/game2/src/main/java/com/survivalcoding/SuperHero.java b/game2/src/main/java/com/survivalcoding/SuperHero.java new file mode 100644 index 0000000..7818072 --- /dev/null +++ b/game2/src/main/java/com/survivalcoding/SuperHero.java @@ -0,0 +1,39 @@ +package com.survivalcoding; + +public class SuperHero extends Hero { + public static void main(String[] args) { + SuperHero superHero = new SuperHero("홍길동", 50); + superHero.attack(); + superHero.run(); + superHero.setFlying(true); + } + + private boolean isFlying; + + //상속을 받으면 부모 클래스의 생성자를 반드시 호출해야만 한다. + public SuperHero(String name, int hp) { + super(name, hp); + } + + + public boolean isFlying() { + return isFlying; + } + + public void setFlying(boolean flying) { + isFlying = flying; + } + + @Override + public void run() { + System.out.println("매우 빠르게 달렸다."); + } + + @Override + void attack() { + super.attack(); + if (isFlying) { + System.out.println("한번 더 때려라"); + } + } +} From 0448d642be75dfd34778aed8bae4a771b533f1da Mon Sep 17 00:00:00 2001 From: "Sunjin.Kim" Date: Tue, 16 Jun 2026 15:07:12 +0900 Subject: [PATCH 10/20] =?UTF-8?q?=ED=9E=88=EC=96=B4=EB=A1=9C=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/survivalcoding/Hero.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/game2/src/main/java/com/survivalcoding/Hero.java b/game2/src/main/java/com/survivalcoding/Hero.java index e1d2d76..0e5d889 100644 --- a/game2/src/main/java/com/survivalcoding/Hero.java +++ b/game2/src/main/java/com/survivalcoding/Hero.java @@ -3,6 +3,7 @@ public class Hero { public static int money = 100; + public static int MaxHP = 100; private String name; private int hp; @@ -13,6 +14,21 @@ public int getHp() { } public void setHp(int hp) { + if (hp < 0) { + hp = 0; + } + this.hp = hp; + } + + public Hero() { + this.name = "홍길동"; + this.hp = 100; + System.out.println("홍길동 생성자"); + + } + + public Hero(String name, int hp) { + this.name = name; this.hp = hp; } @@ -40,6 +56,10 @@ void attack() { hp -= 1; System.out.println("공격했다"); } + + public void run() { + System.out.println("달렸다"); + } } From 9f168922af67446d3e4eb2cbdfe78b8d064b23c0 Mon Sep 17 00:00:00 2001 From: "Sunjin.Kim" Date: Tue, 16 Jun 2026 15:07:20 +0900 Subject: [PATCH 11/20] =?UTF-8?q?=EC=97=B0=EC=8A=B5=EB=AC=B8=EC=A0=9C5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/survivalcoding/GreatWizard.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 game2/src/main/java/com/survivalcoding/GreatWizard.java diff --git a/game2/src/main/java/com/survivalcoding/GreatWizard.java b/game2/src/main/java/com/survivalcoding/GreatWizard.java new file mode 100644 index 0000000..fb0b9dd --- /dev/null +++ b/game2/src/main/java/com/survivalcoding/GreatWizard.java @@ -0,0 +1,53 @@ +package com.survivalcoding; + +import static com.survivalcoding.Hero.MaxHP; + +public class GreatWizard extends Wizard { + private int Mp = 150; + + @Override + public int getMp() { + return Mp; + } + + @Override + public void setMp(int mp) { + Mp = mp; + } + + public GreatWizard() { + super(); + } + + + @Override + void heal(Hero hero) { + int basePoint = 25; + int baseMp = 5; + + if (this.getMp() >= 5) { + hero.setHp(hero.getHp() + basePoint); + this.setMp(this.getMp() - baseMp); + System.out.println("힐을 시전했습니다."); + System.out.println(hero + "HP :" + hero.getHp()); + } else { + System.out.println("마나가 부족합니다"); + } + } + + void superHeal(Hero hero) { + + int basePoint = MaxHP; + int baseMp = 50; + + + if (this.getMp() >= 50) { + hero.setHp(basePoint); + this.setMp(this.getMp() - baseMp); + System.out.println("슈퍼 힐을 시전했습니다"); + System.out.println(hero + "HP :" + hero.getHp()); + } else { + System.out.println("마나가 부족합니다"); + } + } +} From 5b9eeeab07e2874de95e79821e28d185e51e1da5 Mon Sep 17 00:00:00 2001 From: "Sunjin.Kim" Date: Tue, 16 Jun 2026 15:07:27 +0900 Subject: [PATCH 12/20] =?UTF-8?q?=EC=97=B0=EC=8A=B5=EB=AC=B8=EC=A0=9C5=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/survivalcoding/GreatWizardTest.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 game2/src/test/java/com/survivalcoding/GreatWizardTest.java diff --git a/game2/src/test/java/com/survivalcoding/GreatWizardTest.java b/game2/src/test/java/com/survivalcoding/GreatWizardTest.java new file mode 100644 index 0000000..a4c3e13 --- /dev/null +++ b/game2/src/test/java/com/survivalcoding/GreatWizardTest.java @@ -0,0 +1,72 @@ +package com.survivalcoding; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + + +class GreatWizardTest { + + @Test + @DisplayName("GreatWizard 초기 MP는 150이어야 한다") + void getMp() { + GreatWizard greatWizard = new GreatWizard(); + + assertEquals(150, greatWizard.getMp()); + } + + @Test + @DisplayName("GreatWizard는 MP5를 소비하여 HP 25를 회복해야 한다.") + void heal() { + int baseHp = 30; + int baseMp1 = 5; + int baseMp2 = 4; + int testMp = 5; + int baseHeal = 25; + + + //Given + GreatWizard greatwizard = new GreatWizard(); + Hero hero = new Hero(); + hero.setHp(baseHp); + + + //When + greatwizard.setMp(baseMp1); + greatwizard.heal(hero); + //Then + + assertEquals(baseHp + baseHeal, hero.getHp()); + assertEquals(baseMp1 - testMp, greatwizard.getMp(), "힐을 시전했습니다."); + + greatwizard.setMp(baseMp2); + greatwizard.heal(hero); + } + + @Test + @DisplayName("슈퍼힐을 시전하면 HP가 최대값이 되고 MP를 50소모되어야 한다") + void superHeal() { + int basePoint = 100; //히어로 클래스 히어로 체력 100설정 + int baseMp = 50; + int testHp = 30; + int testMp = 50; + int baseMp2 = 49; + + + //Given + Hero hero = new Hero(); + GreatWizard greatWizard = new GreatWizard(); + hero.setHp(testHp); + + greatWizard.setMp(baseMp); + greatWizard.superHeal(hero); + + assertEquals(basePoint, hero.getHp()); + assertEquals(baseMp - testMp, greatWizard.getMp(), "슈퍼 힐을 시전했습니다."); + + greatWizard.setMp(baseMp2); + greatWizard.superHeal(hero); + + } +} \ No newline at end of file From a346e36bca1c57f8969ef29d03233d730aed33a0 Mon Sep 17 00:00:00 2001 From: "Sunjin.Kim" Date: Tue, 16 Jun 2026 15:07:37 +0900 Subject: [PATCH 13/20] =?UTF-8?q?=EC=97=B0=EC=8A=B5=EB=AC=B8=EC=A0=9C1~2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...54\227\260\354\212\265\353\254\270\354\240\234" | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 "game2/src/main/java/com/survivalcoding/260616_\354\227\260\354\212\265\353\254\270\354\240\234" diff --git "a/game2/src/main/java/com/survivalcoding/260616_\354\227\260\354\212\265\353\254\270\354\240\234" "b/game2/src/main/java/com/survivalcoding/260616_\354\227\260\354\212\265\353\254\270\354\240\234" new file mode 100644 index 0000000..b3175ff --- /dev/null +++ "b/game2/src/main/java/com/survivalcoding/260616_\354\227\260\354\212\265\353\254\270\354\240\234" @@ -0,0 +1,14 @@ +슈퍼클래스 서브클래스 +1 Person Student +2 Car Engine +3 Father Child +4 Food Susi +5 SuperMan Man + +2, 3, 5 + +부모 클래스와 자식 클래스 1개씩 + +기계 기계 책 +Phone Car Dictionary +아이폰 슈퍼카 영어사전 \ No newline at end of file From 11369085604baf6ed1031ad168ad84c4836fca2e Mon Sep 17 00:00:00 2001 From: "Sunjin.Kim" Date: Tue, 16 Jun 2026 15:13:05 +0900 Subject: [PATCH 14/20] =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game2/src/test/java/com/survivalcoding/GreatWizardTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game2/src/test/java/com/survivalcoding/GreatWizardTest.java b/game2/src/test/java/com/survivalcoding/GreatWizardTest.java index a4c3e13..ba9e4f4 100644 --- a/game2/src/test/java/com/survivalcoding/GreatWizardTest.java +++ b/game2/src/test/java/com/survivalcoding/GreatWizardTest.java @@ -49,9 +49,9 @@ void heal() { void superHeal() { int basePoint = 100; //히어로 클래스 히어로 체력 100설정 int baseMp = 50; + int baseMp2 = 49; int testHp = 30; int testMp = 50; - int baseMp2 = 49; //Given From 990801f5ebb294bdf2859f384d9bea4b471de3bc Mon Sep 17 00:00:00 2001 From: "Sunjin.Kim" Date: Tue, 16 Jun 2026 15:13:28 +0900 Subject: [PATCH 15/20] =?UTF-8?q?=EC=8A=AC=EB=9D=BC=EC=9E=84=20=EB=B6=80?= =?UTF-8?q?=EB=AA=A8=ED=81=B4=EB=9E=98=EC=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/survivalcoding/Slime.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 game2/src/main/java/com/survivalcoding/Slime.java diff --git a/game2/src/main/java/com/survivalcoding/Slime.java b/game2/src/main/java/com/survivalcoding/Slime.java new file mode 100644 index 0000000..5254302 --- /dev/null +++ b/game2/src/main/java/com/survivalcoding/Slime.java @@ -0,0 +1,17 @@ +package com.survivalcoding; + +public class Slime { + final String suffix; + int hp; + + public Slime(String suffix) { + this.suffix = suffix; + } + + void attack(Hero hero) { + System.out.println("슬라임" + suffix + "이/가 공격했다"); + System.out.println("10의 데미지"); + + hero.setHp((hero.getHp()) - 10); + } +} From 697b1559a042b9d05150c47240df685ed39f63ad Mon Sep 17 00:00:00 2001 From: "Sunjin.Kim" Date: Tue, 16 Jun 2026 16:06:50 +0900 Subject: [PATCH 16/20] =?UTF-8?q?=EC=97=B0=EC=8A=B5=EB=AC=B8=EC=A0=9C3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/survivalcoding/PoisonSlime.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 game2/src/main/java/com/survivalcoding/PoisonSlime.java diff --git a/game2/src/main/java/com/survivalcoding/PoisonSlime.java b/game2/src/main/java/com/survivalcoding/PoisonSlime.java new file mode 100644 index 0000000..555f801 --- /dev/null +++ b/game2/src/main/java/com/survivalcoding/PoisonSlime.java @@ -0,0 +1,31 @@ +package com.survivalcoding; + +public class PoisonSlime extends Slime { + private int poisonCount = 5; + + public int getPoisonCount() { + return poisonCount; + } + + public void setPoisonCount(int poisonCount) { + this.poisonCount = poisonCount; + } + + public PoisonSlime(String name) { + super(name); + } + + @Override + void attack(Hero hero) { + + if (this.getPoisonCount() > 0) { + super.attack(hero); + System.out.println("추가로, 독 포자를 살포했다!"); + hero.setHp(hero.getHp() - (int) (hero.getHp()) / 5); + System.out.println("~포인트 데미지"); + this.poisonCount--; + } else { + super.attack(hero); + } + } +} From 4a58170e09e62911c962f894269086bf259cb81e Mon Sep 17 00:00:00 2001 From: "Sunjin.Kim" Date: Tue, 16 Jun 2026 16:06:55 +0900 Subject: [PATCH 17/20] =?UTF-8?q?=EC=97=B0=EC=8A=B5=EB=AC=B8=EC=A0=9C3=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/survivalcoding/PoisonSlimeTest.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 game2/src/test/java/com/survivalcoding/PoisonSlimeTest.java diff --git a/game2/src/test/java/com/survivalcoding/PoisonSlimeTest.java b/game2/src/test/java/com/survivalcoding/PoisonSlimeTest.java new file mode 100644 index 0000000..8a0edec --- /dev/null +++ b/game2/src/test/java/com/survivalcoding/PoisonSlimeTest.java @@ -0,0 +1,45 @@ +package com.survivalcoding; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static com.survivalcoding.Hero.MaxHP; +import static org.junit.jupiter.api.Assertions.assertEquals; + + +class PoisonSlimeTest { + + @Test + @DisplayName("A라는 PoisonSlime이 공격하면 보통슬라임과 같은 공격을 한 후 추가로 독데미지를 살포 해야한다") + void attack() { + int testHp = MaxHP; + int testCount = 5; + + + Hero hero = new Hero(); + PoisonSlime poisonSlime = new PoisonSlime("A"); + + hero.setHp(testHp); + poisonSlime.attack(hero); + poisonSlime.setPoisonCount(testCount); + + assertEquals(MaxHP - 10 - ((MaxHP - 10) / 5), hero.getHp()); + + } + + @Test + @DisplayName("PoisonCount 가 1보다 작아지면 독데미지가 들어가면 안된다") + void attack2() { + int testHp = MaxHP; + int testCount = 0; + + Hero hero = new Hero(); + PoisonSlime poisonSlime = new PoisonSlime("A"); + + hero.setHp(testHp); + poisonSlime.setPoisonCount(testCount); + poisonSlime.attack(hero); + + assertEquals(testHp - 10, hero.getHp()); + } +} \ No newline at end of file From 12f0780bae42d8894d1ed6366131592a70163ba5 Mon Sep 17 00:00:00 2001 From: "Sunjin.Kim" Date: Tue, 16 Jun 2026 16:22:10 +0900 Subject: [PATCH 18/20] =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EA=B7=B8?= =?UTF-8?q?=EB=A6=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game2/game2.puml | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 game2/game2.puml diff --git a/game2/game2.puml b/game2/game2.puml new file mode 100644 index 0000000..2347662 --- /dev/null +++ b/game2/game2.puml @@ -0,0 +1,59 @@ +@startuml +class SuperHero extends Hero { + +void setFlying(bool flying) + +boolean isFlying() + + run()+ +} +class Hero { + - int hp 100 + - int mp + - int money 100 + -String name + + void attack() + + run() +} +class Cleric { + - int hp + - int mp + - int MaxHP + - int MaxMP + - String name + + selfAid() + + pray() +} +class GreatWizard extends Wizard { + +heal()+ + +superHeal() +} + +class Wizard { + - int hp + - int mp = 100 + - Wand wand + - String name + + setWand() + + heal() +} + +class Wand { + - String name + - double power +} + +class Person { + -int age + -String name + -int birthYear +} +class PoisonSlime extends Slime { + +attack()+ +} + +class Slime { + -String suffix + -int hp + +attack() +} + + +@enduml \ No newline at end of file From 7d3d925f6eb0b6b6166cbb748dca2fd29f53d59a Mon Sep 17 00:00:00 2001 From: "Sunjin.Kim" Date: Tue, 16 Jun 2026 16:26:11 +0900 Subject: [PATCH 19/20] =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "TIL/2026-06-11-\354\203\201\354\206\215.md" | 60 ++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 "TIL/2026-06-11-\354\203\201\354\206\215.md" diff --git "a/TIL/2026-06-11-\354\203\201\354\206\215.md" "b/TIL/2026-06-11-\354\203\201\354\206\215.md" new file mode 100644 index 0000000..03efcce --- /dev/null +++ "b/TIL/2026-06-11-\354\203\201\354\206\215.md" @@ -0,0 +1,60 @@ +# 2026-06-11 상속 + +## 오늘 배운 내용 + +- 상속을 받으면 부모 클래스의 생성자를 반드시 호출해야만 한다. +- @Override를 통해 기존 부모의 것을 가져 올 수 있고 필요하면 수정도 가능하다. + +## 실습 코드 + +```java +public class SuperHero extends Hero { + public static void main(String[] args) { + SuperHero superHero = new SuperHero("홍길동", 50); + superHero.attack(); + superHero.run(); + superHero.setFlying(true); + } + + private boolean isFlying; + + //상속을 받으면 부모 클래스의 생성자를 반드시 호출해야만 한다. + public SuperHero(String name, int hp) { + super(name, hp); + } + + + public boolean isFlying() { + return isFlying; + } + + public void setFlying(boolean flying) { + isFlying = flying; + } + + @Override + public void run() { + System.out.println("매우 빠르게 달렸다."); + } + + @Override + void attack() { + super.attack(); + if (isFlying) { + System.out.println("한번 더 때려라"); + } + } +} +``` + +## 어려웠던 점 + +- 상속받는 클래스 만드는 것과 테스트 코드 짜는법 + +## 해결 방법 + +- 계속 원하는 바가 안나와서 테스트 코드를 보니 When 순서가 이상해서 안되었다는 걸 알아서 앞으로 When 순서도 잘 생각해서 넣어야한다는 걸 알았습니다. + +## 내일 더 공부할 것 + +- 상속에 관련 클래스를 더 공부하고 여러개를 만들어볼 것 \ No newline at end of file From aa9d756946ba58c8c11e3e920a1384436af9470e Mon Sep 17 00:00:00 2001 From: "Sunjin.Kim" Date: Tue, 16 Jun 2026 16:39:18 +0900 Subject: [PATCH 20/20] =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game2/src/test/java/com/survivalcoding/PoisonSlimeTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game2/src/test/java/com/survivalcoding/PoisonSlimeTest.java b/game2/src/test/java/com/survivalcoding/PoisonSlimeTest.java index 8a0edec..2a761a8 100644 --- a/game2/src/test/java/com/survivalcoding/PoisonSlimeTest.java +++ b/game2/src/test/java/com/survivalcoding/PoisonSlimeTest.java @@ -20,8 +20,8 @@ void attack() { PoisonSlime poisonSlime = new PoisonSlime("A"); hero.setHp(testHp); - poisonSlime.attack(hero); poisonSlime.setPoisonCount(testCount); + poisonSlime.attack(hero); assertEquals(MaxHP - 10 - ((MaxHP - 10) / 5), hero.getHp());