App.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study04
{
public class App
{
public App()
{
Console.WriteLine("2020-09-25\n");
Unit unit1 = new Unit("마린");
Unit unit2 = new Unit("저글링");
Console.WriteLine("===================================\n");
unit1.Attack(unit2);
unit2.Hit(unit1);
Console.WriteLine("===================================\n");
}
}
}
Unit.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study04
{
public class Unit
{
public string name;
public Unit(string name)
{
this.name = name;
Console.WriteLine("{0}이 생성되었습니다.", name);
}
public void Attack(Unit target)
{
Console.WriteLine("{0}이 {1}을 공격했습니다.",this.name,target.name);
}
public void Hit(Unit attacker)
{
Console.WriteLine("{0}이 {1}으로부터 공격당했습니다.", this.name, attacker.name);
}
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study04
{
class Program
{
static void Main(string[] args)
{
new App();
}
}
}
'C# > 수업내용' 카테고리의 다른 글
2020-09-25 Instance관련 예제5 (0) | 2020.09.25 |
---|---|
2020.09.25 수업내용 (0) | 2020.09.25 |
2020-09-25 Instance관련 예제4 (0) | 2020.09.25 |
2020-09-25 Instance관련 예제3 (0) | 2020.09.25 |
2020-09-25 Instance관련 예제1 (0) | 2020.09.25 |