App Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study06
{
class App
{
//생성자
public App()
{
Console.WriteLine("App 생성자");
Hero hero = new Hero();
Monster monster = new Monster();
Coin coin = monster.Die();
hero.Get(coin);
}
}
}
Hero Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study06
{
class Hero
{
int coinCount = 0;
//생성자
public Hero()
{
Console.WriteLine("Hero 생성");
Console.WriteLine("현재 코인: {0}", coinCount);
}
public void Get(Coin coin)
{
coinCount++;
Console.WriteLine("현재 코인: {0}", coinCount);
}
}
}
Monster Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study06
{
class Monster
{
//생성자
public Monster()
{
Console.WriteLine("Monster 생성");
}
public Coin Die()
{
Console.WriteLine("몬스터 죽음.");
return new Coin();
}
}
}
Coin Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study06
{
class Coin
{
//생성자
public Coin()
{
Console.WriteLine("Coin 생성");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study06
{
class Program
{
static void Main(string[] args)
{
new App();
}
}
}
실행결과
'C# > 수업내용' 카테고리의 다른 글
[C# 6일차] Method return 연습_Box에서 Item 획득 (0) | 2023.01.06 |
---|---|
[C# 6일차] Method return 연습_StarCraft Templer to Archon (0) | 2023.01.06 |
[C# 5일차] Starcraft Larva-Hydralisk-Lurker 진화 (0) | 2023.01.05 |
[C# 5일차] Class 복습과 활용_Starcraft SiegeTank 모드 변환 (0) | 2023.01.05 |
[C# 5일차] Class 복습과 활용_Starcraft Marine과 Medic (1) | 2023.01.05 |