📜 ⬆️ ⬇️

The apogee of the possibilities of a freshman - the first console game in C ++

Foreword


For over 30 years, video games have been actively developing, ranging from gameplay and graphic capabilities, right up to advanced artificial intelligence systems and users' perception of the material submitted by developers. Cybersport, in turn, is a full-fledged sport with multi-million prizes and billions in turnover. And the video game industry itself is constantly gaining momentum, being one of the most cash and mass branches of the entertainment industry. And to all this, humanity has come from the most primitive implementation of "tennis", launched on an oscilloscope.


As a freshman, I decided within the framework of studying the basic console capabilities of C / C ++, it is possible to program a “classic” ASCII game, which requires the player to think fast, to interact continuously with the game, as well as to have a simple graphic part, which the player could interpret as something like three-dimensional image.


Despite the visual primitiveness of such decisions, they certainly cause players nostalgia for old school games.


Inspiration


At the dawn of the appearance on the mobile phone market with monochrome displays, the Space Impact game was stitching, which was sewn into Nokia devices. She perfectly fit into the limited capabilities of the then cellular. After the introduction of simple games into mobile phones, the sales of devices have increased dramatically, and mobile gaming has gradually become popular, and now it is fully competing with the industry of “adult” AAA projects.


Space Impact was the basis for my first game because of its ease of execution and popularity in the early 2000s.


Features of "Space Invader"


First of all - the lightness of the program. The executable file takes less than 100 kb and will work, as intended, on virtually any computer running Windows OC with Visual C ++.


Secondly, portability - the source code can be remade in a few minutes to POSIX systems, thereby ensuring operability on UNIX and Mac operating systems, only by replacing a few functions and reassembling the program on the appropriate compiler.


The third advantage - the program is portable, does not require any additional files. All additional files, if necessary, are created automatically in the directory where the executable file is located.


The simplest intuitive interface that does not require a description or instructions for use.


The content of the game "Space Invader"
  • The main menu of 4 points, which can be selected using the arrows on the keyboard.
  • Item "Game" - opens the menu of two items:

    • Sub-item "New game" - launches a new game session.
    • Sub-item “Continue” - loads the last saved game from a binary file in the directory of the executable file and starts the game session using the received data.

  • Item "Help" - instructions for working with the application and its description. Scroll by pressing the arrows on the keyboard.
  • The “Hall of Fame” item is a list of game sessions leaders, loaded from a binary file in the directory of the executable file and displayed in formatted format to the console.
  • Item "Exit" - exit from the application.
  • Moving to the left "world" with dynamic speed. "World" contains random fields above and below the thickness of 1 or 2 characters. Also between the fields randomly appears "space junk", displayed by the symbol "¤", which is an obstacle for the player.
  • Pinned to the left edge of the window "spaceship". The ship is shifted up and down using the arrows on the keyboard, by pressing the spacebar it releases a projectile, which destroys the "space debris" by touch.
  • “Dashboard” at the top of the console, showing the mileage, current speed and the number of remaining attempts.

How does the Space Invader work?


When you start the application, a splash-animation appears. It consists of 6 preformatted character arrays, alternating every 200ms.


image
Initial Screen - Final Slide


Next comes the main menu function with parameter 1 (integer). The function displays a menu with a menu item highlighted by angle brackets, the number of which coincides with the input parameter. Items in menu 4, respectively, the input parameter can vary from 1 to 4. When you press the down arrow, recursive treatment is performed with the incremented input parameter in the case if the input parameter is less than 4, with parameter 1, if the input parameter is 4. When you press Space or Enter the function corresponding to the selected menu item is accessed.


