= class 사용 전 = {{{#include #include #include #define NUM 4 typedef struct z{ int gong; int bang; int hp; int name; }unit; void attack(unit a, unit &b) { if(b.hp<=0 || a.hp<=0) return; b.hp -=a.gong; printf("저글링 %d이 저글링 %d에게 데미지 %d를 입혀 HP가 %d가 되었다.\n", a.name, b.name, a.gong, b.hp); if(b.hp==0) printf("저글링 %d이 전사했습니다.\n", b.name); } void init_unit(unit a[NUM]){ int n; for(n=0 ; n #include #include #include"unit.h" #define NUM 4 int main() { unit a[NUM]; for(int i=0 ; i void unit::attack(unit &b) { if(b.hp<=0 || this->hp<=0) return; b.hp -=this->gong; printf("저글링 %d이 저글링 %d에게 데미지 %d를 입혀 HP가 %d가 되었다.\n", this->name, b.name, this->gong, b.hp); if(b.hp==0) printf("저글링 %d이 전사했습니다.\n", b.name); } void unit::init_unit(int n){ this->gong=5; this->bang=0; this->hp=50; this->name=n; } bool unit::is_dead() { if(this->hp<=0) return true; else return false; }}}} == unit.h == {{{ class unit{ int gong; int bang; int hp; int name; public: void attack(unit &b); void init_unit(int n); bool is_dead(); };}}}