U E D R , A S I H C RSS

데블스캠프2010/다섯째날/ObjectCraft/미션2/서민관 (rev. 1.1)

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

메인함수

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

int main(void)
{
	//zergling** z = NULL;
	//z[0] = createZergling();
	//z[1] = createZergling();

	zergling* z1 = createZergling();
	zergling* z2 = createZergling();

	// attack(z1, z2);

	fight(z1, z2);
}

zergling.cpp

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

using namespace std;

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

	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;
	}
}

void fight(zergling* z1, zergling* z2)
{
	while ( z1->HP != 0 && z2->HP != 0 )
	{
		cout << "z1이 z2에게 데미지 " << z1->atk << "를 입혀 HP가 " << z2->HP << "가 되었다." << endl;
		z2->HP -= z1->atk;
		cout << "z2가 z1에게 데미지 " << z2->atk << "를 입혀 HP가 " << z1->HP << "가 되었다." << endl;
		z1->HP -= z2->atk;
	}
}

void fight2(zergling** z)
{
	z[0]->number = 0;
	z[1]->number = 1;

	while ( z[0]->HP != 0 && z[1]->HP != 0 )
	{
		cout << "저글링" << z[0]->number << "이 z2에게 데미지 " << z[0]->atk << "를 입혀 HP가 " << z[0]->HP << "가 되었다." << endl;
		z[1]->HP -= z[0]->atk;
		cout << "저글링" << z[1]->number << "z2가 z1에게 데미지 " << z[1]->atk << "를 입혀 HP가 " << z[1]->HP << "가 되었다." << endl;
		z[0]->HP -= z[1]->atk;
	}
}

zergling.h

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

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