U E D R , A S I H C RSS

데블스캠프2010/다섯째날/Object Craft/미션2/강소현

Difference between r1.1 and the current

@@ -1,4 +1,5 @@
Describe 데블스캠프2010/다섯째날/ObjectCraft/미션2/강소현 here
== before ==
{{{
#include <stdio.h>
#include <stdlib.h>
@@ -28,4 +29,59 @@
printf("게임 끝 ㅇㅇ\n");
return 0;
}
}}}
== after ==
{{{
#include <stdio.h>
#include <stdlib.h>
#include<time.h>
typedef struct zergling{
char *name;
int attack;
int protect;
int HP;
}zerg;
void init(zerg *newZerg, zerg *newZerg2){
newZerg->name="ㅡㅁㅡ";
newZerg->HP = 50;
newZerg->attack = 5;
newZerg->protect = 0;
 
newZerg2->name="ㅇㅁㅇ";
newZerg2->HP = 50;
newZerg2->attack = 5;
newZerg2->protect = 0;
 
srand((unsigned)time(NULL));
}
int order(){
 
int ordering = (int) rand() % 2;
return ordering;
}
 
void AAttackB(zerg *a, zerg *b){
if(order() == 0){
b->HP -= a->attack;
printf("%s가 %s에게 데미지 %d를 입혀 HP가 %d가 되었다.\n",a->name, b->name, a->attack, b->HP);
}else{
a->HP -= b->attack;
printf("%s가 %s에게 데미지 %d를 입혀 HP가 %d가 되었다.\n",b->name, a->name, b->attack, a->HP);
}
}
bool isDead(zerg a, zerg b){
return a.HP > 0 && b.HP >0;
}
int main(){
zerg zerg1, zerg2;
init(&zerg1, &zerg2);
while(isDead(zerg1, zerg2)){
AAttackB(&zerg1,&zerg2);
}
puts("---------------------------------------------------");
printf("게임 끝 ㅇㅇ\n");
return 0;
}
}}}


Describe 데블스캠프2010/다섯째날/ObjectCraft/미션2/강소현 here

before

#include <stdio.h>
#include <stdlib.h>
typedef struct zergling{
	char *name;
	int attack;
	int protect;
	int HP;
}zerg;
void AAttackB(zerg *a, zerg *b){
	b->HP -= a->attack;
}
int main(){
	zerg zerg1={"저그1",5,0,50}, zerg2={"저그2",5,0,50};
	int order;
	while(zerg2.HP > 0 && zerg1.HP >0){
		order = (int) rand() % 2;
		if(order == 0){
			AAttackB(&zerg1,&zerg2);
			printf("%s가 %s에게 데미지 %d를 입혀 HP가 %d가 되었다.\n",zerg1.name, zerg2.name, zerg1.attack, zerg2.HP);
		}else{
			AAttackB(&zerg2,&zerg1);
			printf("%s가 %s에게 데미지 %d를 입혀 HP가 %d가 되었다.\n",zerg2.name, zerg1.name, zerg2.attack, zerg1.HP);
		}
	}
	puts("--------------------------------------------------");
	printf("게임 끝 ㅇㅇ\n");
	return 0;
}

after

#include <stdio.h>
#include <stdlib.h>
#include<time.h>
typedef struct zergling{
	char *name;
	int attack;
	int protect;
	int HP;
}zerg;
void init(zerg *newZerg, zerg *newZerg2){
	newZerg->name="ㅡㅁㅡ";
	newZerg->HP = 50;
	newZerg->attack = 5;
	newZerg->protect = 0;

	newZerg2->name="ㅇㅁㅇ";
	newZerg2->HP = 50;
	newZerg2->attack = 5;
	newZerg2->protect = 0;

	srand((unsigned)time(NULL));
}
int order(){

	int ordering = (int) rand() % 2;
	return ordering;
}

void AAttackB(zerg *a, zerg *b){
	
	if(order() == 0){
		b->HP -= a->attack;
		printf("%s가 %s에게 데미지 %d를 입혀 HP가 %d가 되었다.\n",a->name, b->name, a->attack, b->HP);
	}else{
		a->HP -= b->attack;
		printf("%s가 %s에게 데미지 %d를 입혀 HP가 %d가 되었다.\n",b->name, a->name, b->attack, a->HP);
	}
}
bool isDead(zerg a, zerg b){
	return a.HP > 0 && b.HP >0;
}
int main(){
	zerg zerg1, zerg2;
	init(&zerg1, &zerg2);
	
	while(isDead(zerg1, zerg2)){
		AAttackB(&zerg1,&zerg2);
	}
	puts("---------------------------------------------------");
	printf("게임 끝 ㅇㅇ\n");
	return 0;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:10
Processing time 0.0210 sec