#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <Windows.h>
#include <time.h>
void gotoxy(int x, int y)
{
COORD pos={x-1, y-1};
SetConsoleCursorPosition(
GetStdHandle(STD_OUTPUT_HANDLE),
pos);
}
void draw_rectangle(int r, int c)
{
unsigned char a=0xa6;
unsigned char b[7];
int i, j;
for(i=1; i<7; i++)
b[i] = 0xa0 +i;
printf("%c%c", a, b[3]);
for(i=0; i<c; i++);
printf("%c%c", a, b[1]);
printf("%c%c", a, b[4]);
printf("\n");
for(j=0; j<r; j++)
{
printf("%c%c",a, b[2]);
for(i=0;i<c; i++)
printf(" ");
printf("%c%c",a, b[2]);
printf("\n");
}
printf("%c%c",a, b[6]);
for(i=0; i<c; i++)
printf("%c%c",a, b[1]);
printf("%c%c",a, b[5]);
printf("\n");
}
void display_text(int bn, int dn)
{
gotoxy(46, 2);
printf("총알의 개수: %d", bn);
gotoxy(46, 5);
printf("맞춘 회수: %d" , dn);
}
int main(void)
{
char enemy[3] ="★";
char hero[3] = "○";
char bullet[3] = "+";
int enemy_posx;
int hero_posx=3;
int hero_dir=1;
int bullet_posy;
int ch;
int bullet_num=10;
int destory_num=0;
srand((unsigned int)time(NULL));
do{
system("cls");
draw_rectangle(20, 20);
display_text(bullet_num, destory_num);
enemy_posx = rand()5+4;
gotoxy(enemy_posx, 2);
printf("%s", enemy);
do {
do {
hero_posx += hero_dir;
if ( hero_posx > 39 )
hero_dir = -1;
else if (hero_posx < 3)
hero_dir= 1;
gotoxy(hero_posx, 21);
printf("%s", hero);
Sleep(50);
} while(!kbhit());
ch = getch();
}while( ch != 32);
bullet_num--;
bullet_posy = 21;
while(bullet_posy>2)
{
bullet_posy--;
gotoxy(hero_posx, bullet_posy);
printf("%s", bullet);
Sleep(50);
printf("\b ");
}
if ( ( enemy_posx-2) <= hero_posx &&
( enemy_posx+1) >= hero_posx )
// if( enemy_posx == hero_posx )
{
gotoxy(46,8);
printf("맞았습니다");
destory_num++;
}
else
{
gotoxy(46,8);
printf("메롱");
}
Sleep(1000);
if ( bullet_num == 0 ) break;
}while(1);
return 0;
}
이걸 빌드하면 네모난 칸에 뚜겅이 열려잇는데 어떻게 해야 고쳐질까?
댓글 0