HomeCar Game coding for Dev C++ Car Game coding for Dev C++ byHimanshu Sharma •June 27, 2021 0 Car Game coding for Dev C++ Game Play Method Game ScreenshotStep 1: Press one (1) to start the game.Step 2 : Press ( A Key - left ) and ( D Key - Right ) Copy Code and Paste for Dev C++ #include #include #include #include #include #define SCREEN_WIDTH 90 #define SCREEN_HEIGHT 26 #define WIN_WIDTH 70 using namespace std; HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); COORD CursorPosition; int enemyY[3]; int enemyX[3]; int enemyFlag[3]; char car[4][4] = { ' ','±','±',' ', '±','±','±','±', ' ','±','±',' ', '±','±','±','±' }; int carPos = WIN_WIDTH/2; int score = 0; void gotoxy(int x, int y){ CursorPosition.X = x; CursorPosition.Y = y; SetConsoleCursorPosition(console, CursorPosition); } void setcursor(bool visible, DWORD size) { if(size == 0) size = 20; CONSOLE_CURSOR_INFO lpCursor; lpCursor.bVisible = visible; lpCursor.dwSize = size; SetConsoleCursorInfo(console,&lpCursor); } void drawBorder(){ for(int i=0; i= 23 ){ if( enemyX[0] + 4 - carPos >= 0 && enemyX[0] + 4 - carPos < 9 ){ return 1; } } return 0; } void gameover(){ system("cls"); cout< 18 ) carPos -= 4; } if( ch=='d' || ch=='D' ){ if( carPos < 50 ) 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(); } if( enemyY[1] > SCREEN_HEIGHT-4 ){ resetEnemy(1); score++; updateScore(); } } } int main() { setcursor(0,0); srand( (unsigned)time(NULL)); do{ system("cls"); gotoxy(10,5); cout<<" -------------------------- "; gotoxy(10,6); cout<<" | Car Game | "; gotoxy(10,7); cout<<" --------------------------"; gotoxy(10,9); cout<<"1. Start Game"; gotoxy(10,10); cout<<"2. Instructions"; gotoxy(10,11); cout<<"3. Quit"; gotoxy(10,13); cout<<"Select option: "; char op = getche(); if( op=='1') play(); else if( op=='2') instructions(); else if( op=='3') exit(0); }while(1); return 0; } Thank You Tags: Car Game coding for Dev C++ Facebook Twitter