11일차 클래스(15)

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

 

 
Crop.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax42
{
    public class Crop
    {
        //data
        //name
        //hp
        public string name;
        public int maxHp = 30;
        public int hp;
        public Crop(string name)
        {
            this.name = name;
            Console.WriteLine($"{this.name}이(가) 생성되었습니다.");
            this.hp = this.maxHp;
        }
 
        public void Hit(Monster 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
 

 

 
Monster.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax42
{
    public class Monster
    {
        //data
        //name
        //damage       
        public string name;
        public int damage = 5;
       
 
        public Monster(string name)
        {
            this.name = name;
            Console.WriteLine($"{this.name}이(가) 생성되었습니다.");
        }
 
        public void Attack(Crop crop)
        {
            Console.WriteLine($"{this.name}가 {crop.name}을 공격했습니다.");
            crop.Hit(this);
        }
       
    }
}
 
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax42
{
    public class Game
    {
        //data
        //name
        public string name;
        public Game(string name)
        {
            this.name = name;
            Console.WriteLine($"{this.name}이(가) 생성되었습니다.");
        }
        public Monster MakeMonster(string name)
        {
            var monster = new Monster(name);
            return monster;
        }
 
        public Crop MakeCrop(string name)
        {
            var crop = new Crop(name);
            return crop;
        }
    }
}
 
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax42
{
    public class App
    {
        public App()
        {
            var game1 = new Game("게임 관리자");
 
            var monster1 =game1.MakeMonster("쥐");
            var crop1 = game1.MakeCrop("호박");
 
            monster1.Attack(crop1);
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter

 

 

 

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

11일차 클래스(17)  (0) 2019.10.04
11일차 클래스(16)  (0) 2019.10.04
11일차 클래스(14)  (0) 2019.10.04
11일차 클래스(13)  (0) 2019.10.04
11일차 클래스(12)  (0) 2019.10.04
: