0317 interface+abstract+stack+queue
2021. 3. 17. 18:22ㆍC#/과제
public class Censored:Abnormality,IEscapable,ISpawnBaby
{
public Censored()
{
}
public void Escapable()
{
Console.WriteLine("검열삭제가 격리실을 벗어났습니다.");
}
public override void Attack()
{
Console.WriteLine("검열삭제가 공격합니다.");
}
public void SpawnBaby()
{
Console.WriteLine("검열삭제가 새끼를 깝니다.");
}
}
public class SilentOrchestra:Abnormality,IEscapable
{
public SilentOrchestra()
{ }
public void Escapable()
{
Console.WriteLine("고요한 오케스트라가 격리실을 벗어났습니다.");
}
public override void Attack()
{
Console.WriteLine("고요한 오케스트라가 연주를 시작했습니다.");
}
}
public class WhiteNight:Abnormality,ISpawnBaby
{
public WhiteNight()
{ }
public void SpawnBaby()
{
Console.WriteLine("백야가 12명의 사도를 소환합니다.");
}
public override void Attack()
{
Console.WriteLine("백야가 Pale 광선을 뿜습니다.");
}
}
public class NothingThere:Abnormality,IEscapable
{
public NothingThere()
{
}
public void Escapable()
{
Console.WriteLine("아무것도 없는이 격리실을 벗어났습니다.");
}
public void OneKill()
{
Console.WriteLine("아무것도 없는이 Good Bye를 외칩니다.");
}
public override void Attack()
{
Console.WriteLine("아무것도 없는이 공격합니다.");
}
}
interface IEscapable
{
void Escapable();
}
interface ISpawnBaby
{
void SpawnBaby();
}
public class App
{
public App()
{
Console.WriteLine("App 생성자");
Censored cesorned = new Censored();
cesorned.Escapable();
cesorned.Attack();
cesorned.SpawnBaby();
Console.WriteLine();
NothingThere nothingThere = new NothingThere();
nothingThere.Escapable();
nothingThere.Attack();
nothingThere.OneKill();
Console.WriteLine();
SilentOrchestra silentOrchestra = new SilentOrchestra();
silentOrchestra.Escapable();
silentOrchestra.Attack();
Console.WriteLine();
WhiteNight whiteNight = new WhiteNight();
whiteNight.SpawnBaby();
whiteNight.Attack();
}
}
public abstract class Abnormality
{
public abstract void Attack();
}
public class BlueStar:Abnormality,IAttackable
{
public BlueStar()
{
}
public override void Attack()
{
Console.WriteLine("푸른 별이 청량한 소리를 냅니다.");
}
public void Attackable()
{
Console.WriteLine("푸른 별을 제압합니다.");
}
}
public class DimensionalRefraction:Abnormality,ICloak
{
public DimensionalRefraction()
{ }
public override void Attack()
{
Console.WriteLine("차원굴절 변이체가 관리직을 공격합니다.");
}
public void Cloak()
{
Console.WriteLine("차원굴절 변이체가 공중을 떠다닙니다.");
}
}
public class MeatLantern:Abnormality
{
public MeatLantern()
{ }
public override void Attack()
{
Console.WriteLine("고기 초롱이 사무직을 잡아먹습니다.");
}
public void Cloak()
{
Console.WriteLine("고기 초롱이 숨었습니다.");
}
}
interface ICloak
{
void Cloak();
}
interface IAttackable
{
void Attackable();
}
Console.WriteLine("App 생성자");
MeatLantern meatLantern = new MeatLantern();
meatLantern.Cloak();
meatLantern.Attack();
Console.WriteLine();
DimensionalRefraction dimensionalRefraction = new DimensionalRefraction();
dimensionalRefraction.Cloak();
dimensionalRefraction.Attack();
Console.WriteLine();
BlueStar blueStar = new BlueStar();
blueStar.Attack();
blueStar.Attackable();
stack
public App()
{
//stack<string>변수 선언과 인스턴스 생성 및 초기화
Stack<string> names = new Stack<string>();
names.Push("질롯");
names.Push("드라군");
names.Push("템플러");
names.Push("다크템플러");
names.Push("옵져버");
foreach (string name in names)
{
Console.WriteLine(name);
}
string namePop=names.Pop();
Console.WriteLine(namePop);
Console.WriteLine(names.Count);
bool isContains=names.Contains("질롯");
Console.WriteLine(isContains);
string namePeek = names.Peek();
Console.WriteLine("Peek: {0}",namePeek);
//stack > array //요소 복사본을 포함하는 새 배열 반환
string[] arrNames=names.ToArray();
Console.WriteLine("=======Array=======");
for (int i = 0; i < arrNames.Length; i++)
{
Console.WriteLine("index:{0} name; {1}",i,arrNames[i]);
}
//copy to
Console.WriteLine("=======Array arrNames copy to arrNames2=======");
string[] arrNames2 = new string[arrNames.Length * 2];
Console.WriteLine(arrNames2.Length);
arrNames.CopyTo(arrNames2, arrNames.Length);
for (int i = 0; i < arrNames2.Length; i++)
{
if (string.IsNullOrEmpty(arrNames2[i]))
{
Console.WriteLine("[empty]");
}
else
{
Console.WriteLine(arrNames2[i]);
}
}
}
queue
public App()
{
//Queue<stirng>인스턴스 생성
Queue<string> names = new Queue<string>();
names.Enqueue("질롯");
names.Enqueue("드라군");
names.Enqueue("템플러");
names.Enqueue("다크템플러");
foreach (string name in names)
{
Console.WriteLine(name);
}
Console.WriteLine("======================");
string deQueueName = names.Dequeue();
Console.WriteLine(deQueueName);
Console.WriteLine("============Array==========");
string[] arrNames = names.ToArray();
for (int i = 0; i < arrNames.Length; i++)
{
Console.WriteLine(arrNames[i]);
}
Console.WriteLine("=========names copy to namesCopy=============");
Queue<string> namesCopy = new Queue<string>(arrNames);
foreach (string name in names)
{
Console.WriteLine(name);
}
bool isContains=names.Contains("드라군");
Console.WriteLine(isContains);
}
'C# > 과제' 카테고리의 다른 글
0329 스레드 복습 (0) | 2021.03.29 |
---|---|
0322 delegate 연습 (0) | 2021.03.23 |
0316 컬랙션 과제 (0) | 2021.03.17 |
0314 클래스와 메서드 (0) | 2021.03.15 |
0311 Class+맴버 변수+메서드 호출 연습 (0) | 2021.03.11 |