C#/수업과제
03/11 클래스 생성 -> 인스턴스 생성 연습
박준희
2021. 3. 11. 17:37
Program.cs
namespace study01
{
class Program
{
static void Main(string[] args)
{
new App();
}
}
}
App.cs
using System;
namespace study01
{
public class App
{
public App()
{
Console.WriteLine("App생성자");
//질럿
Zealot zealot = new Zealot();
zealot.hp = 100;
Console.WriteLine("질럿의 hp :" + zealot.GetHp());
Console.WriteLine(zealot);
//드라군
Dragoon dragoon = new Dragoon();
dragoon.groundAttack = 20;
Console.WriteLine("드라군의 공격력 :" + dragoon.GetGroundAttack());
Console.WriteLine(dragoon);
//캐리어
Carrier carrier = new Carrier();
carrier.armor = 4;
Console.WriteLine("캐리어의 방어력 : " + carrier.GetArmor());
Console.WriteLine(carrier);
//아비터
Arbiter arbiter = new Arbiter();
arbiter.maximumEnergy = 200;
Console.WriteLine("아비터의 에너지 : " + arbiter.GetMaximumEnergy());
Console.WriteLine(arbiter);
//다크템플러
DarkTemplar darkTemplar = new DarkTemplar();
darkTemplar.minerals = 125;
Console.WriteLine("다크템플러의 필요 미네랄 : " + darkTemplar.GetMinerals());
Console.WriteLine(darkTemplar);
//프로브
Probe probe;
probe = new Probe();
probe.producedFrom = "넥서스";
Console.WriteLine("프로브 생산 건물 : " + probe.GetProducedFrom());
Console.WriteLine(probe);
//리버
Reaver reaver;
reaver = new Reaver();
reaver.requires = "Robotics support bay";
Console.WriteLine("리버 생산을 위해 필요한 건물 : " + reaver.GetRequires());
Console.WriteLine(reaver);
//스카웃
Scout scout;
scout = new Scout();
scout.size = "Large";
Console.WriteLine("스카웃 유닛 크기 : " + scout.GetSize());
Console.WriteLine(scout);
//셔틀
Shuttle shuttle;
shuttle = new Shuttle();
shuttle.hotkey = 's';
Console.WriteLine("셔틀의 단축키 : " + shuttle.GetHotkey());
Console.WriteLine(shuttle);
//옵저버
Observer observer;
observer = new Observer();
observer.sight = 9;
Console.WriteLine("옵저버의 시야 : " + observer.GetSight());
Console.WriteLine(observer);
}
}
}
Zealot.cs
using System;
namespace study01
{
public class Zealot
{
public float hp;
public Zealot()
{
Console.WriteLine("질럿 생성자 호출");
}
public float GetHp()
{
return hp;
}
}
}
Dragoon.cs
using System;
namespace study01
{
public class Dragoon
{
public int groundAttack;
public Dragoon()
{
Console.WriteLine("드라군 생성자 호출");
}
public int GetGroundAttack()
{
return groundAttack;
}
}
}
Carrier.cs
using System;
namespace study01
{
public class Carrier
{
public int armor;
public Carrier()
{
Console.WriteLine("캐리어 생성자 호출");
}
public int GetArmor()
{
return armor;
}
}
}
Arbiter.cs
using System;
namespace study01
{
public class Arbiter
{
public int maximumEnergy;
public Arbiter()
{
Console.WriteLine("아비터 생성자 호출");
}
public int GetMaximumEnergy()
{
return maximumEnergy;
}
}
}
DarkTemplar.cs
using System;
namespace study01
{
public class DarkTemplar
{
public int minerals;
public DarkTemplar()
{
Console.WriteLine("다크템플러 생성자 호출");
}
public int GetMinerals()
{
return minerals;
}
}
}
Probe.cs
using System;
namespace study01
{
public class Probe
{
public string producedFrom;
public Probe()
{
Console.WriteLine("프로브 생성자 호출");
}
public string GetProducedFrom()
{
return producedFrom;
}
}
}
Reaver.cs
using System;
namespace study01
{
public class Reaver
{
public string requires;
public Reaver()
{
Console.WriteLine("리버 생성자 호출");
}
public string GetRequires()
{
return requires;
}
}
}
Scout.cs
using System;
namespace study01
{
public class Scout
{
public string size;
public Scout()
{
Console.WriteLine("스카웃 생성자 호출");
}
public string GetSize()
{
return size;
}
}
}
Shuttle.cs
using System;
namespace study01
{
public class Shuttle
{
public char hotkey;
public Shuttle()
{
Console.WriteLine("셔틀 생성자 호출");
}
public char GetHotkey()
{
return hotkey;
}
}
}
Observer.cs
using System;
namespace study01
{
public class Observer
{
public float sight;
public Observer()
{
Console.WriteLine("옵저버 생성자 호출");
}
public float GetSight()
{
return sight;
}
}
}