Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

데블스캠프2010/다섯째날/ObjectCraft/미션3/김상호: Difference between revisions

From ZeroWiki
imported>rlaace423
No edit summary
 
imported>rlaace423
No edit summary
Line 1: Line 1:
#include<stdio.h>
#include&lt;stdlib.h&gt;
#include<stdlib.h>
#include&lt;time.h&gt;
#include<time.h>
#define NUM 4
#define NUM 4
typedef struct z{
typedef struct z{
int gong;
int gong;
int bang;
int bang;
int hp;
int hp;
int name;
int name;
}unit;
}unit;
 
void attack(unit a, unit &amp;b)
void attack(unit a, unit &b)
{
{
if(b.hp&lt;=0 || a.hp&lt;=0)
if(b.hp<=0 || a.hp<=0)
return;
return;
b.hp -=a.gong;
b.hp -=a.gong;
printf("저글링 %d이 저글링 %d에게 데미지 %d를 입혀 HP가 %d가 되었다.\n", a.name, b.name, a.gong, b.hp);
printf("저글링 %d이 저글링 %d에게 데미지 %d를 입혀 HP가 %d가 되었다.\n", a.name, b.name, a.gong, b.hp);
if(b.hp==0)
if(b.hp==0)
printf("저글링 %d이 전사했습니다.\n", b.name);
printf("저글링 %d이 전사했습니다.\n", b.name);
}
}
void init_unit(unit a[NUM]){
void init_unit(unit a[[NUM]]){
int n;
int n;
for(n=0 ; n&lt;NUM ; n++){
for(n=0 ; n<NUM ; n++){
a[n].gong=5;
a&#91;n&#93;.gong=5;
a[n].bang=0;
a&#91;n&#93;.bang=0;
a[n].hp=50;
a&#91;n&#93;.hp=50;
a[n].name=n;
a&#91;n&#93;.name=n;
}
}
}
}
int main()
int main()
{
{
unit a[NUM];
unit a[[NUM]];
init_unit(a);
init_unit(a);
int sel;
int sel;
 
 
srand(time(NULL));
srand(time(NULL));
while(!((a[0].hp&lt;=0 &amp;&amp; a[1].hp&lt;=0) || (a[2].hp&lt;=0 &amp;&amp; a[3].hp&lt;=0))) //0과 1이 죽으면 끝or 2와 3이 죽으면 끝
while(!((a&#91;0&#93;.hp<=0 && a&#91;1&#93;.hp<=0) || (a&#91;2&#93;.hp<=0 && a&#91;3&#93;.hp<=0))) //0과 1이 죽으면 끝or 2와 3이 죽으면 끝
{
{
 
sel=rand()%(NUM*2);
sel=rand()%(NUM*2);
int attackerTeam = rand() % 2;
int attackerTeam = rand() % 2;
int attackerUnit = rand() % 2;
int attackerUnit = rand() % 2;
int defenderunit = rand() % 2;
int defenderunit = rand() % 2;
attack(a[attackerTeam * 2 + attackerUnit],a[(!attackerTeam) * 2 + defenderunit]);
attack(a[[attackerTeam * 2 + attackerUnit]],a[[(!attackerTeam) * 2 + defenderunit]]);
}
}
if(a[0].hp&lt;=0 &amp;&amp; a[1].hp&lt;=0)
if(a&#91;0&#93;.hp<=0 && a&#91;1&#93;.hp<=0)
printf("뒷 팀이 이겼습니다!!\n");
printf("뒷 팀이 이겼습니다!!\n");
if(a[2].hp&lt;=0 &amp;&amp; a[3].hp&lt;=0)
if(a&#91;2&#93;.hp<=0 && a&#91;3&#93;.hp<=0)
printf("앞 팀이 이겼습니다!!\n");
printf("앞 팀이 이겼습니다!!\n");
 
return 0;
return 0;
}
}



Revision as of 06:52, 26 June 2010

#include<stdlib.h>
#include<time.h>
#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<NUM ; n++){
		a[n].gong=5;
		a[n].bang=0;
		a[n].hp=50;
		a[n].name=n;
	}
}
int main()
{	
	unit a[NUM];
	init_unit(a);
	int sel;


	srand(time(NULL));
	while(!((a[0].hp<=0 && a[1].hp<=0) || (a[2].hp<=0 && a[3].hp<=0))) //0과 1이 죽으면 끝or 2와 3이 죽으면 끝
	{

		sel=rand()%(NUM*2);
		int attackerTeam = rand() % 2;
		int attackerUnit = rand() % 2;
		int defenderunit = rand() % 2;
	
		attack(a[attackerTeam * 2 + attackerUnit],a[(!attackerTeam) * 2 + defenderunit]);
	}
	if(a[0].hp<=0 && a[1].hp<=0)
		printf("뒷 팀이 이겼습니다!!\n");
	if(a[2].hp<=0 && a[3].hp<=0)
		printf("앞 팀이 이겼습니다!!\n");

	return 0;
}