메인 메서드
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
public enum eUnitType
{
Drone, Zergling
}
public enum eBuildType
{
SpawningPool
}
static void Main(string[] args)
{
Larva larva1 = new Larva();
Larva larva2 = new Larva();
SpawningPool pool = null;
//스포닝풀이 있다면 변태한다
if (pool != null)
{
larva2.TransToUnit(eUnitType.Zergling);
larva2 = null;
}
else
{
Console.WriteLine("저글링으로 변태를 시도합니다.");
Console.WriteLine("스포닝풀이 필요합니다.");
}
Drone drone1 = larva1.TransToUnit(eUnitType.Drone);
larva1 = null;
pool = drone1.TransToBuild(eBuildType.SpawningPool);
drone1 = null;
if (pool != null)
{
larva2.TransToUnit(eUnitType.Zergling);
larva2 = null;
}
else
{
Console.WriteLine("저글링으로 변태를 시도합니다.");
Console.WriteLine("스포닝풀이 필요합니다.");
}
Console.WriteLine();
Console.WriteLine("확인");
Console.WriteLine("라바1: {0}", larva1);
Console.WriteLine("라바2: {0}", larva2);
Console.WriteLine("드론1: {0}", drone1);
Console.WriteLine("스포닝풀: {0}", pool);
}
}
라바 클래스
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Larva
{
//생성자
public Larva()
{
Console.WriteLine("라바가 생성되었습니다.");
}
//멤버 메서드
public Drone TransToUnit(Program.eUnitType unitType)
{
Console.WriteLine("라바가 {0}로 변태를 시도합니다.", unitType);
if (unitType == Program.eUnitType.Drone)
{
return new Drone();
}
else if (unitType == Program.eUnitType.Zergling)
{
Zergling zergling1 = new Zergling();
Zergling zergling2 = new Zergling();
Console.WriteLine("zergling1 : {0}", zergling1);
Console.WriteLine("zergling2 : {0}", zergling2);
return null;
}
else
{
return null;
}
}
}
드론 클래스
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Drone
{
//멤버 변수
//생성자
public Drone()
{
Console.WriteLine("드론이 생성되었습니다.");
}
//멤버 메서드
public SpawningPool TransToBuild(Program.eBuildType buildType)
{
Console.WriteLine("{0}로 변태를 시도합니다.", buildType);
if (buildType == Program.eBuildType.SpawningPool)
{
return new SpawningPool();
}
else
{
return null;
}
}
}
저글링 클래스
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Zergling
{
//생성자
public Zergling()
{
Console.WriteLine("저글링이 생성되었습니다.");
}
//멤버 메서드
void Attack()
{
}
}
스포닝풀 클래스
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class SpawningPool
{
//멤버 변수
//생성자
public SpawningPool()
{
Console.WriteLine("스포닝풀이 생성되었습니다.");
}
//멤버 메서드
}
'C# > 수업 내용' 카테고리의 다른 글
클래스, new, 생성자, this. 질럿1-질럿2 (0) | 2021.12.24 |
---|---|
다른 클래스에 접근할때? X; 목표 객체에 접근할때. (0) | 2021.12.24 |
클래스 만들기-생성자 메서드 (라바-드론 생산) (0) | 2021.12.23 |
계산기 메서드 만들어보기 (0) | 2021.12.23 |
반환값이 있는 메서드 연습 (벌쳐, 템플러, 홀짝 판단, 줄넘기) (0) | 2021.12.23 |