C Cgame
C Cgame
#include<conio.h>
#include <windows.h>
#include <time.h>
#define SCREEN_WIDTH 90
#define SCREEN_HEIGHT 26
#define WIN_WIDTH 70
COORD CursorPosition;
int enemyY[3];
int enemyX[3];
int enemyFlag[3];
'|','|','|','|',
'|','|','|','|' };
int score = 0;
CursorPosition.X = x;
CursorPosition.Y = y;
SetConsoleCursorPosition(console, CursorPosition);
}
void drawBorder(){
gotoxy(0+j,i); cout<<"|";
gotoxy(WIN_WIDTH-j,i); cout<<"|";
gotoxy(SCREEN_WIDTH,i); cout<<"|";
void updateScore(){
enemyX[ind] = 17 + rand()%(33);
void drawCar(){
}
}
int collision(){
return 1;
return 0;
void gameover(){
system("cls");
cout<<endl;
cout<<"\t\t--------------------------"<<endl;
cout<<"\t\t--------------------------"<<endl<<endl;
getch();
}
void eraseCar(){
eraseEnemy(ind);
enemyY[ind] = 1;
genEnemy(ind);
void play(){
carPos = -1 + WIN_WIDTH/2;
score = 0;
enemyFlag[0] = 1;
enemyFlag[1] = 0;
enemyY[0] = enemyY[1] = 1;
system("cls");
drawBorder();
updateScore();
genEnemy(0);
genEnemy(1);
gotoxy(WIN_WIDTH + 6, 4);cout<<"----------";
gotoxy(WIN_WIDTH + 6, 6);cout<<"----------";
getch();
while(true){
if(kbhit()){
char ch = getch();
carPos -= 4;
carPos += 4;
}
if(ch==27){
break;
drawCar();
drawEnemy(0);
drawEnemy(1);
if( collision() == 1 ){
gameover();
return;
Sleep(50);
eraseCar();
eraseEnemy(0);
eraseEnemy(1);
if( enemyY[0] == 10 )
if( enemyFlag[1] == 0 )
enemyFlag[1] = 1;
if( enemyFlag[0] == 1 )
enemyY[0] += 1;
if( enemyFlag[1] == 1 )
enemyY[1] += 1;
if( enemyY[0] > SCREEN_HEIGHT-4 ){
resetEnemy(0);
score++;
updateScore();
resetEnemy(1);
score++;
updateScore();
if(size == 0)
size = 20;
CONSOLE_CURSOR_INFO lpCursor;
lpCursor.bVisible = visible;
lpCursor.dwSize = size;
SetConsoleCursorInfo(console,&lpCursor);
int main()
setcursor(0,0);
srand( (unsigned)time(NULL));
do{
system("cls");
char op = getche();
else if( op=='2') cout << "'a' for left \n'd' for right ";
}while(true);
return 0;