Advertisement
PedalaVasile

Nume_Inspirat_Pentru_Un_Joc_!Interesant

Jan 31st, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.03 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <windows.h>
  3. #include <conio.h>
  4.  
  5. using namespace std;
  6.  
  7. int Nr_Inamici = 2;
  8. int morti = 0;
  9. int N = 5;
  10.  
  11. char Tabla[100][100];
  12.  
  13. const int Tick = 10000;
  14.  
  15. ///Player setting
  16. const int D_Max_Player_Heal = 100;
  17. const int D_Max_Player_Damage = 10;
  18. const int D_Player_i = 1;
  19. const int D_Player_j = 1;
  20.  
  21. ///Inamic TIP 1
  22. const int D_Max_T1_Heal = 50;
  23. const int D_Max_T1_Damage = 2;
  24.  
  25. struct Player
  26. {
  27.     int i = D_Player_i;
  28.     int j = D_Player_j;
  29.     int heal = D_Max_Player_Heal;
  30.     int damage = D_Max_Player_Damage;
  31. };
  32.  
  33.  
  34. struct InamiciTip1
  35. {
  36.     int i, j;
  37.     int heal = D_Max_T1_Heal;
  38.     int damage = D_Max_T1_Damage;
  39.     bool mort = false;
  40. } A[3];
  41.  
  42. Player P;
  43.  
  44.  
  45. void Creeaza()
  46. {
  47.     for(int i = 1; i <= N; i++)
  48.         for(int j = 1; j <= N; j++)
  49.             Tabla[i][j] = '-';
  50.  
  51.     Tabla[1][1] = 'P';
  52.     return;
  53. }
  54.  
  55. bool verificare(int i, int j)
  56. {
  57.     return (i == N && j == N);
  58. }
  59.  
  60. void A_T()
  61. {
  62.     system("cls");
  63.     for(int i = 1; i <= N; i++)
  64.     {
  65.         for(int j = 1; j <= N; j++)
  66.             cout << Tabla[i][j] << ' ';
  67.  
  68.         cout << '\n';
  69.     }
  70.  
  71.     cout << "Heal: " << P.heal;
  72. }
  73.  
  74. int FindCoord(int i, int j)
  75. {
  76.     for(int k = 0; k < Nr_Inamici; k++)
  77.         if(A[k].i == i && A[k].j == j)
  78.             return k;
  79. }
  80.  
  81. void G_Key()
  82. {
  83.     int c = 0;
  84.  
  85.     while(!_kbhit())
  86.     {
  87.         ///ASTA II MISCAREA INAMICIILOR
  88.         ///E FOARTE PROASTA SO INCA MAI LUCREZ LA EA
  89.  
  90.         /**c += 2;
  91.  
  92.         if(c == Tick)
  93.         {
  94.             c = 0;
  95.  
  96.             char dir = rand() % 4;
  97.  
  98.             /// 0 -> w
  99.             /// 1 -> a
  100.             /// 2 -> s
  101.             /// 3 -> d
  102.  
  103.             for(int i = 0; i < Nr_Inamici; i++)
  104.             {
  105.                 if(A[i].mort == false)
  106.                 {
  107.                     Tabla[A[i].i][A[i].j] = '-';
  108.                     switch(dir)
  109.                     {
  110.                     case 0:
  111.                         if(A[i].i > 1)
  112.                             A[i].i--;
  113.                         else
  114.                             dir++;
  115.                         break;
  116.  
  117.                     case 1:
  118.                         if(A[i].j > 1)
  119.                             A[i].j--;
  120.                         else
  121.                             dir++;
  122.                         break;
  123.  
  124.                     case 2:
  125.                         if(A[i].i < N)
  126.                             A[i].i++;
  127.                         else
  128.                             dir++;
  129.                         break;
  130.                     case 3:
  131.                         if(A[i].j < N)
  132.                             A[i].j++;
  133.                         else
  134.                             dir++;
  135.                         break;
  136.                     }
  137.  
  138.                     dir %= 4;
  139.  
  140.                     int di[] = {+1, -1, +0, +0};
  141.                     int dj[] = {+0, +0, +1, -1};
  142.  
  143.                     bool oke = false;
  144.  
  145.                     for(int z = 0; z < 4; z++)
  146.                     {
  147.                         int nexti = A[i].i + di[z];
  148.                         int nextj = A[i].j + dj[z];
  149.  
  150.                         if(nexti == P.i && nextj == P.j)
  151.                         {
  152.                             cout << "Ti am dat Damage!!!\n";
  153.                             P.heal -= rand() % A[i].damage + 1, oke = true;}
  154.                     }
  155.  
  156.                     if(oke == false)
  157.                         Tabla[A[i].i][A[i].j] = 'I';
  158.                 }
  159.             }
  160.         }*/
  161.     }
  162.  
  163.     int I = P.i;
  164.     int J = P.j;
  165.  
  166.     if(_kbhit())
  167.         switch(_getch())
  168.         {
  169.         case 'w':
  170.             if(P.i > 1)
  171.                 P.i--;
  172.             break;
  173.  
  174.         case 'a':
  175.             if(P.j > 1)
  176.                 P.j--;
  177.             break;
  178.  
  179.         case 's':
  180.             if(P.i < N)
  181.                 P.i++;
  182.             break;
  183.  
  184.         case 'd':
  185.             if(P.j < N)
  186.                 P.j++;
  187.             break;
  188.         }
  189.  
  190.     if(Tabla[P.i][P.j] == 'I')
  191.     {
  192.         int k = FindCoord(P.i, P.j);
  193.  
  194.         while(A[k].heal > 0)
  195.         {
  196.             int Damage_To_I = rand() % P.damage + 1;
  197.             int Damage_From_I = rand() % A[k].damage;
  198.  
  199.             P.heal -= Damage_From_I;
  200.             A[k].heal -= Damage_To_I;
  201.  
  202.             if(P.heal < 0)
  203.                 exit(0);
  204.         }
  205.  
  206.         A[k].mort = true;
  207.         morti++;
  208.  
  209.         Tabla[P.i][P.j] = 'P';
  210.     }
  211. }
  212.  
  213.  
  214. int main()
  215. {
  216.     srand(time(0));
  217.     cout << "Dimensiunea tablei de joc (maxim 100): ";
  218.     cin >> N;
  219.     cout << "Nr total de inamici (maxim " << N * N - 1 << "): ";
  220.     cin >> Nr_Inamici;
  221.     cout << "Pozitiile inamicilor (i, j): ";
  222.  
  223.     Creeaza();
  224.  
  225.     for(int i = 0; i < Nr_Inamici; i++)
  226.         {
  227.             cin >> A[i].i >> A[i].j;
  228.             Tabla[A[i].i][A[i].j] = 'I';
  229.         }
  230.  
  231.     A_T();
  232.  
  233.     START:
  234.  
  235.     do
  236.     {
  237.  
  238.         Tabla[P.i][P.j] = '-';
  239.         G_Key();
  240.         Tabla[P.i][P.j] = 'P';
  241.         A_T();
  242.  
  243.     }
  244.     while( (P.i != N || P.j != N));
  245.  
  246.     if(morti != Nr_Inamici)
  247.         goto START;
  248.  
  249.     return 0;
  250. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement