Hello guyz im trying to create "game" in lang. c. I create 2d string where i randomly put '*' and i move the char '&' by arrows. Ss there some possible way how can i do something when the '&' hit '*'?
Thanks (under is my code)
Code:
#include<stdio.h>
#include<conio.h>
#include<windows.h>
#include<stdlib.h>
#include<time.h>
#define KeyUp 72
#define KeyLeft 75
#define KeyRight 77
#define KeyEsc 27
#define KeyDown 80
void gotoxy (short x, short y)
{
COORD pos = {x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
int main()
{
printf("VITAJ V HRE THE METEOR!\n");
printf("TVOJOU ULOHOU JE PREJST CEZ PADAJUCE METEORITY!\n");
printf("SI READY?(stlac lub.klavesu)");
getch();
system("cls");
printf("START!(hru ukoncis stlacenim klavesy ESC)");
Sleep(3000);
system("cls");
int i,r;
int x=8,y=7;
int x1=1,y1=1;
int ch,k=0;
char field[7][20]={"-----------------",//pole
" ",
" ",
" ",
" ",
" ",
" ",
" "};
for(i=0;i<7;i++)//vypis pola
{
printf("%s\n",field[i]);
}
for(i=0;i<=15;i++)
{
x1=rand()%15+1;
y1=rand()%5+2;
gotoxy(x1,y1);
printf("*");
Sleep(100);
}
while(k!=2)
{
while(k!=1)
{
gotoxy(x,y);printf("&");
ch=getch();
switch(ch)
{
case KeyUp:if(y>1)y--;k++;break;
case KeyDown:if(y<7)y++;k++;break;
case KeyLeft:if(x>0)x--;k++;break;
case KeyRight:if(x<16)x++;k++;break;
case KeyEsc:k++;k++;break;
}
}
if(k==2)
{
system("cls");
printf("UKONCIL SI HRU!");
Sleep(1000);
return 0;
}
k=0;
}
}