More actions
imported>smksyj No edit summary |
imported>smksyj No edit summary |
||
| Line 9: | Line 9: | ||
//z[1] = createZergling(); | //z[1] = createZergling(); | ||
zergling* z1 = createZergling(); | zergling* z1 = createZergling(1); | ||
zergling* z2 = createZergling(); | zergling* z2 = createZergling(2); | ||
// | // fight(z1, z2); | ||
fightwith(z1, z2); | |||
return 0; | |||
} | } | ||
== zergling.cpp == | == zergling.cpp == | ||
| Line 23: | Line 24: | ||
using namespace std; | using namespace std; | ||
zergling* createZergling() | zergling* createZergling(int num) | ||
{ | { | ||
zergling* z1 = (zergling*)malloc(sizeof(zergling)); | zergling* z1 = (zergling*)malloc(sizeof(zergling)); | ||
| Line 29: | Line 30: | ||
z1->def = 0; | z1->def = 0; | ||
z1->HP = 50; | z1->HP = 50; | ||
z1->number = | z1->number = num; | ||
return z1; | return z1; | ||
| Line 37: | Line 38: | ||
{ | { | ||
//sleep(1000); | //sleep(1000); | ||
if ( z2->HP == 0 ) | |||
{ | |||
cout << z2->number << "가 죽었습니다." << endl; | |||
return; | |||
} | |||
else | |||
{ | { | ||
cout << z1->number << "이 " << z2->number << "에게 데미지 " << z1->atk << "를 입혀 HP가 " << z2->HP << "가 되었다." << endl; | |||
z2->HP -= z1->atk; | z2->HP -= z1->atk; | ||
} | } | ||
| Line 54: | Line 54: | ||
while ( z1->HP != 0 && z2->HP != 0 ) | while ( z1->HP != 0 && z2->HP != 0 ) | ||
{ | { | ||
attack(z1, z2); | |||
} | } | ||
} | } | ||
void | void fightwith(zergling* z1, zergling* z2) | ||
{ | { | ||
while ( z1->HP != 0 && z2->HP != 0 ) | |||
while ( | |||
{ | { | ||
attack(z1, z2); | |||
attack(z2, z1); | |||
} | } | ||
} | } | ||
== zergling.h == | == zergling.h == | ||
| Line 84: | Line 76: | ||
} zergling; | } zergling; | ||
zergling* createZergling(); | zergling* createZergling(int num); | ||
void attack(zergling* z1, zergling* z2); | void attack(zergling* z1, zergling* z2); | ||
void fight(zergling* z1, zergling* z2); | void fight(zergling* z1, zergling* z2); | ||
void | void fightwith(zergling* z1, zergling* z2); | ||
Revision as of 05:47, 26 June 2010
메인함수
#include <iostream>
#include "zergling.h"
int main(void)
{
//zergling** z = NULL;
//z[0] = createZergling();
//z[1] = createZergling();
zergling* z1 = createZergling(1);
zergling* z2 = createZergling(2);
// fight(z1, z2);
fightwith(z1, z2);
return 0;
}
zergling.cpp
#include <iostream>
#include "zergling.h"
#include <time.h>
using namespace std;
zergling* createZergling(int num)
{
zergling* z1 = (zergling*)malloc(sizeof(zergling));
z1->atk = 5;
z1->def = 0;
z1->HP = 50;
z1->number = num;
return z1;
}
void attack(zergling* z1, zergling* z2)
{
//sleep(1000);
if ( z2->HP == 0 )
{
cout << z2->number << "가 죽었습니다." << endl;
return;
}
else
{
cout << z1->number << "이 " << z2->number << "에게 데미지 " << z1->atk << "를 입혀 HP가 " << z2->HP << "가 되었다." << endl;
z2->HP -= z1->atk;
}
}
void fight(zergling* z1, zergling* z2)
{
while ( z1->HP != 0 && z2->HP != 0 )
{
attack(z1, z2);
}
}
void fightwith(zergling* z1, zergling* z2)
{
while ( z1->HP != 0 && z2->HP != 0 )
{
attack(z1, z2);
attack(z2, z1);
}
}
zergling.h
typedef struct zergling
{
int atk;
int def;
int HP;
int number;
} zergling;
zergling* createZergling(int num);
void attack(zergling* z1, zergling* z2);
void fight(zergling* z1, zergling* z2);
void fightwith(zergling* z1, zergling* z2);