Advertisement
TroubleMaker84

ATESTAT 2.0

Apr 26th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>
  3. #include <conio.h>
  4. #include <stdio.h>
  5. #include <time.h>
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8.  
  9. #define LATIME 30
  10. #define LUNGIME 30
  11. #define SIMBOL_MARGINE1 '-'
  12. #define SIMBOL_MARGINE2 '|'
  13. #include <windows.h>
  14. using namespace std;
  15.  
  16.  
  17. void gotoxy( int column, int line ) //
  18.   {
  19.   COORD coord;
  20.   coord.X = column;
  21.   coord.Y = line;
  22.   SetConsoleCursorPosition(
  23.     GetStdHandle( STD_OUTPUT_HANDLE ),
  24.     coord
  25.     );
  26.   }
  27.  
  28. char Monster[4][4];
  29. bool GAMEEND = false;
  30. char matTer[LUNGIME][LATIME];
  31. long long Score,M_ShootRate=0;
  32. short int pozNava = 15, Player_Lifes=3;
  33.  
  34. void show_cursor(bool show){ //vizibilitate curosor in consola
  35.     HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
  36.     CONSOLE_CURSOR_INFO infCursor;
  37.     GetConsoleCursorInfo(out, &infCursor);
  38.     infCursor.bVisible = show;
  39.     SetConsoleCursorInfo(out, &infCursor);
  40. }
  41. void DEL_Monster(int m, int n){
  42.     for(int i = m - 1; i <= m + 3; i++)
  43.         for(int j = n; j<=n + 3; j++)
  44.                 if(matTer[i][j]!=char(219))
  45.                     matTer[i][j]='\0';
  46. }
  47. void afisare(){
  48.     for (int i = 1; i <= LUNGIME - 1; i++){
  49.         for (int j = 1; j <= LATIME - 1; j++)
  50.                 cout << matTer[i][j];
  51.         cout << endl;
  52.         }
  53. }
  54.  void creare_teren(){
  55.     int i;
  56.     for (i = 1; i <= LATIME ; i++)
  57.         matTer[i][1] = matTer[i][LUNGIME - 1] = SIMBOL_MARGINE2;
  58.     for (i = 1; i <= LUNGIME - 1; i++)
  59.         matTer[1][i] = matTer[LATIME - 1][i] = SIMBOL_MARGINE1;
  60. }
  61.  
  62. void nava(){
  63.     matTer[LUNGIME-2][pozNava-1] = matTer[LUNGIME-2][pozNava] = matTer[LUNGIME-2][pozNava+1] = matTer[LUNGIME-3][pozNava] = (char)219;
  64. }
  65.  
  66. void Check_KeyPress ()
  67. {
  68.         char newKey;
  69.  
  70.     if (_kbhit())
  71.         newKey = _getch();
  72.     if(newKey == 'd' ||newKey == 'D')
  73.         if(pozNava < LATIME-3){
  74.             matTer[LUNGIME-2][pozNava + 2] = matTer[LUNGIME-2][pozNava];
  75.             matTer[LUNGIME-3][pozNava+1] =matTer[LUNGIME-2][pozNava] ;
  76.             matTer[LUNGIME-2][pozNava-1] = matTer[LUNGIME-3][pozNava] = '\0';
  77.             pozNava++;
  78.         }
  79.     if(newKey == 'a' || newKey == 'A')
  80.         if(pozNava > 3){
  81.             matTer[LUNGIME-2][pozNava-2] = matTer[LUNGIME-3][pozNava-1]= char(219);
  82.             matTer[LUNGIME-2][pozNava+1] = matTer[LUNGIME-3][pozNava] = '\0';
  83.             pozNava--;
  84.         }
  85.     if(newKey == (char)32){
  86.         matTer[LUNGIME-4][pozNava] = char(248);
  87.     }
  88. }
  89.  
  90. void Delete_Monster(int x, int y)
  91. {
  92.     if(matTer[x][y]=='o' && matTer[x][y-1]=='\0' && matTer[x][y+1]=='\0')
  93.     {
  94.         matTer[x][y] = matTer[x-1][y] = matTer[x-1][y-1]= matTer[x-1][y+1] = matTer[x-2][y-1] = matTer[x-2][y+1] = '\0';
  95.     }
  96.     else
  97.         if(matTer[x][y]=='o' && matTer[x][y-1]=='o' && matTer[x][y+1]=='\0')
  98.             matTer[x+1][y-1] = matTer[x][y-1] = matTer[x][y]= matTer[x][y-2] = matTer[x-1][y] = matTer[x-1][y-2] = '\0';
  99.         else
  100.             if(matTer[x][y]=='o' && matTer[x][y+1]=='o' && matTer[x][y-1]=='\0')
  101.                 matTer[x+1][y+1] = matTer[x][y+1] = matTer[x][y]= matTer[x][y+2] = matTer[x-1][y] = matTer[x-1][y+2] = '\0';
  102. }
  103.  
  104. int Last_monster(int i)
  105. {
  106.     for( int j=4;j<=LUNGIME;j+=4)
  107.         if(matTer[j][i]=='o' && matTer[j+4][i]=='\0')
  108.             return j;
  109.     return 0;
  110.  
  111. }
  112.  
  113. void Generate_Monster_Bullets()
  114. {
  115.         if(Last_monster(3)!=0 && M_ShootRate%50==49)
  116.             matTer[Last_monster(3)+1][3]='.';
  117.         if(Last_monster(7)!=0 && M_ShootRate%50==32)
  118.             matTer[Last_monster(7)+1][7]='.';
  119.         if(Last_monster(11)!=0 && M_ShootRate%50==23)
  120.             matTer[Last_monster(11)+1][11]='.';
  121.         if(Last_monster(15)!=0 && M_ShootRate%50==1)
  122.             matTer[Last_monster(15)+1][15]='.';
  123.         if(Last_monster(19)!=0 && M_ShootRate%50==10)
  124.             matTer[Last_monster(19)+1][19]='.';
  125.         if(Last_monster(23)!=0 && M_ShootRate%50==40)
  126.             matTer[Last_monster(23)+1][23]='.';
  127.         if(Last_monster(27)!=0 && M_ShootRate%50==17)
  128.             matTer[Last_monster(27)+1][27]='.';
  129.         M_ShootRate++;
  130. }
  131.  
  132. void Bullet_Movement ()
  133. {
  134.     int i, j;
  135.     for(i=2;i<=LATIME-1;i++)
  136.         for(j=2;j<=LUNGIME-1;j++)
  137.             {if (matTer[i][j]==char(248))
  138.                 if(i==2)
  139.                         matTer[i][j]='\0';
  140.                 else
  141.                     if(matTer[i-1][j]=='\0')
  142.                         {matTer[i-1][j]=char(248);
  143.                         matTer[i][j]='\0'; }
  144.                     else
  145.                         if(matTer[i-1][j]=='o')
  146.                             {Delete_Monster(i-1, j);
  147.                              matTer[i][j]='\0';
  148.                              Score+= 500; }
  149.                         }
  150.    Generate_Monster_Bullets();
  151.     char aux;
  152.     for(i=2;i<=LATIME-1;i++)
  153.         for(j=2;j<=LUNGIME-1;j++)
  154.             {if(matTer[j][i]=='.')
  155.                 if(matTer[j+1][i]=='\0')
  156.                     {if(M_ShootRate%5==0)
  157.                         {matTer[j+1][i]='.';
  158.                         matTer[j][i]='\0'; j+=2;}
  159.                     }
  160.                 else
  161.                     if(matTer[j+1][i]==char(219))
  162.                         {Player_Lifes--;
  163.                         Sleep(2000);
  164.                         matTer[j][i]='\0';
  165.                         Score-=1000;
  166.                         if(Player_Lifes==0)
  167.                             GAMEEND=TRUE;
  168.                         }
  169.                     else
  170.                         if(matTer[j+1][i]==char(248))
  171.                             {Sleep(120);
  172.                             aux=matTer[j+1][i];
  173.                              matTer[j+1][i]=matTer[j][i];
  174.                              matTer[j][i]=aux;
  175.                             }
  176.                         else
  177.                             if (j==LUNGIME-2)
  178.                                 matTer[j][i]='\0';
  179.  
  180.                 }
  181. }
  182.  
  183. void Create_Monsters()
  184. {
  185.     int i,j;
  186.     for(i=2;i<=LUNGIME/2;i+=4)
  187.         for(j=2;j<=LATIME-3;j+=4)
  188.         {matTer[i][j]= matTer[i][j+2] = matTer[i+1][j] = matTer[i+1][j+1]= matTer[i+1][j+2]=matTer[i+2][j+1]= 'o';
  189.  
  190.         }
  191. }
  192.  
  193. void GameOver_Animation()
  194. {
  195.     gotoxy(11,15);
  196.     cout<<"GAME";
  197.     gotoxy(11,16); cout<<"OVER";
  198.     gotoxy(11,17);
  199.     cout<<"FINAL SCORE: ";
  200.     gotoxy(11,18); cout<<Score;
  201.     Sleep(5500);
  202.     gotoxy(0, 32);
  203.  
  204. }
  205.  
  206. int main (){
  207.     char x,y;
  208.     show_cursor(false);
  209.     while(x!='4' )
  210.     {cout << "_______________________________________________________________________" << endl;
  211.     cout << "|                                                                      |" << endl;
  212.     cout << "|            *       *   ***  *    ***   **   *     *  ***             |" << endl;
  213.     cout << "|             *  *  *    **   *    *    *  *  *  *  *  **              |" << endl;
  214.     cout << "|              *   *     ***  ***  ***   **   *     *  ***             |" << endl;
  215.     cout << "|                                                                      |" << endl;
  216.     cout << "|                                                                      |" << endl;
  217.     cout << "|                      PRESS 1 TO START GAME                           |" << endl;
  218.     cout << "|                     PRESS 2 FOR INSTRUCTIONS                         |" << endl;
  219.     cout << "|                PRESS 3 TO KNOW MORE ABOUT THE GAME                   |" << endl;
  220.     cout << "|                        PRESS 4 TO QUIT                               |" << endl;
  221.     cout << "|______________________________________________________________________|" << endl;
  222.     cin >> x;
  223.     system("cls");
  224.     if(x == '1'){
  225.         creare_teren();
  226.         nava();
  227.         Create_Monsters();
  228.         afisare();
  229.         while (GAMEEND==FALSE)
  230.             {
  231.                 Check_KeyPress();
  232.                 Sleep(100);
  233.                 gotoxy(0, 0);
  234.                 Bullet_Movement();
  235.                 afisare();
  236.                 Score++;
  237.                 cout<<"Scor:"<<Score<<"           "<<"Lifes: ";
  238.                 for(int h=1;h<=Player_Lifes;h++)
  239.                     cout<< char(254)<< ' ';
  240.             }
  241.  
  242.         GameOver_Animation();
  243.         x='4';
  244.         }
  245.     else
  246.         if(x=='2')
  247.             {
  248.             gotoxy(0, 0);
  249.             cout << "_______________________________________________________________________" << endl;
  250.             cout << "|                                                                      |"<< endl;
  251.             cout << "|                  USE 'D' KEY TO MOVE TO RIGHT                        |"<<endl;
  252.             cout << "|                     USE 'A' KEY TO MOVE LEFT                         |"<< endl;
  253.             cout << "|                      USE SPACEBAR TO SHOOT                           |"<< endl;
  254.             cout << "|                                                                      |"<< endl;
  255.             cout << "|        YOUR GOAL IS TO KILL ALL THE INVADERS AND SAVE OUR PLANET     |"<< endl;
  256.             cout << "|            THE WHOLE WORLD COUTS ON YOU. DO NOT DISAPPOINT           |"<< endl;
  257.             cout << "|                   GOOD LUCK IN YOUR JOURNEY                          |"<< endl;
  258.             cout << "|                                                                      |"<< endl;
  259.             cout << "|                 PRESS B TO GO BACK TO MAIN MENU                      |" << endl;
  260.             cout << "|______________________________________________________________________|" << endl;
  261.             cin >> x;
  262.             system("cls");
  263.             }
  264.         else
  265.             if(x=='3')
  266.             {   system("cls");
  267.                 cout << "_______________________________________________________________________" << endl;
  268.                 cout << "|                                                                      |"<< endl;
  269.                 cout << "|                  MADE BY: Aenasoaei Denis-Claudiu                    |"<< endl;
  270.                 cout << "|                   DEVELOPED IN: CODE::BLOCKS IDE                     |"<< endl;
  271.                 cout << "|                 PROFESOR COORDONATOR: Hulea Monica                   |"<< endl;
  272.                 cout << "|                                                                      |"<< endl;
  273.                 cout << "|                   PRESS B TO GO BACK TO MAIN MENU                    |" << endl;
  274.                 cout << "|______________________________________________________________________|" << endl;
  275.                 cin>> x;
  276.                 gotoxy(0,0);
  277.                 system("cls");}
  278.  
  279.     }
  280.  
  281.     return 0;
  282. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement