C#/수업 과제
클래스 과제1
HSH12345
2023. 1. 4. 21:39
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _230104
{
class Program
{
static void Main(string[] args)
{
App app = new App();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _230104
{
class App
{
enum UnitType
{
None = -1,
Upper,
Lower
}
//생성자
public App()
{
Goliath goliath = new Goliath();
//상태 출력
Console.WriteLine("유닛 이름 : {0}\n", goliath.name);
Console.WriteLine("생명력 {0}/{1}", goliath.maxHp, goliath.hp);
Console.WriteLine("이동속도 : {0}", goliath.moveSpeed);
Console.WriteLine("지상 공격력 : {0}", goliath.lowerDmg);
Console.WriteLine("공중 공격력 : {0}\n", goliath.upperDmg);
//기능 출력
goliath.Move();
goliath.Att(Convert.ToInt32(UnitType.Upper));
goliath.Att(Convert.ToInt32(UnitType.Lower));
goliath.Att(Convert.ToInt32(UnitType.None));
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _230104
{
class Goliath
{
public string name = "골리앗";
public int maxHp = 125;
public int hp = 125;
public int upperDmg = 20;
public int lowerDmg = 12;
public float moveSpeed = 2.2f;
//생성자
public Goliath()
{
}
public void Move()
{
Console.WriteLine("{0}의 속도로 이동하였습니다.", this.moveSpeed);
}
public void Att(int unitType)
{
if(unitType == 0)
{
Console.WriteLine("공중 유닛을 공격({0})하였습니다.", this.upperDmg);
}
else if(unitType == 1)
{
Console.WriteLine("지상 유닛을 공격({0})하였습니다.", this.lowerDmg);
}
else
{
Console.WriteLine("공격할 수 없습니다.");
}
}
}
}