11일차 클래스(13)

Console Programming/C# Console 2019. 10. 4. 14:45

배럭스

 
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax40
{
    public class Unit
    {
        //data
        //name
        //hp
        //damage
        public string name;
        public int maxHp = 40;
        public int hp;
        public int damage = 6;
 
        public Unit(string name)
        {
            this.name = name;
            Console.WriteLine($"{this.name}이(가) 생성되었습니다.");
            this.hp = this.maxHp;
        }
        public void Attack(Unit target)
        {
 
            Console.WriteLine($"{this.name}이 {target.name}을 공격 했습니다.");
            target.Hit(this);
 
        }
        public void Hit(Unit attacker)
        {
            this.hp = this.hp - attacker.damage;
            Console.WriteLine($"{this.name}가 {attacker.name}에게 공격당했습니다.({this.hp})/({this.maxHp})");
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

 
Building.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax40
{
    
 
    public class Building
    {
        //data
        //name
        public string name;
        public Building()
        {
 
        }
        public Unit MakeUnit(string name)
        {
            var unit = new Unit(name);
            return unit;
        }
    }
 
   
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

 
App.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax40
{
    public class App
    {
        public App()
        {
            var building1 = new Building();
            building1.name = "배럭스";
            Console.WriteLine($"{building1.name}이(가) 생성되었습니다.");
            var unit1 = building1.MakeUnit("마린1");
            var unit2 = building1.MakeUnit("마린2");
 
            unit1.Attack(unit2);
 
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

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

11일차 클래스(15)  (0) 2019.10.04
11일차 클래스(14)  (0) 2019.10.04
11일차 클래스(12)  (0) 2019.10.04
11일차 클래스(11)  (0) 2019.10.04
11일차 클래스(10)  (0) 2019.10.04
: