10.03 11일차 클래스 (29) 질럿,드라군 공격사거리

Console Programming/C# Console 2019. 10. 8. 03:10

 

 

 

 
Unit.cs  
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApp1007
{
    public class Unit
    {
        //data
        //name
        //damage
        //hp
        //attackRange
        public string name;
        public int hp;
        public int maxHp;
        public int damage;
        public int attackRange;        
        public Unit(string name, int maxHp, int damage, int attackRange)
        {
            this.name = name;
            this.maxHp = maxHp;
            this.hp = maxHp;
            this.damage = damage;
            this.attackRange = attackRange;
            Console.WriteLine($"{this.name}이 생성되었습니다.");
            Console.WriteLine($"{this.name}의 공격력은{this.damage}입니다.");
            Console.WriteLine($"{this.name}의 공격사거리는 {this.attackRange}입니다.");
            Console.WriteLine($"{this.name}의 체력은 {this.hp}입니다.");
        }
        //function
        //Attack
        //Hit
        public void Attack(Unit target, int distance)
        {
            Console.WriteLine($"{this.name}이 {target.name}을 공격했습니다.");
            if(distance>this.attackRange)
            {
                Console.WriteLine("사거리가 되지 않아 공격에 실패 했습니다");
                return;
            }
            target.Hit(this);
        }
        public void Hit(Unit attacker)
        {
            this.hp = this.hp - attacker.damage;
            Console.WriteLine($"{attacker.name}이 {this.name}을 공격했습니다.");
            Console.WriteLine($"{this.name}의 체력이 감소했습니다.");
            Console.WriteLine($"{this.name}의 체력은 {this.hp}{this.maxHp}입니다.");
 
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

49라인이 38라인과 중복되고

51라인의 {this.hp}{this.maxHp}가 곱연산으로 나와서 결과가 610으로 나왔다.

 

 

 

'Console Programming > C# Console' 카테고리의 다른 글

백준 2675 문자열 반복  (0) 2019.10.08
백준 11809 알파벳 찾기  (0) 2019.10.08
11일차 클래스(23)  (0) 2019.10.04
11일차 클래스(22)  (0) 2019.10.04
11일차 클래스(21)  (0) 2019.10.04
: