Mrowqa

Simple Console Tool

Jul 20th, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.98 KB | None | 0 0
  1. /**
  2.  * Simple Console Tool by
  3.  * @author Artur "Mrowqa" Jamro
  4.  */
  5.  
  6. #include <iostream>
  7. #include <conio.h>
  8. #include <ctime>
  9. #include <string>
  10. #include "C:\Users\R620\Desktop\Biblioteki\ddt-console\ddtconsole.h"
  11. using namespace std;
  12. using namespace ddt::console;
  13. void zwloka( int sekund )
  14. {
  15.     time_t poczatkowy_czas = time( NULL );
  16.     while( time( NULL ) - poczatkowy_czas < sekund );
  17.     return;
  18. }
  19. void kodZnaku( void )
  20. {
  21.     clrscr();
  22.     unsigned char znak;
  23.     cout << "[ESC] Wyjscie do menu\nPodaj znak" << endl;
  24.     do
  25.     {
  26.         znak = getch();
  27.         cout << "znak: '" << znak << "' kod: " << static_cast < int >( znak ) << endl;
  28.         while( kbhit() )
  29.         {
  30.             znak = getch();
  31.             cout << "*znak: '" << znak << "' kod: " << static_cast < int >( znak ) << endl;
  32.         }
  33.         cout << endl;
  34.     } while( znak != 27 ); //ESC
  35.    
  36.     return;
  37. }
  38. void kolor( void )
  39. {
  40.     SetCursor( true );
  41.     clrscr();
  42.     int kolor [2];
  43.     cout << "[16] Wyjscie do menu" << endl;
  44.     do
  45.     {
  46.         cout << "\nPodaj nr koloru textu i tla (oddziel spacja): ";
  47.         cin >> kolor[ 0 ] >> kolor[ 1 ];
  48.         if( cin.fail() )
  49.         {
  50.             cin.clear();
  51.             cin.sync();
  52.             return;
  53.         }
  54.         textcolor( kolor[ 0 ] );
  55.         textbackground( kolor[ 1 ] );
  56.  
  57.         cout << "             ..               \n"
  58.                 "         Text  test           \n"
  59.                 "   *  * ***  --  *** *  *     \n"
  60.                 "         Text  test           \n"
  61.                 "             ..               \n\n";
  62.  
  63.         textcolor( 7 );
  64.         textbackground( 0 );
  65.  
  66.     } while( kolor[ 0 ] != 16 );
  67.     return;
  68. }
  69. void pokazKolor( void )
  70. {
  71.     clrscr();
  72.     cout << endl << "0. - czarny";
  73.     for(int i = 0; i < 16; i++)
  74.     {
  75.         textcolor( i );
  76.         textbackground( 0 );
  77.         cout << endl << i << ".\t\t Text test \t\t";
  78.         textbackground ( i );
  79.         cout << "               ";
  80.  
  81.     }
  82.     textcolor( 7 );
  83.     textbackground( 0 );
  84.     cout << endl << endl << endl ;
  85.     system("pause");
  86.     return;
  87. }
  88. void okienko( void )
  89. {
  90.     SetCursor( true );
  91.     clrscr();
  92.     int minX,
  93.         maxX,
  94.         minY,
  95.         maxY,
  96.         textCol,
  97.         backGrCol,
  98.         act;
  99.     cout << "minX = ";
  100.     cin >> minX;
  101.     cout << "maxX = ";
  102.     cin >> maxX;
  103.     cout << "minY = ";
  104.     cin >> minY;
  105.     cout << "maxY = ";
  106.     cin >> maxY;
  107.     cout << "kolor textu: ";
  108.     cin >> textCol;
  109.     cout << "kolor tla: ";
  110.     cin >> backGrCol;
  111.     cout << "[ESC] Wyjscie";
  112.     if( cin.fail() )
  113.     {
  114.         cin.clear();
  115.         cin.sync();
  116.         return;
  117.     }
  118.     if( minX < 1 || minX > 80 || minY < 1 || minY > 80 )
  119.     {
  120.         return;
  121.     }
  122.     if( minX >= maxX  )
  123.     {
  124.         int a = minX;
  125.         minX = maxX;
  126.         maxX = a;
  127.     }
  128.     if( minY >= maxY )
  129.     {
  130.         int a = minY;
  131.         minY = maxY;
  132.         maxY = a;
  133.     }
  134.  
  135.     textbackground( backGrCol );
  136.     textcolor( textCol );
  137.     act = minX + 1;
  138.     for( int o = 0; o < maxY - minY + 1; o++)
  139.     {
  140.         gotoxy( minX, minY + o );
  141.         for( int i = 0; i < maxX - minX + 1; i++ ) cout << " ";
  142.     }
  143.     char znak;
  144.     for( int i = 0; i < maxY - minY - 1; i++ )
  145.     {
  146.         gotoxy( minX + 1, minY + i + 1 );
  147.         //act = minX + 1;
  148.         //cout << "1";
  149.         for( int ii = 0; ii < maxX - minX - 1; ii++ )
  150.         {
  151.             znak = getch();
  152.             //cout << (int(znak));
  153.             //cout << ii;
  154.             if( znak == 27 ) // ESC
  155.                 goto koniec;
  156.             if( znak == 13 ) // Enter
  157.                 break;
  158.             if( znak == 8 ) // backspace
  159.             {
  160.                 //cout << "" << ii; getch();
  161.                 if( ii + minX  ==  minX )
  162.                 {
  163.                     //gotoxy( minX + 2, minY + i + 1 );
  164.                     cout << " ";
  165.                     //cout << ii+minX << " "<< minX + 1; getch();
  166.                     //act = minX + 1;
  167.                     ii = 1;
  168.                     if( i != 0 )
  169.                     {
  170.                         i--;
  171.                         gotoxy( maxX, minY + i + 1);
  172.                         ii = maxX - minX - 1;
  173.                         cout << znak << " ";
  174.                     }
  175.                 }
  176.                 else
  177.                     cout << znak << " ";
  178.                 ii = ii - 2;
  179.                 //act--;
  180.             }
  181.             if( znak == -32 ) // strzalki
  182.             {
  183.                 znak = getch();
  184.                 if( znak == 75 ) // strzalka w lewo
  185.                 {
  186.                     if( minX + 1 < wherex() )
  187.                     {
  188.                         gotoxy( wherex() - 1, wherey() );
  189.                         ii -= 2;
  190.                     }
  191.                     else ii--;
  192.                 }
  193.                 if( znak == 77 ) // strzalka w prawo
  194.                 {
  195.                     if( maxX - 1 > wherex() )
  196.                     {
  197.                         gotoxy( wherex() + 1, wherey() );
  198.                     }
  199.                     else ii++;
  200.                 }
  201.                 if( znak == 72 ) // strzalka w gore
  202.                 {
  203.                     if( minY + 1 < wherey() )
  204.                     {
  205.                         gotoxy( wherex(), wherey() - 1 );
  206.                         i -= 1;
  207.                     }
  208.                     else if( ii == maxX - minX - 2 ) i--;
  209.                 }
  210.                 if( znak == 80 ) // strzalka w dol
  211.                 {
  212.                     if( maxY - 1 > wherey() )
  213.                     {
  214.                         gotoxy( wherex(), wherey() + 1 );
  215.                         i += 1;
  216.                     }
  217.                     else if( ii == maxX - minX - 2 ) i++;
  218.                 }
  219.                 znak = 0;
  220.             }
  221.             /*if( act == maxX )
  222.                     break;*/
  223.             else
  224.             cout << znak;
  225.             //act++;
  226.         }
  227.     }
  228. koniec:
  229.     gotoxy( 1, 25 );
  230.     textcolor( 7 );
  231.     textbackground( 0 );
  232.     cout << "Juz !";
  233.     getch();
  234.     return;
  235. }
  236. int main()
  237. {
  238.     title("2ls 4u by Mrowqa");
  239.     bool koniec = false;
  240.     unsigned char znak;
  241.     while( koniec != true )
  242.     {
  243.         SetCursor( false );
  244.         clrscr();
  245.         textcolor( 7 );
  246.         textbackground( 0 );
  247.         cout << "[1] Kod znaku \n"
  248.                 "[2] Kolor czcionki i tla\n"
  249.                 "[3] Pokaz kolory\n"
  250.                 "[4] Kolorowe okienko\n"
  251.                 "[5] Wyjscie";
  252.         znak = getch();
  253.         switch( znak )
  254.         {
  255.             case '1':
  256.                 kodZnaku();
  257.                 break;
  258.             case '2':
  259.                 kolor();
  260.                 break;
  261.             case '3':
  262.                 pokazKolor();
  263.                 break;
  264.             case '4':
  265.                 okienko();
  266.                 break;
  267.             case '5':
  268.                 koniec = true;
  269.                 break;
  270.             case 27:
  271.                 koniec = true;
  272.                 break;
  273.         }
  274.        
  275.     }
  276.  
  277.     SetCursor( false );
  278.     clrscr();
  279.    string credits = "                             Credits i nie tylko ;D                             " // 1.
  280.                     "                                                                                " // 2.
  281.                     "                                                                                " // 3.
  282.                     "                        Program powstal, poniewaz czasem                        " // 4.
  283.                     "                     potrzebowalem kodu jakiegos znaku albo                     " // 5.
  284.                     "                        numeru koloru. Pomyslalem troche                        " // 6.
  285.                     "                   i stwierdzilem, ze taki program sie przyda                   " // 7.
  286.                     "                nie tylko mnie, ale i takze innym programistom :D               " // 8.
  287.                     "                    Komentarze mile widziane na moim chomiku:                   " // 9.
  288.                     "                                chomikuj.pl/iant                                " // 10.
  289.                     "                      Znajdziesz tam takze wiecej programow.                    " // 11.
  290.                     "           Program moze byc rozpowszechniany tylko w calosci (paczka)           " // 12.
  291.                     "           Program jest bezplatny i zostal pobrany z chomikuj.pl/iant           " // 13.
  292.                     "                                                                                " // 14.
  293.                     "                                                            Artur J             " // 15.
  294.                     "                                                                                " // 16.
  295.                     "                                                                                " // 17.
  296.                     "                                                                                " // 18.
  297.                     "                                                                                " // 19.
  298.                     "                                                                                " // 20.
  299.                     "                                                                                " // 21.
  300.                     "                                                                                " // 22.
  301.                     "                                                                                " // 23.
  302.                     "                                                                                " // 24.
  303.                     "                                                                      by Mrowqa";// 25.
  304.    int col, tlo;
  305.    for( int i = 0; i < 5; i++ )
  306.    {
  307.        srand( time( NULL ) );
  308.        col = rand() % 16;
  309.        tlo = rand() % 16;
  310.        while( tlo == col )
  311.          tlo = rand();
  312.        textcolor( col );
  313.        textbackground( tlo );
  314.        clrscr();
  315.        cout << credits;
  316.        zwloka( 1 );
  317.    }
  318.     getch();
  319.     gotoxy( 1, 16 );
  320.     textcolor( col + 1 != tlo ? col + 1 : col + 3 );
  321.     string by =     "      by Mrowqa                                                    by Mrowqa    " // 16.
  322.                     "                    by Mrowqa                   by Mrowqa                       " // 17.
  323.                     "                                  by Mrowqa                                     " // 18.
  324.                     "   by Mrowqa                                                by Mrowqa           " // 19.
  325.                     "                     by Mrowqa                                                  " // 20.
  326.                     "        by Mrowqa                             by Mrowqa                         " // 21.
  327.                     "                              by Mrowqa                            by Mrowqa    " // 22.
  328.                     "          by Mrowqa                                 by Mrowqa                   " // 23.
  329.                     "                     by Mrowqa         by Mrowqa                                " // 24.
  330.                     "  by Mrowqa                                                           by Mrowqa";// 25.
  331.     cout << by;
  332.     getch();
  333.     return( 0 );
  334. }
Advertisement
Add Comment
Please, Sign In to add comment