Marcel12311

C++ game console#1

Apr 12th, 2021 (edited)
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h> // srand() rand()
  3. #include <windows.h> // Sleep()
  4. using namespace std;
  5. class Money;
  6. int wypelnij(int[],const int);
  7. int JustSame(int[],const int);
  8. void ifSame(int[],const int,Money&);
  9. void shop(Money&);
  10. void Game(Money&);
  11. void Stats(Money&);
  12. void levelup(Money&);
  13. void failed(Money&);
  14. class Money{
  15. public:
  16.     int gold;
  17.     int level;
  18.     int expMin;
  19.     int expMax;
  20.     Money(int g,int l,int eMin,int eMax){
  21.         gold=g;
  22.         level=l;
  23.         expMin=eMin;
  24.         expMax=eMax;
  25.     }
  26. };
  27. int main()
  28. {
  29.     Money kasa(100,1,0,10);
  30.     srand(time(NULL));
  31.     Game(kasa);
  32.     return 0;
  33. }
  34. void Game(Money& x){
  35.     levelup(x);
  36.     system("cls");
  37.     int n = 10;
  38.     int tab[n];
  39.     int c=0;
  40.     Stats(x);
  41.     cout<<"\nprint 1 to start game\n";
  42.     cout<<"\nprint 2 go to shop\n";
  43.     cout<<"Enter: ";
  44.     cin >>c;
  45.     switch(c){
  46.     case 1:
  47.         {
  48.             wypelnij(tab,n);
  49.             cout<<"\nwait...\n";
  50.             Sleep(5000);
  51.             system("cls");
  52.             ifSame(tab,n,x);
  53.             break;
  54.         }
  55.     case 2:
  56.         {
  57.             cout<<"\nwait...\n";
  58.             Sleep(5000);
  59.             system("cls");
  60.             shop(x);
  61.             break;
  62.         }
  63.     default:
  64.         {
  65.             cout << "unknown error";exit(0);
  66.         }
  67.     }
  68. }
  69. void levelup(Money& x){
  70.     if(x.expMin >= x.expMax){
  71.         if(x.expMin > x.expMax){
  72.         int bs=0;
  73.         bs=x.expMin-x.expMax;
  74.         x.expMin=0;
  75.         x.expMax*=2;
  76.         x.expMin+=bs;
  77.         }else {x.expMin=0;x.expMax*=2;};
  78.         x.level+=1;
  79.         cout <<"Congratulations! You have reached a higher level!\n";
  80.         Sleep(5000);
  81.         return Game(x);
  82.     }
  83. }
  84. void Stats(Money& x){
  85.     cout << "Money: "<<x.gold<<endl;
  86.     cout<< "---------\n";
  87.     cout<<"Exp:"<<x.expMin<<"/"<<x.expMax<<endl;
  88.     cout<<"Level: "<<x.level<<endl;
  89. }
  90. void shop(Money& x){
  91.     levelup(x);
  92.     int printme=0;
  93.     cout << "|print 1| (100 gold : 1 exp)\n";
  94.     cout << "|print 2| (500 gold : 5 exp)\n";
  95.     cout << "|print 3| (1500 gold : 15 exp)\n";
  96.     cout << "|print 4| (5000 gold : 50 exp)\n";
  97.     cout << "|print 5| (10000 gold : 100 exp)\n";
  98.     cout<< "Enter: ";
  99.     cin >> printme;
  100.     if(printme == 1 && x.gold >= 100){
  101.             cout << "successful transaction!\n";
  102.             x.expMin+=1;
  103.             x.gold-=100;
  104.             Sleep(3000);
  105.             return Game(x);
  106.     }else if(printme == 1 && x.gold < 100){
  107.         failed(x);
  108.     }
  109.     if(printme == 2 && x.gold >= 500){
  110.             cout << "successful transaction!\n";
  111.             x.expMin+=5;
  112.             x.gold-=500;
  113.             Sleep(3000);
  114.             return Game(x);
  115.     }else if(printme == 2 && x.gold < 500){
  116.         failed(x);
  117.     }
  118.     if(printme == 3 && x.gold >= 1500){
  119.             cout << "successful transaction!\n";
  120.             x.expMin+=15;
  121.             x.gold-=1500;
  122.             Sleep(3000);
  123.             return Game(x);
  124.     }else if(printme == 3 && x.gold < 1500){
  125.         failed(x);
  126.     }
  127.     if(printme == 4 && x.gold >= 5000){
  128.             cout << "successful transaction!\n";
  129.             x.expMin+=50;
  130.             x.gold-=5000;
  131.             Sleep(3000);
  132.             return Game(x);
  133.     }else if(printme == 4 && x.gold < 5000){
  134.         failed(x);
  135.     }
  136.     if(printme == 5 && x.gold >= 10000){
  137.             cout << "successful transaction!\n";
  138.             x.expMin+=100;
  139.             x.gold-=10000;
  140.             Sleep(3000);
  141.             return Game(x);
  142.     }else if(printme == 5 && x.gold < 10000){
  143.         failed(x);
  144.     }else {cout << "unknown error\n";exit(0);}
  145. }
  146. void failed(Money& x){
  147.         cout << "sorry but you don't have enough money!\n";
  148.         Sleep(3000);
  149.         return Game(x);
  150. }
  151. int wypelnij(int tab[],const int n)
  152. {
  153.     int losowa=0;
  154.     for(int i=0; i<n; i++)
  155.     {
  156.         losowa = rand()%100+1;
  157.         tab[i]=losowa;
  158.     }
  159.     return* tab;
  160. }
  161. int JustSame(int tab[],const int n)
  162. {
  163.     int a=1;
  164.     int numbs=0;
  165.     for(int i=0; i<n; i++)
  166.     {
  167.         for(int j=a; j<n; j++)
  168.         {
  169.             if(tab[i]==tab[j])
  170.             {
  171.                 numbs++;
  172.             }
  173.         }
  174.         a++;
  175.     }
  176.     return numbs;
  177. }
  178. void ifSame(int tab[],const int n,Money& x)
  179. {
  180.     cout<< "Waiting";
  181.     for(int i=0; i<3; i++)
  182.     {
  183.         cout<<".";
  184.         Sleep(1000);
  185.     }
  186.     if(JustSame(tab,n) == 1)
  187.     {
  188.         x.expMin+=1;
  189.         system("cls");
  190.         cout << "Jackpot!\n";
  191.         cout << "Here your gold: "<<50<<endl;
  192.         x.gold+=50;
  193.         Sleep(3000);
  194.         system("cls");
  195.         return Game(x);
  196.     }else if(JustSame(tab,n) == 2){
  197.         x.expMin+=2;
  198.         system("cls");
  199.         cout << "Jackpot! x2\n";
  200.         cout << "Here your gold: "<<100<<endl;
  201.         x.gold+=100;
  202.         Sleep(3000);
  203.         system("cls");
  204.         return Game(x);
  205.     }else if(JustSame(tab,n) == 3){
  206.         x.expMin+=3;
  207.         system("cls");
  208.         cout << "Jackpot! x3\n";
  209.         cout << "Here your gold: "<<150<<endl;
  210.         x.gold+=150;
  211.         Sleep(3000);
  212.         system("cls");
  213.         return Game(x);
  214.     }else if(JustSame(tab,n) == 4){
  215.         x.expMin+=4;
  216.         system("cls");
  217.         cout << "Jackpot! x4\n";
  218.         cout << "Here your gold: "<<300<<endl;
  219.         x.gold+=300;
  220.         Sleep(4000);
  221.         system("cls");
  222.         return Game(x);
  223.     }else if(JustSame(tab,n) == 5){
  224.         x.expMin+=10;
  225.         system("cls");
  226.         cout << "JACKPOT X5 !!!\n";
  227.         cout << "Here your gold: "<<600<<endl;
  228.         x.gold+=600;
  229.         Sleep(6000);
  230.         system("cls");
  231.         return Game(x);
  232.     }
  233.     else
  234.     {
  235.         cout << "try again...\n";
  236.         Sleep(2500);
  237.         system("cls");
  238.         return Game(x);
  239.     }
  240.  
  241. }
  242.  
Add Comment
Please, Sign In to add comment