void StartMenu(int switcher) { system("cls"); switch (switcher) { case 1: cout << "\n\n\n << ! >>\n\n !\n\n  \n\n "; break; case 2: cout << "\n\n\n !\n\n << ! >>\n\n  \n\n "; break; case 3: cout << "\n\n\n !\n\n !\n\n <<   >>\n\n "; break; case 4: cout << "\n\n\n !\n\n !\n\n  \n\n <<  >>"; break; } int choice = _getch(); if (choice == 224) choice = _getch(); if (choice == 72) if (switcher != 1) StartMenu(switcher - 1); else StartMenu(4); if (choice == 80) if (switcher != 4) StartMenu(switcher + 1); else StartMenu(1); if (choice == 13 || choice == 32) { if (switcher == 1) GameMenu(1); if (switcher == 2) Help(0); if (switcher == 3) TopChart(); if (switcher == 4) _exit(0); } } 

image
Main menu (the function is entered with parameter 1)


When accessing the function corresponding to the “Game” item, a function similar in functionality is launched, but there is only a choice of 2 points. Accordingly, the input parameter will be 1 or 2, and when you press any of the arrows (up or down), we only need to change the number to “opposite”. The most optimized option is to subtract the input parameter from 3 (3 - 1 = 2, 3 - 2 = 1).


 void GameMenu(int switcher) { system("cls"); if (switcher == 1) cout << "\n\n\n\n\n <<  ! >>\n\n !"; else cout << "\n\n\n\n\n  !\n\n << ! >>"; int choice = _getch(); if (choice == 224) choice = _getch(); if (choice == 72 || choice == 80) GameMenu(3 - switcher); if (choice == 27) StartMenu(1); if (choice == 13 || choice == 32) Game(switcher); } 

image
Additional menu (input to the function is performed with parameter 1)


Now to the main - the process of the game. When selecting the sub-item “New game”, a new game session is launched. A two-dimensional array is created, measuring 14 rows by 50 columns. The first line is allocated under the dashboard. The first device is the number of kilometers traveled, it is equal to the number of console updates (initially the console is updated every 80ms, with each update this parameter is decremented until it reaches a value of 25).


 int odometerBuf = odometer, odometerDigitLength; for (odometerDigitLength = 0; odometerBuf != 0; odometerBuf /= 10, odometerDigitLength++);//     for (int i = odometerDigitLength, odometerBuf = odometer; i >= 0; i--, scr[0][i] = odometerBuf % 10 + '0', odometerBuf /= 10);//     scr[0][odometerDigitLength++] = ''; scr[0][odometerDigitLength++] = '';// "" odometer++;//  

The second device, the current speed, is a formula - 1000 / console update speed. Speed ​​is measured in kilometers per second. Thus, the ship initially moves at a speed of 12 km / s, and after some time reaches the mark of 40 km / s.


 speed = 1000 / timer;//  int speedBuf = speed; for (int i = 42; speed != 0; i--, scr[0][i] = speed % 10 + '0', speed /= 10);//     scr[0][42] = ''; scr[0][43] = ''; scr[0][44] = '/'; scr[0][45] = '';// "/" 

The third device displays the number of remaining attempts, initially there are 3. Attempts are indicated by the “&” symbol.


 for (int i = 50; lifes > 0; i--, lifes--, scr[0][i] = '&'); 

image
The dashboard at the beginning of the game session


The next 2 lines, like the last 2 - are the fields of the game. The scenery of the fields are chosen randomly, they can consist of 3 characters or a space. The last lines are always completely filled, and the second and last but one contains characters other than spaces in those places where these characters "grow" from others.


 char borderSymbols[] = { '†', '‡', '¤', ' ' }; for (int aboveBelow = 0; aboveBelow < 50; aboveBelow++)//     (2 + 2) { scr[1][aboveBelow] = borderSymbols[rand() % 3]; if (scr[1][aboveBelow] == '‡') scr[2][aboveBelow] = '¤'; scr[13][aboveBelow] = borderSymbols[rand() % 3]; if (scr[13][aboveBelow] == '‡') scr[12][aboveBelow] = '¤'; } 

image
Dashboard and margins at the beginning of a game session


In the central line of the game space, pressed to the left edge, a spaceship is drawn, which the player will manage.


 scr[6][0] = '\\'; scr[6][1] = '\\';//  scr[7][0] = '3'; scr[7][1] = '='; scr[7][2] = '='; scr[8][0] = '/'; scr[8][1] = '/'; 

