11일차 클래스(19)

Console Programming/C# Console 2019. 10. 4. 14:57
 
Weapon.cs
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax46
{
    public class Weapon
    {
        //data
        //name
        public string name;
        public Weapon(string name)
        {
            this.name = name;
            Console.WriteLine($"{this.name}이(가) 생성되었습니다.");
 
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

 
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax46
{
    public class Unit
    {
 
        //data
        //name
        //Weapon
        public string name;
        public Weapon weapon;
        public Unit(string name)
        {
            this.name = name;
            Console.WriteLine($"{this.name}이(가) 생성되었습니다.");
        }
        //function
        //Equip
        //UnEquip
        public void Equip(Weapon weapon)
        {
            this.weapon = weapon;
            Console.WriteLine($"{this.name}이(가) {weapon.name}을 착용했습니다.");
        }
        public void UnEquip(Weapon weapon)
        {
            this.weapon = null;
            Console.WriteLine($"{this.name}이(가) {weapon.name}을 해제했습니다.");
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

 
Game.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax46
{
    public class Game
    {
        //data
        //name
        public string name;
        public Game(string name)
        {
            this.name = name;
            Console.WriteLine($"{this.name}이(가) 생성되었습니다.");
 
        }
        public Unit MakeUnit(string name)
        {
            var unit = new Unit(name);
 
            return unit;
        }
        public Weapon MakeWeapon(string name)
        {
            var weapon = new Weapon(name);
 
            return weapon;
        }
    }
}
 
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
25
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax46
{
    public class App
    {
        public App()
        {
            var game1 = new Game("게임관리자");
 
            var unit1 = game1.MakeUnit("맥크리");
            var weapon1 = game1.MakeWeapon("리볼버");
 
            unit1.Equip(weapon1);
            unit1.UnEquip(weapon1);
 
 
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

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

11일차 클래스(21)  (0) 2019.10.04
11일차 클래스(20)  (0) 2019.10.04
11일차 클래스(18)  (0) 2019.10.04
11일차 클래스(17)  (0) 2019.10.04
11일차 클래스(16)  (0) 2019.10.04
: