C#
대리자 연습 1,2
송현호
2023. 7. 27. 14:40
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
namespace Starcraft
{
public class App
{
//생성자
public App()
{
Hero hero = new Hero();
hero.HitDamage(3, (hp, maxHp) =>
{
Console.WriteLine("{0}/{1}", hp, maxHp);
});
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Starcraft
{
public class Hero
{
int hp;
int maxHp = 40;
public Hero()
{
hp = maxHp;
}
public void HitDamage(int damage, Action<int, int> hit)
{
Console.WriteLine("공격받았습니다.");
this.hp -= damage;
hit(this.hp, this.maxHp);
}
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
namespace Starcraft
{
public class App
{
//생성자
public App()
{
Hero hero = new Hero();
hero.HitDamage(3, (isDie) =>
{
Console.WriteLine("isDie: {0}",isDie);
});
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Starcraft
{
public class Hero
{
int hp;
int maxHp = 40;
public Hero()
{
hp = maxHp;
}
public void HitDamage(int damage, Action<string> callback)
{
this.hp -= damage;
if(this.hp < 0)
{
callback("죽었습니다.");
}
else {
callback("안죽었습니다.");
}
}
}
}