You can control it with up and down arrows.


 if (_kbhit())//    { control = _getch();//    if (control == 224) control = _getch(); } if (control == 72)//    if (scr[2][0] == '\\' || scr[3][0] == '\\' && scr[2][0] == '¤' || scr[3][1] == '\\' && scr[2][1] == '¤')//      -   if (lifes > 1) { cout << '\a'; lifes--; weaponPos = 7; GameStart(scr, lifes, &timer); Sleep(1000); } else GameOver(odometer); else { for (int i = 2; i < 13; i++)//     for (int j = 0; j < 49; j++) if (scr[i][j] == '3' || scr[i][j] == '\\' || scr[i][j] == '=' || scr[i][j] == '/') { scr[i - 1][j] = scr[i][j]; scr[i][j] = ' '; } weaponPos--; } if (control == 80)//    if (scr[12][0] == '/' || scr[11][0] == '/' && scr[12][0] == '¤' || scr[11][1] == '/' && scr[12][1] == '¤')//      -   if (lifes > 1) { cout << '\a'; lifes--; weaponPos = 7; GameStart(scr, lifes, &timer); Sleep(1000); } else GameOver(odometer); else { for (int i = 12; i >= 2; i--)//     for (int j = 0; j < 49; j++) if (scr[i][j] == '3' || scr[i][j] == '\\' || scr[i][j] == '=' || scr[i][j] == '/') { scr[i + 1][j] = scr[i][j]; scr[i][j] = ' '; } weaponPos++; } 

image
The location of the ship when you double-click the up arrow


Moving away from the visualization, it is worth noting that, together with the ship, we move up or down the array element responsible for the “barrel” of the ship. Accordingly, from which you can release the shells by pressing the spacebar.


However, neither the field nor the projectiles move, because in order to “revive” the gameplay, after the timer of the “World” screen redrawing will shift to one column to the left, and projectiles to one column to the right. The ship remains in place until the player wants otherwise. But after redrawing, one empty column now appears - fill it with randomly with fields and "space debris", which can be knocked down with ship projectiles or side strikers.


 for (int i = 1; i < 14; i++)// ""      for (int j = 0; j < 49; j++) { if (scr[i][j] == '\\' && scr[i][j + 1] == '¤' || scr[i][j] == '=' && scr[i][j + 1] == '¤' || scr[i][j] == '/' && scr[i][j + 1] == '¤') if (lifes > 1) { cout << '\a'; lifes--; weaponPos = 7; GameStart(scr, lifes, &timer); Sleep(1000); } else GameOver(odometer); if (scr[i][j] != '3' && scr[i][j] != '\\' && scr[i][j] != '=' && scr[i][j] != '/' && scr[i][j] != '-' && scr[i][j + 1] != '-') scr[i][j] = scr[i][j + 1]; if (scr[i][j] == '¤') scr[i][j + 1] = ' '; } for (int i = 1; i < 14; i++)//      for (int j = 48; j >= 0; j--) if (scr[i][j] == '-') if (j != 48) { scr[i][j + 1] = '-'; scr[i][j] = ' '; } else scr[i][j] = ' '; char borderSymbols[] = { '†', '‡', '¤', ' ' }; scr[2][49] = ' ';//     scr[1][49] = borderSymbols[rand() % 3]; if (scr[1][49] == '‡') scr[2][49] = '¤'; scr[12][49] = ' '; scr[13][49] = borderSymbols[rand() % 3]; if (scr[13][49] == '‡') scr[12][49] = '¤'; for (int i = 3; i < 12; i++)//    { if (rand() % 10 == 1) scr[i][49] = '¤'; } 

When the ship moves up or down at this moment space debris will be destroyed without damage to the ship, all thanks to the bump stops.


image
If at the moment do not dodge the garbage with the arrow down - the ship will be broken


