Advertisement
chrlwrd

Programming Challenge 3 (Weekend)

Feb 26th, 2012
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <Windows.h>
  4. using namespace std;
  5.  
  6. void animateFlomb(string , int );
  7. string flipHorizontal(string );
  8. string flipVertical(string );
  9. void dance(string , int );
  10. void rave(string , int );
  11.  
  12. string defaultFlomb = "\\(O__O\\)", flomb;
  13.  
  14. int main()
  15. {
  16.     string option = "";
  17.  
  18.     while(option != "exit")
  19.     {
  20.         cout << "Please choose a function to test..." << endl
  21.             << "\t[1] animateFlomb (flipVertical)" << endl
  22.             << "\t[2] dance (flipVertical and flipHorizontal)" << endl
  23.             << "\t[3] rave ;)" << endl << endl << "> ";
  24.  
  25.         cin >> option;
  26.  
  27.         if(option == "1") // animateFlomb
  28.         {
  29.             animateFlomb(defaultFlomb, 5);
  30.         }
  31.         else if(option == "2") // dance
  32.         {
  33.             dance(defaultFlomb, 5);
  34.         }
  35.         else if(option == "3")
  36.         {
  37.             rave(defaultFlomb, 15);
  38.         }
  39.         else if(option != "exit")
  40.         {
  41.             cout << endl << "Please try again." << endl << endl;
  42.         }
  43.     }
  44.  
  45.     return 0;
  46. }
  47.  
  48. void animateFlomb(string input, int count)
  49. {
  50.     system("color 0c");
  51.     flomb = defaultFlomb;
  52.     system("cls");
  53.  
  54.     for(int i = 0; i < count; i++)
  55.     {
  56.         cout << endl << endl << endl << "\t\t" << flipVertical(flomb);
  57.         Sleep(500);
  58.         system("cls");
  59.     }
  60.  
  61.     system("color 07");
  62. }
  63.  
  64. string flipHorizontal(string input)
  65. {
  66.     int size = input.length();
  67.     flomb = string(input.rbegin(), input.rend());
  68.  
  69.     for(int i = 0; i < size; i++)
  70.     {
  71.         switch(flomb[i])
  72.         {
  73.         case '\\':
  74.             flomb.replace(i, 1, 1, '/');
  75.             break;
  76.         case '/':
  77.             flomb.replace(i, 1, 1, '\\');
  78.             break;
  79.         case '(':
  80.             flomb.replace(i, 1, 1, ')');
  81.             break;
  82.         case ')':
  83.             flomb.replace(i, 1, 1, '(');
  84.             break;
  85.         default:
  86.             break;
  87.         }
  88.     }
  89.  
  90.     return flomb;
  91. }
  92.  
  93. string flipVertical(string input)
  94. {
  95.     int size = input.length();
  96.     flomb.clear();
  97.    
  98.     for(int i = 0; i < size; i++)
  99.     {
  100.         switch(input[i])
  101.         {
  102.         case '\\':
  103.             flomb.replace(i, 1, 1, '/');
  104.             break;
  105.         case '/':
  106.             flomb.replace(i, 1, 1, '\\');
  107.             break;
  108.         default:
  109.             flomb.replace(i, 1, input, i, 1);
  110.             break;
  111.         }
  112.     }
  113.  
  114.     return flomb;
  115. }
  116.  
  117. void dance(string input, int count)
  118. {
  119.     system("color 0c");
  120.     flomb = defaultFlomb;
  121.     system("cls");
  122.  
  123.     for(int i = 0; i < count; i++)
  124.     {
  125.         for(int j = 0; j < 2; j++)
  126.         {
  127.             cout << endl << endl << endl << "\t\t" << flipVertical(flomb);
  128.             Sleep(500);
  129.             system("cls");
  130.         }
  131.  
  132.         cout << endl << endl << endl << "\t\t" << flipHorizontal(flomb);
  133.         Sleep(500);
  134.         system("cls");
  135.     }
  136.  
  137.     system("color 07");
  138. }
  139.  
  140. void rave(string input, int count)
  141. {
  142.     system("color 0c");
  143.     flomb = defaultFlomb;
  144.     system("cls");
  145.  
  146.     for(int i = 0; i < count; i++)
  147.     {
  148.         switch(i)
  149.         {
  150.         case 1: case 6: case 11:
  151.             system("color 7d");
  152.             break;
  153.         case 2: case 7: case 12:
  154.             system("color 5a");
  155.             break;
  156.         case 3: case 8: case 13:
  157.             system("color 3f");
  158.             break;
  159.         case 4: case 9: case 14:
  160.             system("color 6d");
  161.             break;
  162.         case 5: case 10: case 15:
  163.             system("color 49");
  164.             break;
  165.         }
  166.  
  167.         for(int j = 0; j < 2; j++)
  168.         {
  169.             cout << endl << endl << endl << "\t\t" << flipVertical(flomb);
  170.             Sleep(50);
  171.             system("cls");
  172.         }
  173.  
  174.         cout << endl << endl << endl << "\t\t" << flipHorizontal(flomb);
  175.         Sleep(50);
  176.         system("cls");
  177.     }
  178.  
  179.     system("color 07");
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement