메인메서드
using System;
class Program
{
public static SiegeTank siegeTank;
public static Vulture vulture;
static void Main(string[] args)
{
siegeTank = new SiegeTank();
vulture = new Vulture();
Console.WriteLine();
Console.WriteLine("탱크 인스턴스: {0}", siegeTank);
Console.WriteLine("벌쳐 인스턴스: {0}", vulture);
bool isDie = false;
while (isDie != true)
{
if (siegeTank.hp > 0)
{
Console.WriteLine();
vulture.Attack(siegeTank);
isDie = siegeTank.Hit(vulture);
}
if (vulture.hp > 0)
{
Console.WriteLine();
siegeTank.Attack(vulture);
isDie = vulture.Hit(siegeTank);
}
}
Console.WriteLine();
Console.WriteLine("탱크 인스턴스: {0}", siegeTank);
Console.WriteLine("벌쳐 인스턴스: {0}", vulture);
Console.WriteLine();
Console.WriteLine("탱크 체력: {0}/{1}", siegeTank.hp, siegeTank.maxHp);
Console.ReadLine();
}
}
시즈탱크
using System;
class SiegeTank
{
public int maxHp = 150;
public int hp = 150;
public int damage = 30;
//생성자
public SiegeTank()
{
Console.WriteLine("{0}가 생성되었습니다. hp:{1}, damage:{2}", this, this.hp, this.damage);
}
public void Attack(Vulture target)
{
Console.WriteLine("{0}가 {1}을 공격합니다.", this, target);
}
public bool Hit(Vulture enermy)
{
if (this.hp > 0)
{
this.hp -= enermy.damage;
Console.WriteLine("{0}가 {1}로부터 공격받았습니다.", this, enermy);
if (this.hp <= 0)
{
this.hp = 0;
Console.WriteLine("현재 체력: {0}/{1}", this.hp, this.maxHp);
return Die();
}
else
{
Console.WriteLine("현재 체력: {0}/{1}", this.hp, this.maxHp);
return false;
}
}
else
{
return true;
}
}
private bool Die()
{
Console.WriteLine("{0}가 죽었습니다.", this);
Program.siegeTank = null;
return true;
}
}
벌쳐
using System;
class Vulture
{
private int maxHp = 80;
public int hp = 80;
public int damage = 20;
//생성자
public Vulture()
{
Console.WriteLine("{0}가 생성되었습니다. 체력:{1}, 공격력:{2}", this, this.hp, this.damage);
}
public void Attack(SiegeTank target)
{
Console.WriteLine("{0}가 {1}을 공격합니다.", this, target);
}
public bool Hit(SiegeTank enermy)
{
if (this.hp > 0)
{
this.hp -= enermy.damage;
Console.WriteLine("{0}가 {1}로부터 공격받았습니다.", this, enermy);
if (this.hp <= 0)
{
this.hp = 0;
Console.WriteLine("현재 체력: {0}/{1}", this.hp, this.maxHp);
return Die();
}
else
{
Console.WriteLine("현재 체력: {0}/{1}", this.hp, this.maxHp);
return false;
}
}
else
{
return true;
}
}
private bool Die()
{
Console.WriteLine("{0}가 죽었습니다.", this);
Program.vulture = null;
return true;
}
}
'C# > 수업 과제' 카테고리의 다른 글
스레드 SCV Work 공유자원 동기화 (0) | 2021.12.24 |
---|---|
OX퀴즈 (0) | 2021.12.24 |
건물건설과 유닛생산 (0) | 2021.12.24 |
마린2를 공격하는 마린1 (0) | 2021.12.24 |
마린생산-미네랄 감소 (0) | 2021.12.24 |