The shells produced by the ship, are designed so that they sweep away everything in its path. Consequently, firing one projectile clears the corridor in one line.


However, although the fields are made of materials similar to space debris, they cannot be destroyed by the strikers. The contact of any part of the ship with the fields leads to the inevitable collapse. As well as space debris in the front of the ship. If at such moments there is at least one more “attempt” on the dashboard - the game seems to start all over again, but retaining the accumulated score and losing one “attempt”. The speed is reset to the initial value of 12 km / s.


If the player “crashed” and there are no attempts left - the game session ends, and the player is asked to enter his name in order to save his result in the “hall of fame”.


image
Proposing a player to enter a name to save their result in the “Hall of Fame”


The application processes 2 files:



The “Help” main menu item is a function that takes a parameter from 0 to 22, displaying the next 12 lines of 50 characters from the input parameter. Control is performed recursively using the up and down arrows.


 void Help(int switcher) { system("cls"); cout << ":  / | : ESCAPE\n"; char arr[1800] = { "       –  /   –   ENTER     – ESCAPE     / –  /   –    ,   – ESCAPE   –   ,    .          .    .     –    .     40 /.         ,   ,    .         ,      « » (  «&»),   3.     –   ESCAPE.  ,             «!».        .     !  Svjatoslav Laskov – AUTHOR Igor Marchenko – COACH National Technical University «Kharkiv Polytechnic Institute» 2016" }; for (int i = 0, buf = switcher; i < 13; i++) { for (int j = buf * 50; j < buf * 50 + 50; j++) cout << arr[j]; if (i != 12) cout << endl; buf++; } int controller = _getch();//    if (controller == 224)//    controller = _getch();//    if (controller == 72)//   if (switcher > 0) Help(switcher - 1); else Help(0); if (controller == 80)//   if (switcher < 22) Help(switcher + 1); else Help(22); if (controller == 27)// Escape StartMenu(2); } 

“Exit” main menu item - exits the application.


User's manual

• MANAGEMENT IN MENU
o Move through items - UP / DOWN ARROW
o Select item - SPACE or ENTER
o Return to the previous menu - ESCAPE
• GAME CONTROL
o Move up / down - UP / DOWN ARROW
o Take a shot - SPACEBAR
o Return to the menu, save the game - ESCAPE
• BRIEFING
You are a pilot of a space ship caught in a space storm. You need not to break and fly as far as possible.


The ship is equipped with dynamic control. The faster you fly, the sharper the vessel turns. The ship automatically gradually accelerates to 40 km / s.


You can shoot down space debris using a magnetic gun built into the ship, as well as side dampers.
When controlling a ship, the distance traveled, the current speed and the number of remaining “rollback cells” (indicated by the “&” symbol) are displayed on the instrument panel, initially 3.


If you decide to stop playing, just hit ESCAPE. The game will continue, and you can continue it even after the application is restarted using the “CONTINUE!” Item.


In the main menu you can see the table of honorary pilots. Get your right there to be!


Total


Personally, I got a lot of pleasure from the development of such a petty project, especially since the standard console is designed to display information, and not for games. Because of this, the frame rate is very limited regardless of the computer on which the application is running.


I also wanted to divide the application into several threads for a more correct response to the user pressing the keys, but I implement the threads in the next C ++ project.


Source
 #include "conio.h" #include "windows.h" #include "ctime" #include <iostream> using namespace std; struct player// ,     -    { char name[7]; int score; int mday; int mon; int year; }; struct save// ,       { int weaponPos; int timer; int odometer; int lifes; char scr[14][50]; }; void ScreenOutput(char scr[14][50])//      { system("cls"); for (int i = 0; i < 14; i++) { for (int j = 0; j < 50; j++) cout << scr[i][j]; if (i != 13) cout << endl; } } //   void StartMenu(int switcher);//,    ,   ""  "" void GameMenu(int switcher);//   void GameStart(char scr[14][50], int lifes, int *timer);//,          void Game(int var);//   void GameOver(int score);//,   ,        void Help(int switcher);//   void TopChart();// " " -    void Help(int switcher) { system("cls"); cout << ":  / | : ESCAPE\n"; char arr[1800] = { "       –  /   –   ENTER     – ESCAPE     / –  /   –    ,   – ESCAPE   –   ,    .          .    .     –    .     40 /.         ,   ,    .         ,      « » (  «&»),   3.     –   ESCAPE.  ,             «!».        .     !  Svjatoslav Laskov – AUTHOR Igor Marchenko – COACH National Technical University «Kharkiv Polytechnic Institute» 2016" }; for (int i = 0, buf = switcher; i < 13; i++) { for (int j = buf * 50; j < buf * 50 + 50; j++) cout << arr[j]; if (i != 12) cout << endl; buf++; } int controller = _getch();//    if (controller == 224)//    controller = _getch();//    if (controller == 72)//   if (switcher > 0) Help(switcher - 1); else Help(0); if (controller == 80)//   if (switcher < 22) Help(switcher + 1); else Help(22); if (controller == 27)// Escape StartMenu(2); } void StartMenu(int switcher) { system("cls"); switch (switcher) { case 1: cout << "\n\n\n << ! >>\n\n !\n\n  \n\n "; break; case 2: cout << "\n\n\n !\n\n << ! >>\n\n  \n\n "; break; case 3: cout << "\n\n\n !\n\n !\n\n <<   >>\n\n "; break; case 4: cout << "\n\n\n !\n\n !\n\n  \n\n <<  >>"; break; } int choice = _getch(); if (choice == 224) choice = _getch(); if (choice == 72) if (switcher != 1) StartMenu(switcher - 1); else StartMenu(4); if (choice == 80) if (switcher != 4) StartMenu(switcher + 1); else StartMenu(1); if (choice == 13 || choice == 32) { if (switcher == 1) GameMenu(1); if (switcher == 2) Help(0); if (switcher == 3) TopChart(); if (switcher == 4) _exit(0); } } void GameMenu(int switcher) { system("cls"); if (switcher == 1) cout << "\n\n\n\n\n <<  ! >>\n\n !"; else cout << "\n\n\n\n\n  !\n\n << ! >>"; int choice = _getch(); if (choice == 224) choice = _getch(); if (choice == 72 || choice == 80) GameMenu(3 - switcher); if (choice == 27) StartMenu(1); if (choice == 13 || choice == 32) Game(switcher); } void GameStart(char scr[14][50], int lifes, int *timer) { for (int i = 0; i < 14; i++)//   for (int j = 0; j < 50; j++) scr[i][j] = ' '; for (int i = 50; lifes > 0; i--, lifes--, scr[0][i] = '&'); *timer = 80; char borderSymbols[] = { '†', '‡', '¤', ' ' }; for (int aboveBelow = 0; aboveBelow < 50; aboveBelow++)//     (2 + 2) { scr[1][aboveBelow] = borderSymbols[rand() % 3]; if (scr[1][aboveBelow] == '‡') scr[2][aboveBelow] = '¤'; scr[13][aboveBelow] = borderSymbols[rand() % 3]; if (scr[13][aboveBelow] == '‡') scr[12][aboveBelow] = '¤'; } scr[6][0] = '\\'; scr[6][1] = '\\';//  scr[7][0] = '3'; scr[7][1] = '='; scr[7][2] = '='; scr[8][0] = '/'; scr[8][1] = '/'; } void GameOver(int score) { system("cls"); player newPlayer;//  newPlayer.score = score;//    cout << " !\n  " << score << " .\n\n(,    )\n(   6 )\n     \n   : "; cin.getline(newPlayer.name, 7);//   time_t timeCur; time(&timeCur); struct tm * timeCurStruct = localtime(&timeCur); newPlayer.mday = timeCurStruct->tm_mday;//    newPlayer.mon = timeCurStruct->tm_mon; newPlayer.year = timeCurStruct->tm_year; FILE *topChart; fopen_s(&topChart, "TopChart.bin", "ab+"); fwrite(&newPlayer, 1, sizeof(player), topChart);//    fclose(topChart); TopChart(); } void TopChart() { FILE *topChart; fopen_s(&topChart, "TopChart.bin", "rb+"); system("cls"); if (topChart == NULL)//      { system("cls"); cout << "   ."; Sleep(1000); system("cls"); cout << "   .."; Sleep(1000); system("cls"); cout << "   ..."; Sleep(1000); cout << "\n  ,  ."; _getch(); StartMenu(3); } fseek(topChart, 0L, SEEK_END); int playerAmount = ftell(topChart) / sizeof(player); player *temp = new player[playerAmount]; fseek(topChart, 0L, SEEK_SET); for (int i = 0; i < playerAmount; i++)//     fread(&temp[i], 1, sizeof(player), topChart); fclose(topChart); for (int i = 1; i < playerAmount; i++)//      if (temp[i].score > temp[i - 1].score) { player tempAlone; strcpy(tempAlone.name, temp[i].name); tempAlone.score = temp[i].score; tempAlone.mday = temp[i].mday; tempAlone.mon = temp[i].mon; tempAlone.year = temp[i].year; strcpy(temp[i].name, temp[i - 1].name); temp[i].score = temp[i - 1].score; temp[i].mday = temp[i - 1].mday; temp[i].mon = temp[i - 1].mon; temp[i].year = temp[i - 1].year; strcpy(temp[i - 1].name, tempAlone.name); temp[i - 1].score = tempAlone.score; temp[i - 1].mday = tempAlone.mday; temp[i - 1].mon = tempAlone.mon; temp[i - 1].year = tempAlone.year; if (i > 1) i -= 2; else i = 0; } if (playerAmount > 12) playerAmount = 12; cout << "№ " << "" << '\t' << "" << '\t' << "" << endl;//     for (int i = 0; i < playerAmount; i++) { cout << i + 1 << ')' << '\t' << temp[i].name << '\t' << temp[i].score << '\t'; if (temp[i].mday / 10 == 0) cout << '0' << temp[i].mday; else cout << temp[i].mday; cout << ' '; switch (temp[i].mon) { case 0: cout << ""; break; case 1: cout << ""; break; case 2: cout << ""; break; case 3: cout << ""; break; case 4: cout << ""; break; case 5: cout << ""; break; case 6: cout << ""; break; case 7: cout << ""; break; case 8: cout << ""; break; case 9: cout << ""; break; case 10: cout << ""; break; case 11: cout << ""; break; } cout << ' ' << 1900 + temp[i].year << endl; } fopen_s(&topChart, "TopChart.bin", "wb+"); for (int i = 0; i < playerAmount; i++)//      fwrite(&temp[i], 1, sizeof(player), topChart); fclose(topChart); delete[] temp; _getch(); StartMenu(3); } int main() { setlocale(LC_ALL, "Rus");//  system("mode con cols=51 lines=14");//    system("title Space Invader");//    system("color 0A");//   (0- ; - ) HANDLE hCons = GetStdHandle(STD_OUTPUT_HANDLE);//  CONSOLE_CURSOR_INFO cursor = { 100, false };//  1  100    ; false\true -  SetConsoleCursorInfo(hCons, &cursor);//    int timer = 200; cout << " (____/(__) \\_/\\_/ \\___)(____)\n\n\n\n\n\n\n\n\n\n\n __ __ _ _ _ __ ____ ____ ____\n ( )( ( \\/ )( \\ / _\\ ( \\( __)( _ \\";//  Sleep(timer); system("cls"); cout << " \\___ \\ ) __// \\( (__ ) _)\n (____/(__) \\_/\\_/ \\___)(____)\n\n\n\n\n\n\n\n\n __ __ _ _ _ __ ____ ____ ____\n ( )( ( \\/ )( \\ / _\\ ( \\( __)( _ \\\n )( / /\\ \\/ // \\ ) D ( ) _) ) /";//  Sleep(timer); system("cls"); cout << " / ___)( _ \\ / _\\ / __)( __)\n \\___ \\ ) __// \\( (__ ) _)\n (____/(__) \\_/\\_/ \\___)(____)\n\n\n\n\n\n\n __ __ _ _ _ __ ____ ____ ____\n ( )( ( \\/ )( \\ / _\\ ( \\( __)( _ \\\n )( / /\\ \\/ // \\ ) D ( ) _) ) /\n (__)\\_)__) \\__/ \\_/\\_/(____/(____)(__\\_)";//  Sleep(timer); system("cls"); cout << " ____ ____ __ ___ ____\n / ___)( _ \\ / _\\ / __)( __)\n \\___ \\ ) __// \\( (__ ) _)\n (____/(__) \\_/\\_/ \\___)(____)\n\n\n\n\n __ __ _ _ _ __ ____ ____ ____\n ( )( ( \\/ )( \\ / _\\ ( \\( __)( _ \\\n )( / /\\ \\/ // \\ ) D ( ) _) ) /\n (__)\\_)__) \\__/ \\_/\\_/(____/(____)(__\\_)";//  Sleep(timer); system("cls"); cout << "\n ____ ____ __ ___ ____\n / ___)( _ \\ / _\\ / __)( __)\n \\___ \\ ) __// \\( (__ ) _)\n (____/(__) \\_/\\_/ \\___)(____)\n\n\n __ __ _ _ _ __ ____ ____ ____\n ( )( ( \\/ )( \\ / _\\ ( \\( __)( _ \\\n )( / /\\ \\/ // \\ ) D ( ) _) ) /\n (__)\\_)__) \\__/ \\_/\\_/(____/(____)(__\\_)";//  Sleep(timer); system("cls"); cout << "\n\n ____ ____ __ ___ ____\n / ___)( _ \\ / _\\ / __)( __)\n \\___ \\ ) __// \\( (__ ) _)\n (____/(__) \\_/\\_/ \\___)(____)\n __ __ _ _ _ __ ____ ____ ____\n ( )( ( \\/ )( \\ / _\\ ( \\( __)( _ \\\n )( / /\\ \\/ // \\ ) D ( ) _) ) /\n (__)\\_)__) \\__/ \\_/\\_/(____/(____)(__\\_)";//  cout << '\a'; Sleep(10 * timer);//  StartMenu(1); return 0; } void Game(int var) { int weaponPos;//     int timer;//    int odometer;//  ,     int lifes;//  char control = '&';//   int shotPause = 4;//   (    ) int speed;//  char scr[14][50]; if (var == 1) { weaponPos = 7;//     odometer = 1;//  ,     lifes = 3;//  GameStart(scr, lifes, &timer); } else//      { FILE *saveBin; fopen_s(&saveBin, "CurrentSave.bin", "rb"); if (!saveBin) { system("cls"); cout << " ."; Sleep(1000); system("cls"); cout << " .."; Sleep(1000); system("cls"); cout << " ..."; Sleep(1000); Game(1); } fread(&weaponPos, 1, sizeof(int), saveBin); timer = 80; fread(&odometer, 1, sizeof(int), saveBin); fread(&lifes, 1, sizeof(int), saveBin); fread(&scr, 14 * 50, sizeof(char), saveBin); fclose(saveBin); remove("CurrentSave.bin"); } while (true) { int odometerBuf = odometer, odometerDigitLength; for (odometerDigitLength = 0; odometerBuf != 0; odometerBuf /= 10, odometerDigitLength++);//     for (int i = odometerDigitLength, odometerBuf = odometer; i >= 0; i--, scr[0][i] = odometerBuf % 10 + '0', odometerBuf /= 10);//     scr[0][odometerDigitLength++] = ''; scr[0][odometerDigitLength++] = '';// "" odometer++;//  speed = 1000 / timer;//  int speedBuf = speed; for (int i = 42; speed != 0; i--, scr[0][i] = speed % 10 + '0', speed /= 10);//     scr[0][42] = ''; scr[0][43] = ''; scr[0][44] = '/'; scr[0][45] = '';// "/" if (_kbhit())//    { control = _getch();//    if (control == 224) control = _getch(); } if (control == 13 && shotPause == 4 || control == 32 && shotPause == 4)//       { scr[weaponPos][3] = '-'; shotPause = 0; } if (shotPause < 4)// shotPause++; if (control == 27)//  { FILE *saveBin; fopen_s(&saveBin, "CurrentSave.bin", "wb"); fwrite(&weaponPos, 1, sizeof(int), saveBin); fwrite(&odometer, 1, sizeof(int), saveBin); fwrite(&lifes, 1, sizeof(int), saveBin); fwrite(&scr, 14 * 50, sizeof(char), saveBin); fclose(saveBin); GameMenu(2); } if (control == 72)//    if (scr[2][0] == '\\' || scr[3][0] == '\\' && scr[2][0] == '¤' || scr[3][1] == '\\' && scr[2][1] == '¤')//      -   if (lifes > 1) { cout << '\a'; lifes--; weaponPos = 7; GameStart(scr, lifes, &timer); Sleep(1000); } else GameOver(odometer); else { for (int i = 2; i < 13; i++)//     for (int j = 0; j < 49; j++) if (scr[i][j] == '3' || scr[i][j] == '\\' || scr[i][j] == '=' || scr[i][j] == '/') { scr[i - 1][j] = scr[i][j]; scr[i][j] = ' '; } weaponPos--; } if (control == 80)//    if (scr[12][0] == '/' || scr[11][0] == '/' && scr[12][0] == '¤' || scr[11][1] == '/' && scr[12][1] == '¤')//      -   if (lifes > 1) { cout << '\a'; lifes--; weaponPos = 7; GameStart(scr, lifes, &timer); Sleep(1000); } else GameOver(odometer); else { for (int i = 12; i >= 2; i--)//     for (int j = 0; j < 49; j++) if (scr[i][j] == '3' || scr[i][j] == '\\' || scr[i][j] == '=' || scr[i][j] == '/') { scr[i + 1][j] = scr[i][j]; scr[i][j] = ' '; } weaponPos++; } for (int i = 1; i < 14; i++)// ""      for (int j = 0; j < 49; j++) { if (scr[i][j] == '\\' && scr[i][j + 1] == '¤' || scr[i][j] == '=' && scr[i][j + 1] == '¤' || scr[i][j] == '/' && scr[i][j + 1] == '¤') if (lifes > 1) { cout << '\a'; lifes--; weaponPos = 7; GameStart(scr, lifes, &timer); Sleep(1000); } else GameOver(odometer); if (scr[i][j] != '3' && scr[i][j] != '\\' && scr[i][j] != '=' && scr[i][j] != '/' && scr[i][j] != '-' && scr[i][j + 1] != '-') scr[i][j] = scr[i][j + 1]; if (scr[i][j] == '¤') scr[i][j + 1] = ' '; } for (int i = 1; i < 14; i++)//      for (int j = 48; j >= 0; j--) if (scr[i][j] == '-') if (j != 48) { scr[i][j + 1] = '-'; scr[i][j] = ' '; } else scr[i][j] = ' '; char borderSymbols[] = { '†', '‡', '¤', ' ' }; scr[2][49] = ' ';//     scr[1][49] = borderSymbols[rand() % 3]; if (scr[1][49] == '‡') scr[2][49] = '¤'; scr[12][49] = ' '; scr[13][49] = borderSymbols[rand() % 3]; if (scr[13][49] == '‡') scr[12][49] = '¤'; for (int i = 3; i < 12; i++)//    { if (rand() % 10 == 1) scr[i][49] = '¤'; } ScreenOutput(scr);//  if (control != '&')//""   control = '&'; if (timer > 25)//  timer--; Sleep(timer);//  } } 

.exe : Space Invader .


PS: , .


')

Source: https://habr.com/ru/post/304448/


All Articles