C++ Code
C++ Code
#include<conio.h>
#include<dos.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);
If(size == 0)
Size = 20;
CONSOLE_CURSOR_INFO lpCursor;
lpCursor.bVisible = visible;
lpCursor.dwSize = size;
SetConsoleCursorInfo(console,&lpCursor);
Void drawBorder(){
Gotoxy(0+j,i); cout<<”±”;
Gotoxy(WIN_WIDTH-j,i); cout<<”±”;
Gotoxy(SCREEN_WIDTH,i); cout<<”±”;
enemyX[ind] = 17 + rand()%(33);
eraseEnemy(ind);
enemyY[ind] = 1;
genEnemy(ind);
Void drawCar(){
Void eraseCar(){
Int collision(){
Return 1;
Return 0;
Void gameover(){
System(“cls”);
Cout<<endl;
Cout<<”\t\t--------------------------“<<endl;
Cout<<”\t\t--------------------------“<<endl<<endl;
Getch();
Void updateScore(){
Void instructions(){
System(“cls”);
Cout<<”Instructions”;
Cout<<”\n----------------“;
Getch();
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<<”----------“;
gotoxy(WIN_WIDTH + 7, 12);cout<<”Control “;
gotoxy(WIN_WIDTH + 7, 13);cout<<”-------- “;
getch();
gotoxy(18, 5);cout<<” “;
while(1){
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;
resetEnemy(0);
score++;
updateScore();
resetEnemy(1);
score++;
updateScore();
Int main()
{
Setcursor(0,0);
Srand( (unsigned)time(NULL));
Do{
System(“cls”);
Char op = getche();
}while(1);
Return 0;