using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace study04
{
class App
{
//생성자
public App()
{
Console.WriteLine("App");
Marine marine0 = new Marine("marine0", 60, 5);
marine0.Hit(35);
Medic medic0 = new Medic("medic0", 5.86f, 50);
medic0.Heal(marine0);
Console.WriteLine("{0}, hp: {1}/{2}", marine0.name, marine0.hp, marine0.maxHp);
Console.WriteLine("{0}, energy: {1}/{2}", medic0.name, medic0.energy, medic0.maxEnergy);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace study04
{
class Medic
{
public string name;
public int maxEnergy = 200;
public int energy;
public float heal;
//생성자
public Medic(string name, float heal, int energy)
{
this.name = name;
this.energy = energy;
this.heal = heal;
}
public void Heal(Marine target)
{
target.hp = target.hp + (int)this.heal;
this.energy = this.energy - 5;
//Console.WriteLine(this); //medic
//Console.WriteLine(target); //marine
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace study04
{
class Marine
{
//속성,맴버 변수
public int maxHp;
public string name;
public int damage;
public int hp;
//생성자 메서드
public Marine(string name, int maxHp, int damage)
{
this.name = name;
this.maxHp = maxHp;
this.hp = this.maxHp;
this.damage = damage;
Console.WriteLine("{0}이 생성되었습니다.({1}/{2})", this.name, this.hp, this.maxHp);
Console.WriteLine("공격력:{0}", this.damage);
}
//맴버 메서드
public void Attack(Marine target)
{
//Console.WriteLine(this);
//Console.WriteLine(target);
Console.WriteLine("{0}이(가){1}를 공격 했습니다.", this.name, target.name);
//target.hp = target.hp - this.damage;
//Console.WriteLine("{0} 체력 : ({1}/{2})", target.name, target.hp, target.maxHp);
target.Hit(this.damage);
}
public void Hit(int damage)
{
Console.WriteLine("피해({0})를 받았습니다.", damage);
this.hp=this.hp - damage;
Console.WriteLine("{0}체력 : {1}/{2}", this.name, this.hp, this.maxHp);
}
public void Move()
{
Console.WriteLine("이동했습니다.");
}
}
}