using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Starcraft
{
internal class App
{
//생성자
public App()
{
Marine marine = new Marine(40, 6, 1.81f, 5, 0);
marine.HitDamage(3);
Medic medic = new Medic(60,5.8f,1.8f);
medic.Heal(marine);
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace Starcraft
{
internal class Marine
{
//멤버 변수 : 객체의 생명주기동안 유지된다.
public float hp;
int damage;
float moveSpeed;
int x;
int y;
//생성자
public Marine(float hp, int damage, float moveSpeed, int x, int y)
{
this.hp = hp;
this.damage = damage;
this.moveSpeed = moveSpeed;
this.x = x;
this.y = y;
Console.WriteLine("마린이 생성되었습니다.");
Console.WriteLine("위치: {0},{1}", this.x, this.y);
Console.WriteLine("생명력: {0}",this.hp);
Console.WriteLine("공격력: {0}", this.damage);
Console.WriteLine("이동속도: {0}", this.moveSpeed);
}
public void Move(int x, int y) //이동 목표 좌표
{
//(5, 0) -> (x, y)
Console.WriteLine("({0},{1}) -> ({2},{3})",this.x,this.y,x,y);
this.x = x;
this.y = y;
}
public void Attack(Zergling target)
{
Console.WriteLine("{0}을 공격했습니다.",target);
target.HitDamage(this,this.damage);
}
public void HitDamage(int damage)
{
this.hp -= damage;
Console.WriteLine("피해를 받았습니다. 생명력: {0}", this.hp);
}
public void IncreaseHp(float heal)
{
if (this.hp + heal > 40)
{
this.hp = 40;
}
else
{
this.hp += heal;
}
Console.WriteLine("마린이 치유되었습니다.");
Console.WriteLine("마린의 현재 체력 {0}", this.hp);
}
public void PrintProperties()
{
Console.WriteLine("생명력: {0}", this.hp);
Console.WriteLine("공격력: {0}", this.damage);
Console.WriteLine("이동속도: {0}", this.moveSpeed);
Console.WriteLine("위치: {0},{1}", this.x, this.y);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Starcraft
{
internal class Medic
{
int hp;
float heal;
float moveSpeed;
//생성자
public Medic(int hp, float heal, float moveSpeed)
{
this.hp = hp;
this.heal = heal;
this.moveSpeed = moveSpeed;
}
void MoveStop()
{
this.moveSpeed = 0;
Console.WriteLine("정지 했습니다.");
}
void Move()
{
this.moveSpeed = 1.875f;
Console.WriteLine("이동 했습니다.");
}
public void Heal(Marine target)
{
target.IncreaseHp(this.heal);
Console.WriteLine("치료 했습니다.");
}
void Die()
{
Console.WriteLine("사망 했습니다.");
}
public void PrintProperties()
{
Console.WriteLine("생명력: {0}", this.hp);
Console.WriteLine("이동속도: {0}", this.moveSpeed);
}
}
}