메인메서드
using System;
class Program
{
public static int amountMineral = 50;
static void Main(string[] args)
{
Barracks barracks = new Barracks(3, 5);
while (true)
{
Console.WriteLine("현재 미네랄량: {0}", amountMineral);
Console.Write("숫자입력 (1.유닛생산 2.미네랄량에디트 나머지: 종료) : ");
string selected = Console.ReadLine();
if (selected == "1")
{
Console.Write("숫자입력 (1.마린 2.파뱃 3.고스트 4.메딕) : ");
int inputNum = Convert.ToInt32(Console.ReadLine());
if (inputNum == 1)
{
Marine marine = (Marine)barracks.CreateUnit(Barracks.eUnitType.Marine);
}
}
else if (selected == "2")
{
Console.Write("미네랄량 입력 : ");
amountMineral = Convert.ToInt32(Console.ReadLine());
}
else
{
break;
}
}
}
}
병영 클래스
using System;
class Barracks : Building
{
public enum eUnitType
{
Marine, Firebat, Ghost, Medic
}
private int x;
private int y;
//생성자
public Barracks(int x, int y) : base(x, y)
{
this.x = x;
this.y = y;
}
public Unit CreateUnit(eUnitType unit)
{
if (unit == eUnitType.Marine)
{
if (Program.amountMineral >= 50)
{
Program.amountMineral -= 50;
return new Marine(40, 6);
}
else
{
Console.WriteLine("미네랄이 부족합니다.");
return null;
}
}
else
{
return null;
}
}
}
마린 클래스
using System;
class Marine : Unit
{
private int hp;
private int damage;
//생성자
public Marine(int hp, int damage)
{
this.hp = hp;
this.damage = damage;
Console.WriteLine("체력: {0}, 공격력: {1}", this.hp, this.damage);
}
public void Attack()
{
}
}
이어서 생성한 두번째 세번째 개체를 자동으로 새로운 변수에 넣는다든가 해서
마린끼리의 전투까지 하고싶은데 방법을 모르겠다. 가능하긴할까?
'C# > 수업 과제' 카테고리의 다른 글
건물건설과 유닛생산 (0) | 2021.12.24 |
---|---|
마린2를 공격하는 마린1 (0) | 2021.12.24 |
SCV 미네랄캐고 건물짓기 (0) | 2021.12.24 |
클래스 생성과 인스턴스 생성 및 메서드 연습 과제 (0) | 2021.12.24 |
클래스 및 인스턴스 만들기와 메서드 연습6 (히드라-러커) (0) | 2021.12.23 |