├── TANK WAR ├── highestScore.txt ├── gitignore.txt └── tankwars.cpp ├── TIC TAC TOE ├── gitignore.txt └── game.cpp └── README.md /TANK WAR/highestScore.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /TANK WAR/gitignore.txt: -------------------------------------------------------------------------------- 1 | 000 2 | -------------------------------------------------------------------------------- /TIC TAC TOE/gitignore.txt: -------------------------------------------------------------------------------- 1 | 123 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MY-GAMES 2 | 3 | ## Table of Contents 4 | 5 | 1. [Overview](#overview) 6 | 2. [Games](#games) 7 | - [Tank War](#tank-war) 8 | - [Tic Tac Toe](#tic-tac-toe) 9 | 3. [Installation](#installation) 10 | 11 | 12 | ## Overview 13 | 14 | **MY-GAMES** is a repository showcasing two console-based games developed in C++: **Tank War** and **Tic Tac Toe**. Both games are designed to run in a terminal and provide a fun and interactive experience. 15 | 16 | ## Games 17 | 18 | ### Tank War 19 | 20 | - **Description**: A strategic tank battle game where players control a tank and engage in combat with enemy tanks. 21 | - **Features**: 22 | - ["Deal with multiple enemies"] 23 | 24 | - **Controls**: [Use arrows keys to move and F key to fire] 25 | 26 | ### Tic Tac Toe 27 | 28 | - **Description**: A classic Tic Tac Toe game where two players compete to align three symbols in a row. 29 | - **Features**: 30 | - ["Player vs. Player mode"] 31 | 32 | 33 | 34 | ## Installation 35 | 36 | 1. **Clone the repository:** 37 | 38 | ```bash 39 | git clone https://github.com/Ahmed8881/MY-GAMES.git 40 | cd MY-GAMES 41 | -------------------------------------------------------------------------------- /TIC TAC TOE/game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | char square[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; 7 | string setcolor(unsigned short color); 8 | int checkwin(); 9 | void board(); 10 | int main() { 11 | int choice; 12 | char mark; 13 | do { 14 | board(); 15 | setcolor(11); 16 | cout << "Player 1, enter a number: "; 17 | cin >> choice; 18 | setcolor(15); 19 | mark = 'X'; 20 | if (choice >= 1 && choice <= 9 && square[choice] == (choice + '0')) 21 | square[choice] = mark; 22 | else { 23 | cout << "Invalid move "; 24 | getch(); 25 | } 26 | int a = checkwin(); 27 | if (a == 1) { 28 | cout << "Player 1 wins"; 29 | break; 30 | } 31 | else if (a == 0) 32 | { 33 | cout << "Game draw"; 34 | break; 35 | if (choice >= 1 && choice <= 9 && square[choice] == (choice + '0')) 36 | square[choice] = mark; 37 | else { 38 | cout << "Invalid move "; 39 | getch(); 40 | } 41 | } 42 | board(); 43 | setcolor(6); 44 | cout << "Player 2, enter a number: "; 45 | cin >> choice; 46 | setcolor(2); 47 | mark = 'O'; 48 | setcolor(2); 49 | a = checkwin(); 50 | if (a == 1) { 51 | cout << "Player 2 wins"; 52 | break; 53 | } else if (a == 0) { 54 | cout << "Game draw"; 55 | break; 56 | } 57 | } 58 | while (true); 59 | 60 | getch(); 61 | return 0; 62 | } 63 | void board(){ 64 | system("cls"); 65 | setcolor(4); 66 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | void storeHighestScore(int score); 9 | int loadHighestScore(); 10 | // Function prototypes 11 | void gotoxy(int x, int y); 12 | // Player movement functions 13 | void erasetank(int &pX, int &pY); 14 | void printtank(int &pX, int &pY, string &rifle); 15 | void movestankLeft(int &pX, int &pY, string &rifle); 16 | void movetankRight(int &pX, int &pY, string &rifle, int &score); 17 | void movetankup(int &pX, int &pY, string &rifle); 18 | void movetankdown(int &pX, int &pY, string &rifle); 19 | 20 | // Enemy type 1 functions 21 | void printEnemy1(int &eX, int &eY); 22 | void eraseEnemy1(int &eX, int &eY); 23 | void moveEnemy1(int &eX, int &eY, int &pX, int &pY); 24 | // enemy 1 bullet functions 25 | void moveEnemyBullets(int &ex, int &ey, int &pX, int &pY); 26 | 27 | // Enemy type 2 functions 28 | void printEnemy2(int &ex, int &ey); 29 | void eraseEnemy2(int &ex, int &ey); 30 | void moveEnemy2(int &ex, int &ey); 31 | // enemy 2 bullet functions 32 | void moveEnemyBullet(int &ex, int &ey, int &pX, int &pY); 33 | void removeEnemyBullet(); 34 | void drawEnemyBullet(); 35 | 36 | // Enemy type 3 functions 37 | void printEnemy3(int &EX, int &EY); 38 | void eraseEnemy3(int &EX, int &EY); 39 | void moveEnemy3(int &EX, int &EY); 40 | // enemy 3 bullet functions 41 | void drawEnemyBullet3(); 42 | void moveEnemyBullet3(int &ex, int &ey, int &pX, int &pY); 43 | void removeEnemyBullet3(); 44 | 45 | // Bullet functions 46 | void moveBullet(int &ex, int &ey, int &eX, int &eY, int &EX, int &EY, int &score); 47 | void removeBullet(); 48 | void drawBullet(); 49 | 50 | // World-related functions 51 | void printWorld(); 52 | char getCharAtxy(short int x, short int y); 53 | 54 | // Character and color generation functions 55 | void generateCharacters(); 56 | void generateColors(); 57 | 58 | // Other game-related functions 59 | int isAlphabet(string value); 60 | void moveBullet(); 61 | void shootBullet(int pX, int pY); 62 | void display(); 63 | void win(); 64 | void gameover(); 65 | 66 | void controls(); 67 | 68 | // Color constants 69 | string setcolor(unsigned short color) 70 | { 71 | HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE); 72 | SetConsoleTextAttribute(hcon, color); 73 | return ""; 74 | } 75 | int bulletX = 0; 76 | int highestScore = 0; 77 | int black = 0, blue = 1, green = 2, cyan = 3, red = 4, magenta = 5, brown = 6, lightwhite = 7, darkwhite = 8, lightblue = 9, lightgreen = 10, lightcyan = 11, lightred = 12, lightmagenta = 13, yellow = 14, white = 15; 78 | int prevBulletX=0; 79 | int prevBulletY=0; 80 | int bulletY = 0; 81 | // int enemyBulletX = -1; 82 | // int enemyBulletY = -1; 83 | // bool enemyBulletActive = false; 84 | int health=500; 85 | int health1=5,health2=5,health3=5; 86 | void drawEnemyBullets(int &pX,int &pY); 87 | void removeEnemyBullets(int &pX,int &pY); 88 | const int MAX_ENEMY_BULLETS = 5; // Adjust the maximum number of enemy bullets 89 | int enemyX=0; 90 | int enemyY=0; 91 | int enemyX3=0; 92 | int enemyY3=0; 93 | bool live=true; 94 | bool enemi2=true; 95 | bool enemi3=true; 96 | bool enemy2a=true; 97 | bool e3=true; 98 | bool active=true; 99 | int enemyBulletX[MAX_ENEMY_BULLETS]; 100 | int enemyBulletY[MAX_ENEMY_BULLETS]; 101 | bool enemyBulletActive[MAX_ENEMY_BULLETS]; 102 | bool bulletActive = false; 103 | int i=0; 104 | int count=0; 105 | bool level1=true; 106 | bool touch=true; 107 | 108 | // Main function 109 | main() 110 | { 111 | // Variables 112 | string rifle = "||"; 113 | int score=0; 114 | int EX=116,EY=53; 115 | int pX = 3, pY = 20; 116 | int eX = 120, eY = 20; 117 | int ex = 126, ey = 6; 118 | int fire=0; 119 | string ops=""; 120 | 121 | storeHighestScore(score); 122 | highestScore=loadHighestScore(); 123 | if(highestScore>10000){ 124 | highestScore=0; 125 | } 126 | int op=isAlphabet(ops); 127 | while (true) 128 | { 129 | 130 | system("cls"); 131 | if(op==0){ 132 | ops=""; 133 | display(); 134 | gotoxy(75,55); 135 | cin>>ops; 136 | op=isAlphabet(ops); 137 | } 138 | else{ 139 | op==0; 140 | display(); 141 | 142 | gotoxy(75,55); 143 | cin>>ops; 144 | op=isAlphabet(ops); 145 | } 146 | if(op==3){ 147 | system("cls"); 148 | storeHighestScore(score); 149 | exit(0); 150 | } 151 | if(op==2){ 152 | system("cls"); 153 | controls(); 154 | 155 | getch(); 156 | } 157 | if(op==1){ 158 | 159 | system("cls"); 160 | 161 | printWorld(); 162 | printtank(pX,pY,rifle); 163 | 164 | while (true){ 165 | 166 | gotoxy(90,2); 167 | cout<<"Highest Score: "<=0 && active){ //enemy 1 191 | moveEnemy2(ex, ey); 192 | if(ex<100){ 193 | } 194 | if(health1<=0){ 195 | eraseEnemy2(ex,ey); 196 | active=false; 197 | } 198 | } 199 | if(health1>0 ){// 200 | moveEnemyBullets(ex, ey,pX,pY); 201 | } 202 | if(health2>=0 && enemy2a){ 203 | moveEnemy1(eX, eY,pX,pY); 204 | moveEnemyBullet(eX,eY,pX,pY); 205 | if(health2==0){ 206 | eraseEnemy1(eX,eY); 207 | gotoxy(enemyX, enemyY); 208 | cout << " "; 209 | enemy2a=false; 210 | } 211 | } 212 | 213 | if(health1<=0&&health2<=0 && health3<=0){ 214 | system("cls"); 215 | EX=116,EY=53; 216 | pX = 3, pY = 20; 217 | eX = 120, eY = 20; 218 | ex = 126, ey = 6; 219 | health1=5; 220 | health=500; 221 | health2=5; 222 | enemy2a=true; 223 | e3=true; 224 | active=true; 225 | health3=5; 226 | win(); 227 | break; 228 | } 229 | if(health3>=0 && e3){ 230 | moveEnemy3(EX,EY); 231 | touch=true; 232 | moveEnemyBullet3(EX, EY,pX,pY); 233 | if(health3==0){ 234 | eraseEnemy3(EX,EY); 235 | gotoxy(enemyX3-3, enemyY3+2); 236 | cout << " "; 237 | e3=false; 238 | } 239 | } 240 | if (GetAsyncKeyState(VK_LEFT)) 241 | { 242 | movestankLeft(pX, pY,rifle); 243 | } 244 | if (GetAsyncKeyState(VK_UP)) 245 | { 246 | movetankup(pX, pY, rifle); 247 | } 248 | if (GetAsyncKeyState(VK_DOWN)) 249 | { 250 | movetankdown(pX, pY,rifle); 251 | 252 | } 253 | if (GetAsyncKeyState(VK_RIGHT)) 254 | { 255 | movetankRight(pX, pY, rifle, score); 256 | } 257 | if (GetAsyncKeyState(VK_SPACE)) { 258 | shootBullet(pX, pY); 259 | } 260 | 261 | if (GetAsyncKeyState('F')) { 262 | setcolor(green); 263 | if (!bulletActive) { 264 | if (count == 0) { 265 | rifle = "//"; 266 | count = 1; 267 | } else if (count == 1) { 268 | rifle = "=="; 269 | count = 2; 270 | } else if (count == 2) { 271 | rifle = "||"; 272 | count = 0; 273 | } 274 | printtank(pX, pY, rifle); 275 | } 276 | setcolor(15); 277 | } 278 | 279 | if (health <= 0) { 280 | enemy2a=true; 281 | e3=true; 282 | active=true; 283 | health=500; 284 | EX=116,EY=53; 285 | pX = 3, pY = 20; 286 | eX = 120, eY = 20; 287 | ex = 126, ey = 6; 288 | health1=5; 289 | health2=5; 290 | health3=5; 291 | gameover(); 292 | break; 293 | } 294 | removeBullet(); 295 | moveBullet(ex, ey, eX, eY, EX, EY, score); 296 | drawBullet(); 297 | removeEnemyBullets(pX, pY); 298 | gotoxy(3, 3); 299 | cout << "Score: " << score; 300 | Sleep(20); 301 | } 302 | } 303 | } 304 | } 305 | // store highest score 306 | int loadHighestScore() { 307 | fstream file; 308 | int highestScore; 309 | 310 | file.open("highestScore.txt", ios::in); 311 | if (file.is_open()) { 312 | file >> highestScore; 313 | file.close(); 314 | } else { 315 | file.open("highestScore.txt", ios::out); 316 | file << 0; 317 | file.close(); 318 | highestScore = 0; 319 | } 320 | return highestScore; 321 | } 322 | 323 | // highest score 324 | void storeHighestScore(int score) { 325 | fstream file; 326 | file.open("highestScore.txt", ios::out); 327 | 328 | if (!file.is_open()) { 329 | file << 0; 330 | return; 331 | } 332 | 333 | if (score > highestScore) { 334 | file << score; 335 | } 336 | 337 | file.close(); 338 | 339 | } 340 | // shoot bullet 341 | void shootBullet(int pX, int pY) { 342 | if (!bulletActive) { 343 | bulletX = pX+23; 344 | bulletY = pY +3; 345 | bulletActive = true; 346 | } 347 | } 348 | // draw player bullet 349 | void drawBullet() 350 | { 351 | setcolor(10); 352 | if (bulletActive) { 353 | gotoxy(bulletX, bulletY); 354 | if(count==0){ 355 | cout << '|'; 356 | } 357 | if(count==1){ 358 | cout << '/'; 359 | } 360 | if(count==2){ 361 | cout << ">"; 362 | } 363 | prevBulletX = bulletX; 364 | prevBulletY = bulletY; 365 | } 366 | } 367 | // remove player bullet 368 | void removeBullet() 369 | { 370 | if (bulletActive) 371 | { 372 | gotoxy(bulletX, bulletY); 373 | cout << " "; 374 | } 375 | } 376 | // move player bullet 377 | 378 | void moveBullet(int &ex, int &ey, int &eX, int &eY,int &EX,int &EY, int &score) { 379 | if(bulletActive){ 380 | 381 | // Check if the bullet hit enemy 1 382 | if ( bulletX >= eX && bulletX <= eX + 29 && bulletY <= eY + 5 && enemy2a) { 383 | bulletActive = false; 384 | health2--; 385 | score += 10; 386 | } 387 | 388 | // Check if the bullet hit enemy 2 389 | if ( bulletX >= ex && bulletX <= ex + 10 && bulletY >= ey && bulletY <= ey + 7 && active) { 390 | bulletActive = false; 391 | health1--; 392 | score += 20; 393 | } 394 | if (bulletX >= EX && bulletX <= EX + 5 && bulletY >= EY-5 && bulletY <= EY -2 && e3) 395 | { 396 | bulletActive = false; 397 | health3--; 398 | score+=30; 399 | } 400 | // Move horizontally and vertically 401 | if(count==1){ 402 | bulletX++; 403 | bulletY--; 404 | } 405 | if(count==0){ 406 | bulletY--; 407 | } 408 | if(count==2){ 409 | bulletX++; 410 | } 411 | 412 | if (bulletY <= 0 || getCharAtxy(bulletX, bulletY) != ' ') { 413 | bulletActive = false; 414 | } 415 | } 416 | 417 | } 418 | void drawEnemyBullet3() 419 | { 420 | setcolor(4); 421 | if (enemi3) 422 | { 423 | gotoxy(enemyX3, enemyY3-3); 424 | cout << "(_)"; 425 | } 426 | setcolor(15); 427 | } 428 | 429 | void removeEnemyBullet3() 430 | { 431 | if (enemi3) 432 | { 433 | gotoxy(enemyX3, enemyY3-3); 434 | cout << " "; 435 | } 436 | } 437 | 438 | void moveEnemyBullet3(int &EX, int &EY, int &pX, int &pY) 439 | { 440 | if(touch){ 441 | 442 | if (!enemi3 && rand() % 100 < 5) 443 | { 444 | enemyX3 = EX; 445 | enemyY3 = EY; 446 | enemi3 = true; 447 | } 448 | 449 | if (enemi3) 450 | { 451 | removeEnemyBullet3(); 452 | 453 | if (getCharAtxy(enemyX3 - 3, enemyY3) == ' ' || getCharAtxy(enemyX3 - 3, enemyY3) == ' ') 454 | { 455 | enemyX3--; 456 | if ((enemyX3 >= pX && enemyX3-1 <= pX +22 && 457 | enemyY3 >= pY && enemyY3 <= pY + 2&& pX+23<=enemyX3-3)) // Adjusted player's height 458 | { 459 | removeBullet(); 460 | touch = false; 461 | health -= 2; 462 | } 463 | 464 | } else 465 | { 466 | enemi3 = false; 467 | } 468 | if (enemyX3 < 4) 469 | { 470 | enemi3 = false; 471 | } 472 | 473 | drawEnemyBullet3(); 474 | } 475 | } 476 | } 477 | 478 | void drawEnemyBullet() 479 | { 480 | if (enemi2) 481 | { 482 | setcolor(4); 483 | gotoxy(enemyX, enemyY); 484 | cout << "<="; 485 | } 486 | setcolor(15); 487 | } 488 | 489 | void removeEnemyBullet() 490 | { 491 | if (enemi2) 492 | { 493 | gotoxy(enemyX, enemyY); 494 | cout << " "; 495 | } 496 | } 497 | 498 | void moveEnemyBullet(int &ex, int &ey,int &pX,int &pY) 499 | { 500 | if (!enemi2 && rand() % 100 < 5) 501 | { 502 | enemyX = ex; 503 | enemyY = ey; 504 | enemi2 = true; 505 | } 506 | 507 | if (enemi2) 508 | { 509 | removeEnemyBullet(); 510 | 511 | 512 | if (getCharAtxy(enemyX - 3, enemyY) == ' ') 513 | { 514 | enemyX--; 515 | if(enemyX >= pX && enemyX <= pX + 25 && enemyY >= pY && enemyY <= pY + 7){ 516 | health--; 517 | } 518 | } 519 | else 520 | { 521 | 522 | enemi2 = false; 523 | } 524 | 525 | if (enemyX <= 0) 526 | { 527 | enemi2 = false; 528 | } 529 | 530 | drawEnemyBullet(); 531 | } 532 | } 533 | 534 | 535 | int isAlphabet(string value) 536 | { 537 | try 538 | { 539 | 540 | int values = stoi(value); 541 | if (values == 1 || values == 2 || values == 4 || values == 5 || values == 6 || values == 0 || values == 3 || values == 8 || values == 7 || values == 9) 542 | { 543 | return values; 544 | } 545 | else 546 | { 547 | return 0; 548 | } 549 | } 550 | catch (invalid_argument) 551 | { 552 | return 0; 553 | } 554 | catch (out_of_range) 555 | { 556 | return 0; 557 | } 558 | } 559 | // ... 560 | 561 | void drawEnemyBullets(int &pX,int &pY) 562 | { 563 | for (int i = 0; i < MAX_ENEMY_BULLETS; ++i) 564 | { 565 | setcolor(4); 566 | if (enemyBulletActive[i]&&enemyBulletX[i] >=pX && enemyBulletX[i]<=pX+25 && enemyBulletY[i]=pX && enemyBulletX[i]<=pX+25 && enemyBulletY[i]=pX && ex<=pX+25 && ex<110) { 592 | // Fire a new bullet 593 | enemyBulletX[i] = ex; 594 | enemyBulletY[i] = ey + 6; 595 | enemyBulletActive[i] = true; 596 | } 597 | 598 | if (enemyBulletActive[i]) { 599 | gotoxy(enemyBulletX[i], enemyBulletY[i]); 600 | cout << " "; 601 | 602 | if (enemyBulletY[i] + 1 == pY || getCharAtxy(enemyBulletX[i], enemyBulletY[i] + 1) != ' ') { 603 | if (enemyBulletY[i] + 1 == pY) { 604 | health--; 605 | } 606 | enemyBulletActive[i] = false; 607 | } else { 608 | enemyBulletY[i]++; 609 | if (enemyBulletY[i] >= 58) { 610 | enemyBulletActive[i] = false; 611 | } 612 | 613 | // Draw the bullet at the new position 614 | gotoxy(enemyBulletX[i], enemyBulletY[i]); 615 | cout << "\\_/"; 616 | } 617 | } 618 | } 619 | } 620 | 621 | void controls(){ 622 | setcolor(15); 623 | cout << "###########################################################################################################################################################" << endl; 624 | cout << "# #" << endl; 625 | cout << "# #" << endl; 626 | cout << "# #" << endl; 627 | cout << "# #" << endl; 628 | cout << "# #" << endl; 629 | cout << "# #" << endl; 630 | cout << "# #" << endl; 631 | cout << "# #" << endl; 632 | cout << "# #" << endl; 633 | cout << "###########################################################################################################################################################" << endl; 634 | cout << "# #" << endl; 635 | cout << "# #" << endl; 636 | cout << "# #" << endl; 637 | cout << "# #" << endl; 638 | cout << "# @@@@@@@@ @ @ @ @ @@@@@@@@@ @@@@@@@@@ @ @ @@ @@@@@@@@@@ #" << endl; 639 | cout << "# @ @ @ @ @ @ @@ @@ @ @ @ @@ @@ @ #" << endl; 640 | cout << "# @ @ @ @ @ @ @@ @@ @ @ @ @@ @@ #" << endl; 641 | cout << "# @ @ @ @ @ @ @@ @@ @@@@ @ @ @@ @@@ #" << endl; 642 | cout << "# @ @ @ @ @ @ @@ @@ @ @ @ @@ @ @ #" << endl; 643 | cout << "# @@@@@@@@ @ @ @ @ @@ @@ @@ @ @ @ @ @@@@@@@@@ @@@@@@@@ #" << endl; 644 | cout << "# #" << endl; 645 | cout << "# #" << endl; 646 | cout << "# 1) press Space to fire Try to win the game with maximum health #" << endl; 647 | cout << "# #" << endl; 648 | cout << "# 2) press F to change fire direction your score will increase after killng enemies #" << endl; 649 | cout << "# #" << endl; 650 | cout << "# 3) press arrow keys to move If u killed by enemy u lost #" << endl; 651 | cout << "# #" << endl; 652 | cout << "# #" << endl; 653 | cout << "# #" << endl; 654 | cout << "# #" << endl; 655 | cout << "###########################################################################################################################################################" << endl; 656 | 657 | 658 | } 659 | // Move surfer up 660 | void movetankup(int &pX,int &pY,string &rifle) 661 | { 662 | if (getCharAtxy(pX, pY - 2) == ' ' && pY >= 15) 663 | { 664 | 665 | erasetank(pX,pY); 666 | pY = pY - 2; 667 | printtank(pX,pY,rifle); 668 | } 669 | } 670 | // Move surfer left 671 | void movestankLeft(int &pX, int &pY,string &rifle) 672 | { 673 | if (getCharAtxy(pX - 1, pY) == ' ' && getCharAtxy(pX -1, pY + 6) == ' ' && getCharAtxy(pX - 1, pY + 5) == ' ' && getCharAtxy(pX - 1, pY + 4) == ' ' && getCharAtxy(pX -1, pY + 3) == ' ' && getCharAtxy(pX - 1, pY + 2) == ' ') 674 | { 675 | erasetank(pX, pY); 676 | pX = pX - 2; 677 | printtank(pX, pY, rifle); 678 | } 679 | } 680 | 681 | // Move surfer right 682 | void movetankRight(int &pX, int &pY, string &rifle, int &score) 683 | { 684 | if (getCharAtxy(pX + 29, pY) == '*' || getCharAtxy(pX + 25, pY + 6) == '*' || 685 | getCharAtxy(pX + 29, pY + 5) == '*' || getCharAtxy(pX + 25, pY + 4) == '*' || 686 | getCharAtxy(pX + 29, pY + 3) == '*' || getCharAtxy(pX + 25, pY + 2) == '*') 687 | { 688 | erasetank(pX, pY); 689 | score = score + 1; 690 | pX = pX + 2; 691 | printtank(pX, pY, rifle); 692 | } 693 | if (getCharAtxy(pX + 18, pY) == ' ' && getCharAtxy(pX + 23, pY + 6) == ' ' && getCharAtxy(pX + 24, pY + 5) == ' ' && getCharAtxy(pX + 25, pY + 4) == ' ' && getCharAtxy(pX + 27, pY + 3) == ' ' && getCharAtxy(pX + 20, pY + 2) == ' ') 694 | { 695 | 696 | erasetank(pX, pY); 697 | pX = pX + 2; 698 | printtank(pX, pY, rifle); 699 | } 700 | } 701 | 702 | // Move surfer down 703 | void movetankdown(int &pX, int &pY, string &rifle) 704 | { 705 | if (getCharAtxy(pX, pY + 4) == ' ') 706 | { 707 | erasetank(pX, pY); 708 | pY = pY + 2; 709 | printtank(pX, pY, rifle); 710 | } 711 | } 712 | 713 | 714 | void printWorld() 715 | { 716 | setcolor(11); 717 | cout << "###########################################################################################################################################################" << endl; 718 | cout << "# TANK WARS #" << endl; 719 | cout << "# #" << endl; 720 | cout << "# #" << endl; 721 | cout << "# #" << endl; 722 | cout << "###########################################################################################################################################################" << endl; 723 | cout << "# #" << endl; 724 | cout << "# #" << endl; 725 | cout << "# #" << endl; 726 | cout << "# #" << endl; 727 | cout << "# #" << endl; 728 | cout << "# #" << endl; 729 | cout << "# #" << endl; 730 | cout << "# #" << endl; 731 | cout << "# #" << endl; 732 | cout << "# #" << endl; 733 | cout << "# #" << endl; 734 | cout << "# #" << endl; 735 | cout << "# #" << endl; 736 | cout << "# #" << endl; 737 | cout << "# #" << endl; 738 | cout << "# #" << endl; 739 | cout << "# #" << endl; 740 | cout << "# #" << endl; 741 | cout << "# #" << endl; 742 | cout << "# #" << endl; 743 | cout << "# #" << endl; 744 | cout << "# #" << endl; 745 | cout << "# #" << endl; 746 | cout << "# #" << endl; 747 | cout << "# #" << endl; 748 | cout << "# #" << endl; 749 | cout << "# #" << endl; 750 | cout << "# #" << endl; 751 | cout << "# #" << endl; 752 | cout << "# #" << endl; 753 | cout << "# #" << endl; 754 | cout << "# #" << endl; 755 | cout << "# #" << endl; 756 | cout << "# #" << endl; 757 | cout << "# #" << endl; 758 | cout << "# #" << endl; 759 | cout << "# #" << endl; 760 | cout << "# #" << endl; 761 | cout << "# #" << endl; 762 | cout << "# #" << endl; 763 | cout << "# #" << endl; 764 | cout << "# #" << endl; 765 | cout << "# #" << endl; 766 | cout << "# #" << endl; 767 | cout << "# #" << endl; 768 | cout << "# #" << endl; 769 | cout << "# #" << endl; 770 | cout << "# #" << endl; 771 | cout << "# #" << endl; 772 | cout << "# #" << endl; 773 | cout << "# #" << endl; 774 | cout << "# #" << endl; 775 | cout << "###########################################################################################################################################################" << endl; 776 | setcolor(15); 777 | } 778 | 779 | 780 | 781 | // erase player 782 | void erasetank(int &pX,int &pY) 783 | { 784 | gotoxy(pX, pY); 785 | cout << " "; 786 | gotoxy(pX, pY + 1); 787 | cout << " "; 788 | gotoxy(pX, pY + 2); 789 | cout << " "; 790 | gotoxy(pX, pY + 3); 791 | cout << " "; 792 | } 793 | // print player 794 | void printtank(int &pX,int &pY,string &rifle) 795 | { 796 | setcolor(2); 797 | setcolor(10); 798 | gotoxy(pX, pY); 799 | cout<<" __ "< pX && eX < pX + 29 && eY+7 >= pY && eY <= pY + 7|| eY==32){ 871 | patrol = false; 872 | } 873 | } 874 | else 875 | { 876 | eY = eY - 1; 877 | eX = eX + 1; 878 | if (eY == 20) 879 | { 880 | patrol = true; 881 | } 882 | } 883 | 884 | printEnemy1(eX,eY); 885 | Sleep(50); 886 | } 887 | 888 | // text 889 | void text(){ 890 | setcolor(12); 891 | gotoxy(40,3); 892 | cout<<" ___ ____ "; 893 | gotoxy(40,4); 894 | cout<<" || / | / / // | | // ) )"; 895 | gotoxy(40,5); 896 | cout<< " || / | / / //__| | //___/ / "; 897 | gotoxy(40,6); 898 | cout<<" || / /||/ / / ___ | / ___ ( "; 899 | gotoxy(40,7); 900 | cout<<" ||/ / | / // | | // | | "; 901 | gotoxy(40,8); 902 | cout<<" | / | / // | | // | | "; 903 | setcolor(15); 904 | } 905 | // display 906 | void display(){ 907 | setcolor(14); 908 | 909 | cout << "###########################################################################################################################################################" << endl; 910 | cout << "# #" << endl; 911 | cout << "# #" << endl; 912 | cout << "# #" << endl; 913 | cout << "# #" << endl; 914 | cout << "# #" << endl; 915 | cout << "# #" << endl; 916 | cout << "# #" << endl; 917 | cout << "# #" << endl; 918 | cout << "# #" << endl; 919 | cout << "###########################################################################################################################################################" << endl; 920 | cout << "# #" << endl; 921 | cout << "# #" << endl; 922 | cout << "# #" << endl; 923 | cout << "# #" << endl; 924 | cout << "# #" << endl; 925 | cout << "# #" << endl; 926 | cout << R"(# __ ____ _ ____ ___ _ _____ ____ _ _____ #)" << endl; 927 | cout << R"(# / | / __\\/ \ / _ \\ \// / __// _ \/ \__/|/ __/ #)" << endl; 928 | cout << R"(# | | | \/|| | | / \| \ / | | _| / \|| |\/||| \ #)" << endl; 929 | cout << R"(# _| |_ | __/| |_/\| |-|| / / | |_//| |-||| | ||| /_ #)" << endl; 930 | cout << R"(# |_____| \_/ \____/\_/ \|/_/ \____\\_/ \|\_/ \|\____\ #)" << endl; 931 | cout << "# #" << endl; 932 | cout << R"(# #)" << endl; 933 | cout << R"(# #)" << endl; 934 | cout << R"(# #)" << endl; 935 | cout << R"(# #)" << endl; 936 | cout<," << endl; 1056 | gotoxy(EX, EY - 2); 1057 | cout << " _/--\\_" << endl; 1058 | setcolor(15); 1059 | } 1060 | // erase enemy 2 1061 | void eraseEnemy3(int &EX,int &EY) 1062 | { 1063 | gotoxy(EX, EY-5); 1064 | cout << " " << endl; 1065 | gotoxy(EX, EY - 4); 1066 | cout << " " << endl; 1067 | gotoxy(EX, EY - 3); 1068 | cout << " " << endl; 1069 | gotoxy(EX, EY - 2); 1070 | cout << " " << endl; 1071 | } 1072 | // move enemy 2 1073 | void moveEnemy3(int &EX,int &EY) 1074 | { 1075 | if(health3>0){ 1076 | eraseEnemy3(EX,EY); 1077 | if (live) 1078 | { 1079 | printEnemy3(EX,EY); 1080 | } 1081 | } 1082 | else{ 1083 | eraseEnemy3(EX,EY); 1084 | } 1085 | } 1086 | // 1087 | void gameover(){ 1088 | setcolor(4); 1089 | system("cls"); 1090 | setcolor(5); 1091 | gotoxy(50,15); 1092 | cout<<"GAME OVER TRY AGAIN "<