9일차 메서드의 정의(14) 피격시 영웅의 체력을 감소 시키는 메서드

Console Programming/C# Console 2019. 10. 3. 13:54

피격시 영웅의 체력을 감소 시키는 메서드를 작성하세요 

 

 

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
using System;
using Syntax24;
 
namespace Syntax24
{
    class App
    {
      
        public App()
        {
 
            Console.WriteLine("2019-09-30");
            Console.WriteLine();
                       
            int monsterMaxHp = 10;
            int monsterHp = monsterMaxHp;
            int heroDamage = 5;
 
            AttackedMonsterHp(monsterHp, heroDamage);           
        }       
 
        public int AttackedMonsterHp(int monsterHp, int heroDamage)
        {
            if (monsterHp <= heroDamage)
            {
                Console.WriteLine($"몬스터가 데미지({-heroDamage})를 받았습니다.{0}/{monsterHp}");
                Console.WriteLine("몬스터가 죽었습니다.");
                return 0;
            }
 
            Console.WriteLine($"몬스터가 데미지({-heroDamage})를 받았습니다.{monsterHp - heroDamage}/{monsterHp}");
 
            return monsterHp - heroDamage;
 
        }
    }
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

 

: