U E D R , A S I H C RSS

데블스캠프2010/다섯째날/Object Craft/미션2/박재홍

Difference between r1.3 and the current

@@ -1,5 +1,3 @@
Describe 데블스캠프2010/다섯째날/ObjectCraft/미션2/박재홍 here
== zerg2.c ==

{{{


zerg2.c



#include <stdio.h>


struct zergling{

	int attack;
	int defense;
	int HP;

};
int main()
{
	int dam1,dam2=0;
	struct zergling a;
	struct zergling b;

	a.attack=5;
	a.defense=0;
	a.HP=50;

	b.attack=5;
	b.defense=0;
	b.HP=50;

	dam1=a.attack-b.defense;
	dam2=b.attack-a.defense;
	
	while(a.HP && b.HP>0)
	{
		
		a.HP-=dam1;
		b.HP-=dam2;
		printf("저글링  b가 저글링 a에게 데미지 %d를 입혀 HP가 %d가 되었습니다.\n",dam1,a.HP);
		if(a.HP==0)
			break;
		printf("저글링  a가 저글링 b에게 데미지 %d를 입혀 HP가 %d가 되었습니다.\n",dam2,b.HP);

		


	}

	printf("저글링 a가 죽었습니다ㅠㅠ.\n");

	return 0;
		

}



zerg.cpp


#include <stdio.h>


struct zergling{

	int attack;
	int defense;
	int HP;
	int no;

}a,b;
void setup(){

	a.attack=5;
	a.defense=0;
	a.HP=50;
	a.no=1;
	

	b.attack=5;
	b.defense=0;
	b.HP=50;
	b.no=2;
}
int get_damage(zergling a, zergling b){

	return a.attack-b.defense;
}

void att(zergling & a, zergling &b){

	int damage= get_damage(a,b);

	b.HP-=damage;

	printf("저글링 %d이 저글링 %d에게 데미지 %d를 입혀 HP가 %d가 되었습니다.\n",a.no,b.no,damage,b.HP);

}


int main()
{
	setup();
	while(1)
	{
		att(a,b);

		if(b.HP==0){
		printf("저글링 %d이 죽었습니다\n",b.no);
		break;
		}

		att(b,a);

		if(a.HP==0){
		printf("저글링 %d가 죽었습니다\n",a.no);
		break;
		}


	}
	return 0;
		

}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:10
Processing time 0.0334 sec