U E D R , A S I H C RSS

데블스캠프2010/다섯째날/Object Craft/미션1/서민관

메인함수

#include <iostream>
#include "zergling.h"

int main(void)
{
	zergling* z1 = createZergling();
	zergling* z2 = createZergling();

	attack(z1, z2);
}

zergling.cpp

#include <iostream>
#include "zergling.h"

using namespace std;

zergling* createZergling()
{
	zergling* z1 = (zergling*)malloc(sizeof(zergling));
	z1->atk = 5;
	z1->def = 0;
	z1->HP = 50;

	return z1;
}

void attack(zergling* z1, zergling* z2)
{
	//sleep(1000);

	for ( ; z2->HP != 0 ; )
	{
		if ( z2->HP == 0 )
		{
			cout << "z2가 죽었습니다." << endl;
			return;
		}
		cout << "z1이 z2에게 데미지 " << z1->atk << "를 입혀 HP가 " << z2->HP << "가 되었다." << endl;
		z2->HP -= z1->atk;
	}
}

zergling.h

typedef struct zergling
{
	int atk;
	int def;
	int HP;
} zergling;

zergling* createZergling();
void attack(zergling* z1, zergling* z2);
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:10
Processing time 0.0129 sec