Advertisement
TroubleMaker84

Atestat 2.0.1

Apr 27th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 16.78 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. bool GAMEEND = false;
  28. char matTer[LUNGIME][LATIME];
  29. long long Score,M_ShootRate=0;
  30. short int pozNava = 15, Player_Lives=3, Monster_Count=16;
  31. int BulletSpeed,Boss_HP=250;;
  32. void show_cursor(bool show)  //vizibilitate curosor in consola
  33. {
  34.     HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
  35.     CONSOLE_CURSOR_INFO infCursor;
  36.     GetConsoleCursorInfo(out, &infCursor);
  37.     infCursor.bVisible = show;
  38.     SetConsoleCursorInfo(out, &infCursor);
  39. }
  40.  
  41. void afisare()
  42. {
  43.     for (int i = 1; i <= LUNGIME - 1; i++)
  44.     {
  45.         for (int j = 1; j <= LATIME - 1; j++)
  46.             cout << matTer[i][j];
  47.         cout << endl;
  48.     }
  49. }
  50. void creare_teren()
  51. {
  52.     int i;
  53.     for (i = 1; i <= LATIME ; i++)
  54.         matTer[i][1] = matTer[i][LUNGIME - 1] = SIMBOL_MARGINE2;
  55.     for (i = 1; i <= LUNGIME - 1; i++)
  56.         matTer[1][i] = matTer[LATIME - 1][i] = SIMBOL_MARGINE1;
  57. }
  58.  
  59. void nava()
  60. {
  61.     matTer[LUNGIME-2][pozNava-1] = matTer[LUNGIME-2][pozNava] = matTer[LUNGIME-2][pozNava+1] = matTer[LUNGIME-3][pozNava] = (char)223;
  62. }
  63.  
  64. void Check_KeyPress ()
  65. {
  66.     char newKey;
  67.  
  68.     if (_kbhit())
  69.         newKey = _getch();
  70.     if(newKey == 'd' ||newKey == 'D')
  71.         if(pozNava < LATIME-3)
  72.         {
  73.             matTer[LUNGIME-2][pozNava + 2] = matTer[LUNGIME-2][pozNava];
  74.             matTer[LUNGIME-3][pozNava+1] =matTer[LUNGIME-2][pozNava] ;
  75.             matTer[LUNGIME-2][pozNava-1] = matTer[LUNGIME-3][pozNava] = '\0';
  76.             pozNava++;
  77.         }
  78.     if(newKey == 'a' || newKey == 'A')
  79.         if(pozNava > 3)
  80.         {
  81.             matTer[LUNGIME-2][pozNava-2] = matTer[LUNGIME-3][pozNava-1]= char(223);
  82.             matTer[LUNGIME-2][pozNava+1] = matTer[LUNGIME-3][pozNava] = '\0';
  83.             pozNava--;
  84.         }
  85.     if(newKey == (char)32)
  86.     {
  87.         matTer[LUNGIME-4][pozNava] = char(248);
  88.     }
  89. }
  90.  
  91. void Delete_Monster(int x, int y)
  92. {
  93.     if( matTer[x][y-1]=='\0' && matTer[x][y+1]=='\0')
  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.     else if( matTer[x][y-1]=='o' && matTer[x][y+1]=='\0')
  96.         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';
  97.     else if( 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.     Monster_Count--;
  100. }
  101.  
  102. int Last_monster(int i)
  103. {
  104.     for( int j=4; j<=LUNGIME; j+=4)
  105.         if(matTer[j][i]=='o' && matTer[j+4][i]=='\0')
  106.             return j;
  107.     return 0;
  108.  
  109. }
  110.  
  111. void Generate_Monster_Bullets()
  112. {
  113.     int M_Shoot;
  114.     M_Shoot=rand()%76;
  115.     if(Last_monster(3)!=0 && M_Shoot<= 10)
  116.         matTer[Last_monster(3)+1][3]='.';
  117.     if(Last_monster(7)!=0 && M_Shoot>=10 &&M_Shoot<=25 )
  118.         matTer[Last_monster(7)+1][7]='.';
  119.     if(Last_monster(11)!=0 && M_Shoot>=20 && M_Shoot<=35)
  120.         matTer[Last_monster(11)+1][11]='.';
  121.     if(Last_monster(15)!=0 && M_Shoot>=30 && M_Shoot<=45)
  122.         matTer[Last_monster(15)+1][15]='.';
  123.     if(Last_monster(19)!=0 && M_Shoot>=40 && M_Shoot<=55)
  124.         matTer[Last_monster(19)+1][19]='.';
  125.     if(Last_monster(23)!=0 && M_Shoot>=50 && M_Shoot<=65)
  126.         matTer[Last_monster(23)+1][23]='.';
  127.     if(Last_monster(27)!=0 && M_Shoot>=60 && M_Shoot<=75)
  128.         matTer[Last_monster(27)+1][27]='.';
  129.  
  130. }
  131.  
  132. void Bullet_Movement ()
  133. {
  134.     int i, j;
  135.     for(i=3; i<=LATIME-3; i++)
  136.         for(j=3; j<=LUNGIME-3; j++)
  137.         {
  138.             if (matTer[i][j]==char(248))
  139.                 if(i==2)
  140.                     matTer[i][j]='\0';
  141.                 else if(matTer[i-1][j]=='\0')
  142.                 {
  143.                     matTer[i-1][j]=char(248);
  144.                     matTer[i][j]='\0';
  145.                 }
  146.                 else if(matTer[i-1][j]=='o')
  147.                 {
  148.                     Delete_Monster(i-1, j);
  149.                     matTer[i][j]='\0';
  150.                     Score+= 1000;
  151.                 }
  152.         }
  153.     Generate_Monster_Bullets();
  154.     char aux;
  155.     for(i=3; i<=LATIME-3; i++)
  156.         for(j=3; j<=LUNGIME-3; j++)
  157.         {
  158.             if(matTer[j][i]=='.')
  159.                 if(matTer[j+1][i]=='\0')
  160.                 {
  161.                     if(1)
  162.                     {
  163.                         matTer[j+1][i]='.';
  164.                         matTer[j][i]='\0';
  165.                         j++;
  166.                     }
  167.                 }
  168.                 else if(matTer[j+1][i]==char(223))
  169.                 {
  170.                     Player_Lives--;
  171.                     Sleep(1500);
  172.                     matTer[j][i]='\0';
  173.                     Score-=1000;
  174.                     if(Player_Lives==0)
  175.                         GAMEEND=TRUE;
  176.                 }
  177.                 else if(matTer[j+1][i]==char(248))
  178.                 {
  179.                     if(matTer[j+2][i]=='\0' || matTer[j+2][i]==char(223))
  180.                     {
  181.                         Sleep(120);
  182.                         aux=matTer[j+1][i];
  183.                         matTer[j+1][i]=matTer[j][i];
  184.                         matTer[j][i]=aux;
  185.                     }
  186.                     else if(matTer[j+2][i]==char(248))
  187.                         matTer[j][i]='\0';
  188.                 }
  189.                 else if (j==LUNGIME-2)
  190.                     matTer[j][i]='\0';
  191.  
  192.         }
  193.     BulletSpeed++;
  194. }
  195.  
  196.  
  197. void Delete_Bullets()
  198. {
  199.     for(int i=2; i<=LUNGIME-2; i++)
  200.         for(int j=2; j<=LATIME-2; j++)
  201.             if(matTer[i][j]==char(248) || matTer[i][j]=='.')
  202.                 matTer[i][j]='\0';
  203. }
  204.  
  205. void Create_Wave1_Monsters()
  206. {
  207.     int i, j;
  208.     for(j=2; j<=LATIME-3; j+=4)
  209.     {
  210.         matTer[2][j]= matTer[2][j+2] = matTer[3][j] = matTer[3][j+1]= matTer[3][j+2]=matTer[4][j+1]= 'o';
  211.     }
  212.     for(i=6; i<=LUNGIME/2; i+=4)
  213.         for(j=2; j<=LATIME-3; j+=4)
  214.             if(  matTer[i-2][j-3]=='o' && matTer[i-2][j+5]=='o')
  215.                 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';
  216.  
  217.  
  218. }
  219. void Create_Wave2_Monsters()
  220. {
  221.     int i,j;
  222.     for(i=2; i<=LUNGIME/2; i+=4)
  223.         for(j=2; j<=LATIME-3; j+=4)
  224.         {
  225.             Monster_Count++;
  226.             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';
  227.         }
  228.  
  229.  
  230. }
  231.  
  232. void Wave1()
  233. {
  234.     Create_Wave1_Monsters();
  235.     afisare();
  236.     while (GAMEEND==FALSE && Monster_Count!=0)
  237.     {
  238.         Check_KeyPress();
  239.         Sleep(100);
  240.         gotoxy(0, 0);
  241.         Bullet_Movement();
  242.         afisare();
  243.         Score++;
  244.         cout<<"Scor:"<<Score<<"           "<<"Lives: "<<Player_Lives;
  245.     }
  246.     Delete_Bullets();
  247. }
  248.  
  249. void W1_W2_Transition ()
  250. {
  251.     system("cls");
  252.     gotoxy(13,15);
  253.     cout<<"YOU MANAGED TO DEFEAT THESE";
  254.     gotoxy(9,16);
  255.     cout<<"BUT THERE ARE MORE COMING YOUR WAY";
  256.     gotoxy(19,17);
  257.     cout<<"WATCH OUT!!!";
  258.     Sleep(4000);
  259.     system("cls");
  260.  
  261. }
  262.  
  263. void Wave2()
  264. {
  265.     Create_Wave2_Monsters();
  266.     afisare();
  267.     while (GAMEEND==FALSE && Monster_Count!=0)
  268.     {
  269.         Check_KeyPress();
  270.         Sleep(100);
  271.         gotoxy(0, 0);
  272.         Bullet_Movement();
  273.         afisare();
  274.         Score++;
  275.         cout<<"Scor:"<<Score<<"           "<<"Lives: "<<Player_Lives;
  276.  
  277.     }
  278.     Delete_Bullets();
  279. }
  280.  
  281. void W2_B_Transition()
  282. {
  283.     system("cls");
  284.     gotoxy(19,15);
  285.     cout<<"OH NO!!!";
  286.     gotoxy(9,16);
  287.     cout<<"THEY SENT THE BIG GUY AFTER YOU";
  288.     gotoxy(19,17);
  289.     cout<<"LAST ONE";
  290.     gotoxy(10,18);
  291.     cout<<"DEFEAT IT AND SAVE ALL OF US";
  292.     Sleep(4000);
  293.     system("cls");
  294.  
  295. }
  296.  
  297. void Spawn_Boss()
  298. {
  299.     int i;
  300.     matTer[2][5]= matTer[2][LATIME-5] = matTer[3][6]= matTer[3][LATIME-6]=char(219);
  301.     for(i=5; i<=LATIME-5; i++)
  302.         matTer[4][i]=char(219);
  303.     for(i=4; i<=LATIME-4; i++)
  304.         if(i!=8 && i!=21 && i!=10 && i!=9 && i!=20 &&i!=22)
  305.             matTer[5][i]=char(219);
  306.     for(i=3; i<=LATIME-3; i++)
  307.         matTer[6][i]=char(219);
  308.     for(i=3; i<=LATIME-3; i++)
  309.         if(i!=5 && i!=6 && i!=LATIME-5 &&i!= LATIME-6)
  310.             matTer[7][i]=char(219);
  311.     for(i=3; i<=LATIME-3; i++)
  312.         if(i!=5 && i!=6 && i!=LATIME-5 &&i!= LATIME-6)
  313.             matTer[8][i]=char(219);
  314.     matTer[9][3]= matTer[9][4]=matTer[9][7]=matTer[9][8]=matTer[9][LATIME-3]=matTer[9][LATIME-4]=matTer[9][LATIME-7]=matTer[9][LATIME-8]=char(219);
  315.     for (i=7; i<=LATIME-7; i++)
  316.         if(i!=15 && i!= 16 && i!= 14)
  317.             matTer[10][i]=char(219);
  318. }
  319.  
  320. void B_Bullet_Movement()
  321. {
  322.     int i,j;
  323.     for(i=2; i<=LATIME-1; i++)
  324.         for(j=2; j<=LUNGIME-1; j++)
  325.         {
  326.             if (matTer[i][j]==char(248))
  327.             {
  328.                 if(matTer[i-1][j]=='\0')
  329.                 {
  330.                     matTer[i-1][j]=char(248);
  331.                     matTer[i][j]='\0';
  332.                 }
  333.                 else if(matTer[i-1][j]==char(219))
  334.                 {
  335.                     Boss_HP--;
  336.                 }
  337.                 else if(matTer[i-1][j]==char(207) || matTer[i-1][j]==char(220))
  338.                     matTer[i][j]=matTer[i-1][j]='\0';
  339.             }
  340.             if(matTer[i][j]==char(220))
  341.                 {if(i==LUNGIME-2)
  342.                     matTer[i][j]='\0';
  343.                 else
  344.                     if(matTer[i+1][j]=='\0')
  345.                         {matTer[i+1][j]=char(220); matTer[i][j]='\0';}
  346.                     else
  347.                         if(matTer[i+1][j]==char(223))
  348.                         {
  349.                             Player_Lives--;
  350.                             Score-=1000;
  351.                             if(Player_Lives==0)
  352.                                 GAMEEND=TRUE;
  353.                             matTer[i][j]='\0';
  354.                         }
  355.                         else
  356.                             if(matTer[i+1][j]==char(248))
  357.                                 matTer[i][j]=matTer[i+1][j]='\0';}
  358.         }
  359.  
  360. }
  361.  
  362. void Boss_Bullet_Rain()
  363. {
  364.     matTer[10][3]=matTer[10][4]=matTer[10][LATIME-3]=matTer[10][LATIME-4]=char(220);
  365.     int i;
  366.     for(i=8; i<=LATIME-8; i++)
  367.         if(i!=15 && i!= 16 && i!= 14)
  368.             matTer[11][i]=char(220);
  369.     matTer[9][15]=matTer[9][16]=matTer[9][14]= char(220);
  370.  
  371. }
  372. void Boss_Chase_Bullets()
  373. {
  374.     matTer[10][3]=matTer[10][LATIME-3]=char(207);
  375.  
  376. }
  377.  
  378. void Boss_Attack ()
  379. {
  380.     //Boss_Chase_Bullets();
  381.     Boss_Bullet_Rain();
  382.     //if(M_ShootRate%15==0)
  383.     //switch(rand()%3)
  384.  
  385.     //case 0:
  386.  
  387.  
  388.  
  389. }
  390.  
  391. void Boss_Fight()
  392. {
  393.     int i;
  394.     M_ShootRate=0;
  395.     srand(time(NULL));
  396.     creare_teren();
  397.     Spawn_Boss();
  398.     system("cls");
  399.     afisare();
  400.     while(GAMEEND==false && Boss_HP!=0)
  401.     {
  402.         Check_KeyPress();
  403.         B_Bullet_Movement();
  404.         Boss_Attack();
  405.         Sleep(100);
  406.         gotoxy(0,0);
  407.         afisare();
  408.  
  409.     }
  410. }
  411.  
  412. void GameOver_Animation()
  413. {
  414.     Sleep(5000);
  415.     system("cls");
  416.     cout << "_______________________________________________________________________" << endl;
  417.     cout << "|                                                                      |" << endl;
  418.     cout << "|                      ****     *    *   *   ****                      |" << endl;
  419.     cout << "|                      *       * *   * * *   *_                        |" << endl;
  420.     cout << "|                      * **   *****  *   *   *                         | " << endl;
  421.     cout << "|                      ****  *     * *   *   ****                      |" << endl;
  422.     cout << "|                                                                      |" << endl;
  423.     cout << "|                       ****  *     * **** * ***                       |" << endl;
  424.     cout << "|                       *  *   *   *  *_   * * *                       |" << endl;
  425.     cout << "|                       *  *    * *   *    *  *                        |" << endl;
  426.     cout << "|                       ****     *    **** *   *                       |" << endl;
  427.     cout << "|                                                                      |" << endl;
  428.     cout << "|                       FINAL SCORE: " <<Score<<"                             |"<< endl;
  429.     cout << "|                                                                      |" << endl;
  430.     cout << "|______________________________________________________________________|" << endl;
  431.     Sleep(6000);
  432. }
  433.  
  434. int main ()
  435. {
  436.     char x,y;
  437.     show_cursor(false);
  438.  
  439.     while(x!='4' )
  440.     {
  441.         cout << "_______________________________________________________________________" << endl;
  442.         cout << "|                                                                      |" << endl;
  443.         cout << "|            *       *   ***  *    ***   **   *     *  ***             |" << endl;
  444.         cout << "|             *  *  *    **   *    *    *  *  *  *  *  **              |" << endl;
  445.         cout << "|              *   *     ***  ***  ***   **   *     *  ***             |" << endl;
  446.         cout << "|                                                                      |" << endl;
  447.         cout << "|                          SPACE INVADERS                              |" << endl;
  448.         cout << "|                                                                      |" << endl;
  449.         cout << "|                      PRESS 1 TO START GAME                           |" << endl;
  450.         cout << "|                     PRESS 2 FOR INSTRUCTIONS                         |" << endl;
  451.         cout << "|                PRESS 3 TO KNOW MORE ABOUT THE GAME                   |" << endl;
  452.         cout << "|                        PRESS 4 TO QUIT                               |" << endl;
  453.         cout << "|______________________________________________________________________|" << endl;
  454.         cin >> x;
  455.  
  456.         system("cls");
  457.         if(x == '1')
  458.         {
  459.             creare_teren();
  460.             nava();
  461.             Boss_Fight();
  462.             Wave1();
  463.             if(GAMEEND==FALSE)
  464.             {
  465.                 W1_W2_Transition();
  466.                 Wave2();
  467.             }
  468.             if(GAMEEND==FALSE)
  469.             {
  470.                 W2_B_Transition();
  471.                 Boss_Fight();
  472.             }
  473.             GameOver_Animation();
  474.             x='4';
  475.         }
  476.         else if(x=='2')
  477.         {
  478.             gotoxy(0, 0);
  479.             cout << "_______________________________________________________________________" << endl;
  480.             cout << "|                                                                      |"<< endl;
  481.             cout << "|                   USE 'D' KEY TO MOVE TO RIGHT                       |"<<endl;
  482.             cout << "|                     USE 'A' KEY TO MOVE LEFT                         |"<< endl;
  483.             cout << "|                      USE SPACEBAR TO SHOOT                           |"<< endl;
  484.             cout << "|                                                                      |"<< endl;
  485.             cout << "|        YOUR GOAL IS TO KILL ALL THE INVADERS AND SAVE OUR PLANET     |"<< endl;
  486.             cout << "|            THE WHOLE WORLD COUTS ON YOU. DO NOT DISAPPOINT           |"<< endl;
  487.             cout << "|                      GOOD LUCK IN YOUR JOURNEY                       |"<< endl;
  488.             cout << "|                                                                      |"<< endl;
  489.             cout << "|                   PRESS B TO GO BACK TO MAIN MENU                    |" << endl;
  490.             cout << "|______________________________________________________________________|" << endl;
  491.             cin >> x;
  492.             system("cls");
  493.         }
  494.         else if(x=='3')
  495.         {
  496.             system("cls");
  497.             cout << "_______________________________________________________________________" << endl;
  498.             cout << "|                                                                      |"<< endl;
  499.             cout << "|                  MADE BY: Aenasoaei Denis-Claudiu                    |"<< endl;
  500.             cout << "|                   DEVELOPED IN: CODE::BLOCKS IDE                     |"<< endl;
  501.             cout << "|                 PROFESOR COORDONATOR: Hulea Monica                   |"<< endl;
  502.             cout << "|                                                                      |"<< endl;
  503.             cout << "|                   PRESS B TO GO BACK TO MAIN MENU                    |" << endl;
  504.             cout << "|______________________________________________________________________|" << endl;
  505.             cin>> x;
  506.             system("cls");
  507.         }
  508.  
  509.     }
  510.  
  511.     return 0;
  512. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement