Advertisement
Fiszu

Untitled

Feb 29th, 2016
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <time.h>
  4. #include <windows.h>
  5. #include <string>
  6. #include <stdio.h>
  7. #include <conio.h>
  8. #include <math.h>
  9. using namespace std;
  10.  
  11.  
  12. void loosemusic()
  13.    {
  14.     Beep (131,500);
  15.     Beep (123,500);
  16.     Beep (110,500);
  17.     Beep (104,1000);
  18.  
  19.    }
  20.  
  21.  
  22.  
  23. void winmusic()
  24.    {
  25.        int gama[6];
  26.  
  27.    gama[0]=262;
  28.    gama[1]=294;
  29.    gama[2]=330;
  30.    gama[3]=349;
  31.    gama[4]=392;
  32.    gama[5]=440;
  33.    gama[6]=494;
  34.  
  35.     Beep(gama[0],200);
  36.     Beep(gama[0],200);
  37.     Beep(gama[2],200);
  38.     Beep(gama[4],400);
  39.     Beep(gama[2],200);
  40.     Beep(gama[4],800);
  41.  
  42.    }
  43.  
  44. int main() {
  45.     int i,E=1,l=1,pot,w1=0,w2=0,wo1=0,wo2=0,m,u,length,maxlength,note;
  46.     float rounds;
  47.     unsigned long long n,n1,n2,R,q;
  48.    string name1;
  49.    string name2;
  50.  
  51.  
  52.  
  53.  
  54.  
  55.    for(E; E<2; E)
  56.    {
  57.  
  58.  
  59.  
  60.  
  61.     cout << "Press 1 for player Vs Pc mode, press 2 for two players mode, press 3 to learn how does Collatz Conjecture work:"<<endl<<endl<<endl;
  62.     cin >>m;
  63.  
  64.     if (m==3)
  65.     {
  66.         cout<<"Program takes your number then, checks is it even or odd. If it's even it divides it by 2, if it is odd it multiply it by 3 and add 1. It does that until it reaches 1."<<endl<<endl<<endl;;
  67.         cout<<"For example, you chose number 5."<<endl;
  68.         cout<<"5-odd so   5*3+1=16 "<<endl;
  69.         cout<<"16-even so 16/2=8"<<endl;
  70.         cout<<"8-even so  8/2=4"<<endl;
  71.         cout<<"4-even so  4/2=2"<<endl;
  72.         cout<<"2-even so  2/2=1"<<endl<<endl;
  73.         cout<<"the more ''steps'' until it reach 1 the bigger score you'll have"<<endl<<endl<<endl;
  74.         cout << "Press 1 for player Vs Pc mode, press 2 for two players mode, press 3 to learn how does Collatz Conjecture work:"<<endl;
  75.         cin >>m;
  76.     }
  77.  
  78.  
  79.     if (m==1){
  80.  
  81.           //  for(E; E<2; E)
  82.           //  {
  83.  
  84.                 w1=0;
  85.                 w2=0;
  86.  
  87.  
  88.  
  89.     cout << "Enter any integer between 0 and 18*10^18 (18 and 18 zeros) "<<endl;
  90.     cin >> n;
  91.  
  92.  
  93.     while (n > 1)
  94.     {
  95.  
  96.     if ( n%2 == 0)
  97. {
  98.  
  99.  
  100.         n=n/2;
  101.         cout << n << endl;
  102.         w1=w1+1;
  103.  
  104.         Sleep(20);
  105.     }
  106.     else {
  107.         n=3*n+1;
  108.         cout << n << endl;
  109.         w1=w1+1;
  110.         Sleep(20);
  111.         }
  112.         }
  113.  
  114.  
  115.  
  116.             cout << "You scored ";
  117.             cout << w1;
  118.             cout << " points!"<<endl;
  119.  
  120.  
  121.  
  122.         cout << "Pc is picking integer..."<< endl;
  123.         Sleep(3000);
  124.         srand(time(NULL));
  125.         pot =rand()%4+1;
  126.         u=rand()%30+1;
  127.         q=pow(u, pot);
  128.  
  129.         R=((rand()%100+1)*q*(rand()%50+1));
  130.         cout << "He picked:"<< endl;
  131.         cout << R << endl;
  132.         Sleep(3000);
  133.         while (R > 1)
  134.     {
  135.     if ( R%2 == 0) {
  136.         R=R/2;
  137.         cout << R << endl;
  138.         w2=w2+1;
  139.         Sleep(20);
  140.  
  141.     }
  142.     else {
  143.         R=3*R+1;
  144.         cout << R << endl;
  145.           w2=w2+1;
  146.           Sleep(20);
  147.         }
  148.         }
  149.  
  150.  
  151.             cout << "Computer scored " ;
  152.             cout << w2;
  153.             cout <<" points!"<<endl;
  154.  
  155.  
  156.  
  157.         if(w1<w2)
  158.         {
  159.             cout << "YOU LOST..."<<endl<<endl;
  160.             loosemusic();
  161.  
  162.         }
  163.         else
  164.         {
  165.             cout << "YOU WIN!!! :D"<<endl<<endl;
  166.             winmusic();
  167.         }
  168.  
  169.         cout<<"Press 1 to play again, press 2 to exit:"<<endl;
  170.  
  171.         cin>> E;
  172.          //   }
  173.  
  174. }
  175.  
  176.  
  177. if (m==2)
  178. {
  179.  
  180.      cout<< "Enter maximum number of rounds you want to play:"<< endl;
  181.      cin>>rounds;
  182.      cout << "Enter your name Player 1:" << endl;
  183.      cin>> name1;
  184.      cout << "Enter your name Player 2:" << endl;
  185.      cin>> name2;
  186.     for(int dumb=0; dumb<1; dumb)
  187.         {
  188.      cout <<"Enter maximum numbers of digits for your numbers (cannot be bigger than 18)"<<endl;
  189.      cin>>maxlength;
  190.  
  191.     if(maxlength<19 && maxlength>0)
  192.        dumb++;
  193.        else
  194.         cout<<"Learn to read, it's useful ability ;)"<<endl;
  195.         }
  196.  
  197.     cout << "LETS GET READY TO RUMBLE!!" << endl<<endl;
  198.     l=1;
  199.     wo1=0;
  200.     wo2=0;
  201.     Sleep(3000);
  202.  
  203.  
  204.  
  205. for(l; l<=rounds+1; l){
  206.  
  207.         if(wo1<=rounds/2 && wo2<=rounds/2)
  208.         {
  209.  
  210.         w1=0;
  211.         w2=0;
  212.  
  213. for (int dumb=0; dumb<1; dumb){
  214.         cout << "Enter any integer with max. ";
  215.         cout<< maxlength;
  216.         cout << " digits ";
  217.         cout << name1;
  218.         cout<< ":"<<endl;
  219.         cin >> n1;
  220.         n=n1;
  221.  
  222.     length = 1;
  223.     while ( n1 /= 10 )
  224.     length++;
  225.  
  226.     if(length<=maxlength)
  227.     {
  228.        dumb++;
  229.     }
  230.     else
  231.     {
  232.  
  233.  
  234.     cout<<"Try to read... It won't hurt you ;)"<<endl<<endl;
  235.     Sleep(1000);
  236.     }
  237.  
  238. }
  239.  
  240.     while (n > 1)
  241.     {
  242.     if ( n%2 == 0)
  243.         {
  244.         n=n/2;
  245.         cout << n << endl;
  246.         w1=w1+1;
  247.         Sleep(20);
  248.     }
  249.     else {
  250.         n=3*n+1;
  251.         cout << n << endl;
  252.         w1=w1+1;
  253.         Sleep(20);
  254.         }
  255.         }
  256.  
  257.  
  258.             cout << name1;
  259.             cout << " Scored ";
  260.             cout << w1;
  261.             cout << " points!"<<endl<<endl;
  262.  
  263.  
  264.  
  265.  
  266.         for (int dumb=0; dumb<1; dumb){
  267.         cout << "Enter any integer with max. ";
  268.         cout<< maxlength;
  269.         cout << " digits ";
  270.         cout << name2;
  271.         cout<< ":"<<endl;
  272.         cin >> n1;
  273.         n2=n1;
  274.  
  275.     length = 1;
  276.     while ( n1 /= 10 )
  277.     length++;
  278.  
  279.     if(length<=maxlength)
  280.     {
  281.        dumb++;
  282.     }
  283.     else
  284.     {
  285.  
  286.  
  287.     cout<<"Try to read... It won't hurt you ;)"<<endl<<endl;
  288.     Sleep(1000);
  289.     }
  290.  
  291. }
  292.  
  293.  
  294.     while (n2 > 1)
  295.     {
  296.     if ( n2%2 == 0)
  297.         {
  298.         n2=n2/2;
  299.         cout << n2 << endl;
  300.         w2=w2+1;
  301.         Sleep(20);
  302.     }
  303.     else {
  304.         n2=3*n2+1;
  305.         cout << n2 << endl;
  306.         w2=w2+1;
  307.         Sleep(20);
  308.         }
  309.         }
  310.  
  311.  
  312.  
  313.             cout << name2;
  314.             cout << " Scored ";
  315.             cout << w2;
  316.             cout << " points!"<<endl<<endl;
  317.  
  318.         Sleep (2000);
  319.  
  320.         if(w1!=w2)
  321.         {
  322.  
  323.  
  324.  
  325.         if(w1>w2)
  326.         {
  327.             cout<<name1;
  328.             wo1++;
  329.         }
  330.  
  331.         else
  332.         {
  333.             cout<<name2;
  334.             wo2++;
  335.         }
  336.  
  337.             cout<<" is the winner of the ";
  338.             cout<<l;
  339.             if(l==1)
  340.                 cout<< "st ";
  341.  
  342.             if(l==2)
  343.                 cout<< "nd ";
  344.  
  345.             if (l==3)
  346.                 cout<< "rd ";
  347.  
  348.             if (l>3)
  349.                 cout<< "th ";
  350.  
  351.             cout<<"round!"<<endl<<endl;
  352.  
  353.             l++;
  354.  
  355.  
  356.  
  357.         }
  358.  
  359.         else
  360.         {
  361.             cout<<"It's a draw!"<<endl;
  362.         }
  363.  
  364.         Sleep(1000);
  365.  
  366.             cout<<name1;
  367.             cout<<"'s score: ";
  368.             cout<<wo1<<endl<<endl;
  369.  
  370.             cout<<name2;
  371.             cout<<"'s score: ";
  372.             cout<<wo2<<endl<<endl;
  373.  
  374.         }
  375.  
  376.         else
  377.         {
  378.             if(wo1>wo2)
  379.             {
  380.                 cout<<name1;
  381.                 cout<< " IS THE WINNER OF THE GAME!!"<<endl<<endl;
  382.                  winmusic();
  383.             }
  384.             else
  385.             {
  386.                 cout<<name2;
  387.                 cout<< " IS THE WINNER OF THE GAME!!"<<endl<<endl;
  388.                  winmusic();
  389.             }
  390.  
  391.  
  392.              cout<<"Do you want to play again? Press 1 if you want to play, press 2 if you want to exit:"<<endl<<endl;
  393.              cin>>E;
  394.              l++;
  395.  
  396.            /*
  397.             cout<< name1;
  398.             cout<<" ";
  399.             cout<<wo1;
  400.             cout<<":";
  401.             cout<<wo2;
  402.             cout<<" ";
  403.             cout<< name2 <<endl;
  404.             */
  405.  
  406.  
  407.         }
  408.         if(wo1*2==rounds && wo2*2==rounds )
  409.         {
  410.  
  411.  
  412.         cout<<"You've reached the limit of rounds... It' s a DRAW!!"<<endl;
  413.         cout<<"Do you want to play again? Press 1 if you want to play, press 2 if you want to exit:"<<endl<<endl;
  414.         cin>>E;
  415.         l++;
  416.         }
  417.   }
  418. }
  419.    }
  420.  
  421. cout<<"Dziaba"<<endl<<endl;
  422. Sleep(500);
  423.  
  424. cout<<"Dziaba"<<endl<<endl;
  425. Sleep(500);
  426.  
  427. cout<<"Dziaba"<<endl<<endl;
  428. Sleep(500);
  429.  
  430.  
  431. if(E==1){
  432. getch();
  433. }
  434.     return 0;
  435. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement