Advertisement
TroubleMaker84

Untitled

Mar 6th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 17.42 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 LUNGIME 92
  10. #define LATIME 20
  11. #define SIMBOL_MARGINE1 '-'
  12. #define SIMBOL_MARGINE2 '|'
  13.  
  14. using namespace std;
  15.  
  16. struct Monstru{
  17.     int HP, poz, pozy;
  18.     char FORMA[5][7], LASER;
  19. };
  20. Monstru M1, M2, M3, M4, R;
  21. struct wave {
  22.     int Wave_Size;
  23.     Monstru  Monster[Wave_Size];
  24.     int monster_type[Wave_Size];
  25.     }Wave1, Wave2,Wave3, Wave4;
  26. void wave1
  27.    
  28. int sh = 1;
  29. bool GAMEEND = false;
  30. char matTer[LATIME][LUNGIME];
  31. short int pozNava = 4;
  32.  
  33. void m1 (){
  34.     M1.pozy = 88;
  35.     do
  36.         M1.poz = rand() % 19;
  37.     while (
  38.         M1.poz < 3 ||
  39.         matTer[M1.poz][M1.pozy] != '\0' ||
  40.         matTer[M1.poz][M1.pozy + 1] != '\0' ||
  41.         matTer[M1.poz - 1][M1.pozy + 1] != '\0' ||
  42.         matTer[M1.poz + 1][M1.pozy + 1] != '\0' ||
  43.         matTer[M1.poz - 1][M1.pozy + 2] != '\0'||
  44.         matTer[M1.poz][M1.pozy + 2] != '\0'||
  45.         matTer[M1.poz + 1][M1.pozy + 2] != '\0'
  46.     );
  47.     matTer[M1.poz][M1.pozy] = M1.FORMA[2][1];
  48.     matTer[M1.poz - 1][M1.pozy + 2] =
  49.     matTer[M1.poz][M1.pozy + 2] =
  50.     matTer[M1.poz + 1][M1.pozy + 2] =
  51.     matTer[M1.poz - 1][M1.pozy + 1] =
  52.     matTer[M1.poz][M1.pozy + 1] =
  53.     matTer[M1.poz + 1][M1.pozy + 1] =
  54.     M1.FORMA[2][2];
  55.  
  56. }
  57. void m2(){
  58.     M2.pozy = 88;
  59.     do
  60.         M2.poz = rand() % 18;
  61.     while (M2.poz < 3 || matTer[M2.poz][M2.pozy] != '\0' || matTer[M2.poz][M2.pozy + 1] != '\0' || matTer[M2.poz][M2.pozy + 2] != '\0');
  62.     matTer[M2.poz][M2.pozy] =
  63.     matTer[M2.poz][M2.pozy + 1] =
  64.     matTer[M2.poz][M2.pozy + 2] =
  65.     M2.FORMA[1][1];
  66. }
  67.  
  68. void m3(){
  69.     M3.pozy = 88;
  70.     do
  71.         M3.poz = rand() % 18;
  72.     while (
  73.         M3.poz < 3 ||
  74.         matTer[M3.poz][M3.pozy] != '\0' ||
  75.         matTer[M3.poz][M3.pozy + 1] != '\0' ||
  76.         matTer[M3.poz - 1][M3.pozy + 1] != '\0' ||
  77.         matTer[M3.poz + 1][M3.pozy + 1] != '\0' ||
  78.         matTer[M3.poz - 1][M3.pozy + 2] != '\0' ||
  79.         matTer[M3.poz + 1][M3.pozy + 2] != '\0'
  80.     );
  81.     matTer[M3.poz][M3.pozy] =
  82.     matTer[M3.poz][M3.pozy + 1] =
  83.     matTer[M3.poz - 1][M3.pozy + 1] =
  84.     matTer[M3.poz - 1][M3.pozy + 2] =
  85.     matTer[M3.poz + 1][M3.pozy + 1] =
  86.     matTer[M3.poz + 1][M3.pozy + 2] =
  87.     M3.FORMA[2][1];
  88. }
  89.  
  90. void m4(){
  91.     M4.pozy = 88;
  92.     do
  93.         M4.poz = rand() %  16;
  94.     while (
  95.         M4.poz < 5 ||
  96.         matTer[M4.poz - 1][M4.pozy - 1] != '\0' ||
  97.         matTer[M4.poz][M4.pozy - 1] != '\0' ||
  98.         matTer[M4.poz][M4.pozy + 2] != '\0' ||
  99.         matTer[M4.poz + 1][M4.pozy - 1] != '\0' ||
  100.         matTer[M4.poz - 1][M4.pozy - 2] != '\0' ||
  101.         matTer[M4.poz + 1][M4.pozy - 2] != '\0' ||
  102.         matTer[M4.poz - 1][M4.pozy] != '\0' ||
  103.         matTer[M4.poz - 1][M4.pozy + 1] != '\0' ||
  104.         matTer[M4.poz + 1][M4.pozy] != '\0'||
  105.         matTer[M4.poz + 1][M4.pozy+1] != '\0' ||
  106.         matTer[M4.poz - 1][M4.pozy+2] != '\0'||
  107.         matTer[M4.poz + 1][M4.pozy + 2] != '\0' ||
  108.         matTer[M4.poz][M4.pozy] != '\0' ||
  109.         matTer[M4.poz][M4.pozy + 1] != '\0'
  110.     );
  111.  
  112.     matTer[M4.poz -1][M4.pozy-1]=M4.FORMA[1][2];
  113.     matTer[M4.poz][M4.pozy-1]=matTer[M4.poz][M4.pozy+2]=M4.FORMA[2][2];
  114.     matTer[M4.poz +1][M4.pozy-1]=M4.FORMA[4][1];
  115.     matTer[M4.poz-1][M4.pozy-2]=matTer[M4.poz +1][M4.pozy-2]=M4.FORMA[1][1];
  116.     matTer[M4.poz -1 ][M4.pozy]=matTer[M4.poz -1][M4.pozy+1]=matTer[M4.poz +1][M4.pozy]=matTer[M4.poz +1][M4.pozy+1]=M4.FORMA[1][3];
  117.     matTer[M4.poz -1][M4.pozy+2]=M4.FORMA[1][6];
  118.     matTer[M4.poz+1][M4.pozy+2]=M4.FORMA[4][6];
  119.     matTer[M4.poz][M4.pozy]=matTer[M4.poz][M4.pozy+1]=M4.FORMA[3][3];
  120. }
  121.  
  122. void r(){
  123.     R.pozy = 86;
  124.     do
  125.         R.poz = rand () % 18;
  126.     while (
  127.         R.poz<2 ||
  128.         matTer[R.poz][R.pozy] != '\0' ||
  129.         matTer[R.poz - 1][R.pozy + 1] != '\0' ||
  130.         matTer[R.poz - 1][R.pozy + 2] != '\0' ||
  131.         matTer[R.poz - 1][R.pozy + 3] != '\0' ||
  132.         matTer[R.poz][R.pozy + 1] != '\0' ||
  133.         matTer[R.poz][R.pozy + 2] != '\0' ||
  134.         matTer[R.poz][R.pozy + 3] != '\0'
  135.     );
  136.     matTer[R.poz][R.pozy + 4] = R.FORMA[2][4];
  137.     matTer[R.poz - 1][R.pozy + 1] = matTer[R.poz - 1][R.pozy + 2] = matTer[R.poz - 1][R.pozy + 3] = R.FORMA[1][2];
  138.     matTer[R.poz][R.pozy + 1] = matTer[R.poz][R.pozy + 2] = matTer[R.poz][R.pozy + 3] = R.FORMA[1][2];
  139.     matTer[R.poz][R.pozy] = R.FORMA[2][1];
  140. }
  141.  
  142. void show_cursor(bool show){ //vizibilitate curosor in consola
  143.     HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
  144.     CONSOLE_CURSOR_INFO infCursor;
  145.     GetConsoleCursorInfo(out, &infCursor);
  146.     infCursor.bVisible = show;
  147.     SetConsoleCursorInfo(out, &infCursor);
  148. }
  149.  
  150. int check (char x){
  151.     int i,j;
  152.     for(i = 1; i <= 3; i++)
  153.         for(j = 1; j <= 3; j++)
  154.             if (x == M1.FORMA[i][j])
  155.                 return 1;
  156.     if (x == M2.FORMA[1][1])
  157.         return 2;
  158.     for(i = 1; i <= 3; i++)
  159.         for(j = 1;j <= 3; j++)
  160.             if (x == M3.FORMA[i][j])
  161.                 return 3;
  162.     for(i = 1; i <= 5; i++)
  163.         for(j = 1; j <= 4; j++)
  164.             if (x == M4.FORMA[i][j])
  165.                 return 4;
  166.     for(i = 1; i <= 2; i++)
  167.         for(j = 1; j <= 4; j++)
  168.             if(x == R.FORMA[i][j])
  169.                 return 5;
  170.     return 0;
  171. }
  172.  
  173. void DEL_M1(){
  174.     for(int i = M1.poz - 1; i <= M1.poz + 1; i++)
  175.         for(int j = M1.pozy; j <= M1.pozy + 3; j++)
  176.                 matTer[i][j]='\0';
  177. }
  178. void DEL_M2(){
  179.     for(int j = M2.pozy; j <= M2.pozy + 2; j++)
  180.         matTer[M2.poz][j]='\0';
  181. }
  182. void DEL_M3(){
  183.     for(int i = M3.poz - 1; i <= M3.poz + 1; i++)
  184.         for(int j = M3.pozy; j <= M3.pozy + 2; j++)
  185.             if(matTer[i][j] == 'O')
  186.                 matTer[i][j] = '\0';
  187. }
  188. void DEL_M4(){
  189.     for(int i = M4.poz - 1; i <= M4.poz + 2; i++)
  190.         for(int j = M4.pozy - 2; j <= M4.pozy + 3; j++)
  191.             if(check(matTer[i][j]) == 4)
  192.                 matTer[i][j]='\0';
  193. }
  194.  
  195. void afisare(){
  196.     for (int i = 1; i <= LATIME - 1; i++){
  197.         for (int j = 1; j <= LUNGIME - 1; j++)
  198.                 cout << matTer[i][j];
  199.         cout << endl;
  200.         }
  201. }
  202.  
  203. void creare_teren(){
  204.     int i;
  205.     for (i = 1; i <= LATIME - 1; i++)
  206.         matTer[i][1] = matTer[i][LUNGIME - 1] = SIMBOL_MARGINE2;
  207.     for (i = 1; i <= LUNGIME - 1; i++)
  208.         matTer[1][i] = matTer[LATIME - 1][i] = SIMBOL_MARGINE1;
  209. }
  210.  
  211. void nava(){
  212.     matTer[2][2] = matTer[3][2] = matTer[4][2] = matTer[3][3] = (char)219;
  213. }
  214.  
  215. void miscare(){
  216.     char newKey;
  217.     int i,j;
  218.     if (_kbhit())
  219.         newKey = getch();
  220.     if(newKey == 's' ||newKey == 'S')
  221.         if(pozNava < 18){
  222.             matTer[pozNava + 1][2] = matTer[pozNava][2];
  223.             matTer[pozNava ][3] = matTer[pozNava-1][3];
  224.             matTer[pozNava - 2][2] = matTer[pozNava-1][3] = '\0';
  225.             pozNava++;
  226.         }
  227.     if(newKey == 'w' || newKey == 'W')
  228.         if(pozNava > 4){
  229.             matTer[pozNava - 3][2] = matTer[pozNava][2];
  230.             matTer[pozNava - 2][3] = matTer[pozNava - 1][3];
  231.             matTer[pozNava][2] = matTer[pozNava - 1][3] = '\0';
  232.             pozNava--;
  233.         }
  234.     if(newKey == (char)32){
  235.         if (matTer[pozNava - 1][4] != '\0')
  236.             matTer[pozNava - 1][4] = '\0';
  237.         matTer[pozNava - 1][4] = char(248);
  238.     }
  239.  
  240.     //sh, "shoot" in prima faza, era o variabila cu care voiam sa controlez rata la care trag navele lor
  241.     if(sh % 25 == 1 && M1.HP != 0)
  242.         matTer[M1.poz][M1.pozy - 1] = M1.LASER;
  243.     if(sh % 25 == 7 && M2.HP != 0)
  244.         matTer[M2.poz][M2.pozy - 1] = M2.LASER;
  245.     if(sh % 25 == 13 && M3.HP != 0)
  246.         matTer[M3.poz][M3.pozy - 1] = M3.LASER;
  247.     if(sh % 25 == 17 && M4.HP != 0)
  248.         matTer[M4.poz - 1][M4.pozy - 3] = matTer[M4.poz + 1][M4.pozy - 3] = M4.LASER;
  249.     sh++;
  250.     for(i = 2; i <= LATIME - 2; i++)
  251.         for(j = 2 ; j <= LUNGIME - 2; j++)
  252.         {if(matTer[i][j] == (char)248)
  253.             {
  254.                 if(
  255.                     matTer[i][j + 2] == M1.LASER ||
  256.                     matTer[i][j + 2] == M2.LASER ||
  257.                     matTer[i][j + 2] == M3.LASER ||
  258.                     matTer[i][j + 2] == M4.LASER ||
  259.                     matTer[i][j + 1] == M1.LASER ||
  260.                     matTer[i][j + 1] == M2.LASER ||
  261.                     matTer[i][j + 1] == M3.LASER ||
  262.                     matTer[i][j + 1] == M4.LASER
  263.                 )
  264.                     matTer[i][j + 2] = matTer[i][j + 1] = '\0';
  265.                 else
  266.                     if(matTer[i][j + 2] == '\0'){
  267.                         if(j < LUNGIME - 3){
  268.                             matTer[i][j + 2] = (char)248;
  269.                             matTer[i][j] = '\0';
  270.                             j = j + 2;
  271.                         }
  272.                         else
  273.                             matTer[i][j]='\0';
  274.                     }
  275.                     else{
  276.                         switch (check(matTer[i][j + 2]))
  277.                         {                                   //de aici si pana la urmatorul, verific ce "monstru" a lovit
  278.                         case 1:{                            // printr-un switch care verifica acel caracter care este in 2 pozitii
  279.                             M1.HP -= 1;                     //unde ar trebui sa se mute glontele
  280.                             if(M1.HP == 0)
  281.                             DEL_M1();
  282.                             break;
  283.                         }
  284.                         case 2:{
  285.                             M2.HP = 0; //daca distrugi nava, nici sa nu mai traga
  286.                             DEL_M2();
  287.                             break;
  288.                         }
  289.                         case 3:{
  290.                             M3.HP--;
  291.                             if(M3.HP == 0)
  292.                                 DEL_M3();
  293.                             break;
  294.                         }
  295.                         case 4:{
  296.                             if(matTer[M4.poz][M4.pozy]=='\0')
  297.                                     {
  298.                                     Sleep(10000);}
  299.                             M4.HP--;
  300.                             if(M4.HP==0){
  301.                                 DEL_M4();}
  302.                             break;
  303.                         }
  304.                         default: break;
  305.                         }
  306.                         matTer[i][j]='\0';
  307.                     }        //daca s-a intrat pe acel else, se loveste de ceva, fac ce fac, si dupa sterg glontele
  308.             }
  309.             else
  310.                 if(matTer[i][j] == M1.LASER || matTer[i][j] == M2.LASER || matTer[i][j] == M3.LASER || matTer[i][j] == M4.LASER){
  311.                     if (matTer[i][j - 2] == char(219) || matTer[i][j - 1] == char(219))
  312.                         GAMEEND=TRUE;       //daca esti lovit, se termina jocul
  313.                     else
  314.                         if(j==3){
  315.                             matTer[i][j] = '\0';      //daca glontele lui a ajuns la coloana 3, dispare
  316.                         }
  317.                         else
  318.                             if(j > 3){
  319.                                 matTer[i][j-1]=matTer[i][j];
  320.                                 matTer[i][j]='\0';
  321.                             }         //il tot mut cu o pozitie la fiecare parcurgere
  322.                 }
  323.                 else{
  324.                     if(sh % 3 == 0){     //"sh" a devenit si rata la care se misca navele, ca nu vreau sa o faca mereu
  325.                         if(matTer[i][j] != '\0' && matTer[i][j] != char(219))
  326.                             if(check(matTer[i][j])==1){              //toate if/else verifica muta componenta unei nave
  327.                                 if(M1.pozy == 3){       //si in caz ca ajunge la final, o face sa dispara
  328.                                     if(matTer[i][j - 1] == char(219))
  329.                                         GAMEEND=TRUE;
  330.                                     else{
  331.                                         DEL_M1();
  332.                                         M1.HP=0;
  333.                                     }
  334.                                 }
  335.                                 matTer[i][j - 1] = matTer[i][j];
  336.                                 if(i == M1.poz && j == M1.pozy)
  337.                                     M1.pozy--;
  338.                             }
  339.                             else
  340.                                 if(check(matTer[i][j]) == 2){
  341.                                     if(M2.pozy == 3){
  342.                                         if(matTer[i][j - 1] == char(219))
  343.                                             GAMEEND = TRUE;
  344.                                         else{
  345.                                             DEL_M2();
  346.                                             M2.HP = 0;
  347.                                         }
  348.                                     }
  349.                                     matTer[i][j - 1] = matTer[i][j];
  350.                                     if(i == M2.poz && j == M2.pozy)
  351.                                         M2.pozy--;
  352.                                 }
  353.                                 else
  354.                                     if(check(matTer[i][j]) == 3){
  355.                                         if(M3.pozy == 3){
  356.                                             if(matTer[i][j - 1] == char(219))
  357.                                                 GAMEEND = TRUE;
  358.                                             else{
  359.                                                 DEL_M3();
  360.                                                 M3.HP = 0;
  361.                                             }
  362.                                         }
  363.                                         matTer[i][j - 1] = matTer[i][j];
  364.                                         if(i == M3.poz && j == M3.pozy)
  365.                                             M3.pozy--;
  366.                                     }
  367.                                     else
  368.                                         if(check(matTer[i][j]) == 4){
  369.                                             if(M4.pozy == 4){
  370.                                                 if(matTer[i][j - 1] == char(219))
  371.                                                     GAMEEND = TRUE;
  372.                                                 else{
  373.                                                     DEL_M4();
  374.                                                     M4.HP = 0;
  375.                                                 }
  376.                                             }
  377.                                             matTer[i][j - 1] = matTer[i][j];
  378.                                             if(i == M4.poz && j == M4.pozy)
  379.                                                 M4.pozy--;
  380.                                         }
  381.                         if(matTer[i][j] != char(219))
  382.                             matTer[i][j] = '\0';
  383.                     }
  384.                 }
  385.  
  386.  
  387.         }}
  388.  
  389. int main (){
  390.     char x;
  391.     cout << "_______________________________________________________________________" << endl;
  392.     cout << "|                                                                      |" << endl;
  393.     cout << "|          *       *   ***  *    ***   **   *     *  ***               |" << endl;
  394.     cout << "|           *  *  *    **   *    *    *  *  *  *  *  **                |" << endl;
  395.     cout << "|            *   *     ***  ***  ***   **   *     *  ***               |" << endl;
  396.     cout << "|                                                                      |" << endl;
  397.     cout << "|                                                                      |" << endl;
  398.     cout << "|            PRESS 1 TO START GAME                                     |" << endl;
  399.     cout << "|            PRESS 2 TO EXIT                                           |" << endl;
  400.     cout << "_______________________________________________________________________" << endl;
  401.     cin >> x;
  402.     system("cls");
  403.     if(x == '1'){
  404.         creare_teren();
  405.         show_cursor(false);
  406.         M1.HP = 3;
  407.         M2.HP = 1;
  408.         M3.HP = 4;
  409.         M4.HP = 6;
  410.         M1.FORMA[2][1] = (char)174;
  411.         M1.FORMA[1][2] = M1.FORMA[2][2] = M1.FORMA[3][2] = (char)254;
  412.         M2.FORMA[1][1] = M2.FORMA[1][2] = M2.FORMA[1][3] = char(178);
  413.         M3.FORMA[2][1] = M3.FORMA[2][2] = M3.FORMA[1][2] = M3.FORMA[1][3] = M3.FORMA[3][2] = M3.FORMA[3][3] = 'O';
  414.         R.FORMA[2][1] = '<';
  415.         R.FORMA[1][2] = R.FORMA[1][3] = R.FORMA[2][2] = R.FORMA[2][3] = '_';
  416.         R.FORMA[2][4] = '|';
  417.         M4.FORMA[1][1] = M4.FORMA[4][1] = '-';
  418.         M4.FORMA[1][2] = char(201);
  419.         M4.FORMA[1][6] = char(187);
  420.         M4.FORMA[2][2] = M4.FORMA[3][2] = char(186);
  421.         M4.FORMA[1][3] = M4.FORMA[1][4] = M4.FORMA[1][5] = M4.FORMA[4][3] = M4.FORMA[4][4] = M4.FORMA[4][5] = char(205);
  422.         M4.FORMA[2][6] = M4.FORMA[3][6] = char(186);
  423.         M4.FORMA[4][1] = char(200);
  424.         M4.FORMA[4][6] = char(188);
  425.         M4.FORMA[3][2] = M4.FORMA[3][3] = ' ';
  426.         srand(time(NULL));
  427.         m1();
  428.         m2();
  429.         m3();
  430.         m4();
  431.         r();
  432.         nava();
  433.         M1.LASER = char (223);
  434.         M2.LASER = '=';
  435.         M3.LASER = char(249);
  436.         M4.LASER = '~';
  437.         Wa1[1] = M1;
  438.         afisare();
  439.         system("cls");
  440.         while(GAMEEND==FALSE){
  441.                 miscare();
  442.                 Sleep(50);
  443.                 system("cls");
  444.                 afisare();
  445.  
  446.                 if(M1.HP == 0 && M2.HP == 0 && M3.HP == 0 && M4.HP == 0){
  447.                     GAMEEND=TRUE;
  448.                     cout << "CONGRATS";
  449.                 }
  450.         }
  451.     }
  452.     else
  453.         if(x == '2')
  454.           cout << "GAME OVER";
  455.           exit(0);
  456.     return 0;
  457. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement