Notice
Recent Posts
Recent Comments
Link
스토리지
[3.24] Action을 이용한 배럭스 본문
using System;
namespace Study10
{
public class Unit
{
public eUnitType unitType;
public Unit(eUnitType type)
{
Console.WriteLine("{0}이 생성되었습니다.", type);
unitType = type;
}
}
}
using System;
using System.Collections.Generic;
using System.Threading;
namespace Study10
{
public enum eUnitType
{
MARINE,
FIREBAT,
MEDIC
}
public class Barracks
{
Queue<eUnitType> process;
public Barracks()
{
Console.WriteLine("Barracks가 생성되었습니다.");
process = new Queue<eUnitType>();
}
public void CreateUnit(eUnitType[] unitTypes, Action<Unit> callback)
{
foreach (var unitType in unitTypes)
{
process.Enqueue(unitType);
}
while (process.Count != 0)
{
Console.Write("대기열 : ");
foreach (var unitType in process)
{
Console.Write("{0} ", unitType);
}
Console.WriteLine();
for (int i = 10; i <= 100; i += 10)
{
Console.Write("III");
Thread.Sleep(100);
}
Console.WriteLine();
callback(new Unit(process.Dequeue()));
Thread.Sleep(500);
Console.WriteLine();
}
}
}
}
using System;
namespace Study10
{
public class App
{
public App()
{
Barracks barracks = new Barracks();
eUnitType[] order = {
eUnitType.FIREBAT,
eUnitType.MARINE,
eUnitType.MARINE,
eUnitType.MEDIC
};
barracks.CreateUnit(order, (unit) =>
{
Console.WriteLine(unit.unitType); //Marine
});
}
}
}
'Unity > 수업내용(C#)' 카테고리의 다른 글
[3.24] Event를 이용한 드론 조종 (0) | 2021.03.24 |
---|---|
[3.24] SortedList를 통한 IComparable<T> 복습 (0) | 2021.03.24 |
[3.24] delegate를 이용한 드론과 컨트롤러 (0) | 2021.03.24 |
[3.24] delegate 복습 (0) | 2021.03.24 |
[3.22] delegate chain (Multicast delegate) (0) | 2021.03.23 |
Comments