using System;
namespace Study04
{
class Program
{
static void Main(string[] args)
{
new App();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Study04
{
class App
{
public App()
{
SiegeTank tank = new SiegeTank(150,30,1);
tank.Move();
tank.ChangeMode();
Console.WriteLine("공격력:{0}",tank.damage);
tank.Move();
tank.ChangeMode();
Console.WriteLine("공격력:{0}",tank.damage);
tank.Move();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Study04
{
class SiegeTank
{
public enum ModeType
{
TANK, //탱크
SIEGE //공성
}
//멤버 변수
public ModeType modeType;
public int damage;
int hp;
int armor;
//생성자
public SiegeTank(int hp, int damage, int armor)
{
this.modeType = ModeType.TANK;
this.damage = damage;
this.hp = hp;
this.armor = armor;
Console.WriteLine("탱크가 생성되었습니다");
Console.WriteLine("체력:{0}, 공격력:{1}, 방어력:{2}",this.hp,this.damage,this.armor);
}
//멤버 메서드
public void ChangeMode()
{
if (this.modeType == ModeType.TANK)
{
Console.WriteLine("{0}모드에서 {1}모드로 전환합니다", this.modeType, ModeType.SIEGE);
this.modeType = ModeType.SIEGE;
this.damage = 70;
}
else
{
Console.WriteLine("{0}모드에서 {1}모드로 전환합니다", this.modeType, ModeType.TANK);
this.modeType = ModeType.TANK;
this.damage = 30;
}
}
public void Move()
{
if (this.modeType == ModeType.TANK)
{
Console.WriteLine("이동했습니다");
}
else
{
Console.WriteLine("이동할 수 없습니다");
}
}
}
}