Advertisement
heroys6

Fax Lab 5.1 Crossword

Nov 3rd, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.99 KB | None | 0 0
  1. // Windows only
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <Windows.h>
  5.  
  6. #define FILLER  (char)176// (char)176 (char)15 (char)253
  7.  
  8. using namespace std;
  9.  
  10. int srcTable[9][10] = {
  11.     1, 4, -1, -1, 0, 0, 0, 0, 0, 0,
  12.     0, -1, 0, 0, 0, 0, 0, 0, 0, 0,
  13.     0, 2, -1, 5, -1, -1, -1, 0, 0, 0,
  14.     0, -1, 0, -1, 0, 0, 0, 0, 0, 0,
  15.     0, -1, 0, 3, -1, -1, -1, 6, -1, -1,
  16.     0, 0, 0, -1, 0, 0, 0, -1, 0, 0,
  17.     0, 0, 0, -1, 0, 0, 0, -1, 0, 0,
  18.     0, 0, 0, 0, 0, 0, 0, -1, 0, 0,
  19.     0, 0, 0, 0, 0, 0, 0, -1, 0, 0
  20. };
  21.  
  22. char isAnswered[9][10];
  23.  
  24. char *Quest[] = {
  25.     "Questions horizontally:                          ",
  26.     " 1) **** can be storaged in strings              ",
  27.     " 2) R****e the string                            ",
  28.     " 3) ******* can point to smth                    ",
  29.     "                                                 ",
  30.     "Questions vertically:                            ",
  31.     " 4) A**** of symbols                             ",
  32.     " 5) String is s**** class in C++                 ",
  33.     " 6) T**** of strings                             "
  34. };
  35.  
  36. char *Answ[] = {
  37.     "data",
  38.     "resize",
  39.     "pointer",
  40.     "array",
  41.     "super",
  42.     "table"
  43. };
  44.  
  45. void drawCros();
  46.  
  47. int main()
  48. {
  49.     char temp[80] = { 0 };
  50.     int numQ = 0, rightAns = 0;
  51.  
  52.     const DWORD dwSize = 128;
  53.     TCHAR buffer[dwSize];
  54.     GetConsoleTitle(buffer, dwSize);
  55.     HWND hwnd = FindWindow(NULL, buffer); // Узнаем hwnd окна
  56.     MoveWindow(hwnd, 0, 0, 700, 550, true);
  57.  
  58.     for (int i = 0; i < 9; i++) // initialization of array
  59.     for (int j = 0; j < 10; j++)
  60.         isAnswered[i][j] = '0';
  61.  
  62.     do {
  63.         drawCros();
  64.  
  65.         do {
  66.             cin.clear();
  67.             fflush(stdin);
  68.             cout << "\n> Enter the number of a question or\n       '-h' for help, '-x' for exit: ";
  69.             cin.get(temp, 80);
  70.             if (!(atoi(temp) > 0 && atoi(temp) <= 6) && strcmp(temp, "-h") && strcmp(temp, "-x"))
  71.                 cout << "\n> Allowed only digits(1 - 6), '-h' or '-x' . . .\n";
  72.         } while (!(atoi(temp) > 0 && atoi(temp) <= 6) && strcmp(temp, "-h") && strcmp(temp, "-x"));
  73.        
  74.         if (!strcmp(temp, "-x")) {
  75.             cout << "\n\t\t\tLittle shame =/\n\t\t\tGood bye!\n\n\t\t";
  76.             system("pause");
  77.             exit(0);
  78.         }
  79.         else if (!strcmp(temp, "-h")) {
  80.             cout << "\nDictionary: \n\n ~ ";
  81.             for (int i = 5; i >= 0; i--)
  82.                 cout << Answ[i] << " ~ ";
  83.             cout << "\n\n";
  84.             system("pause");
  85.         }
  86.         else {
  87.             numQ = atoi(temp);
  88.  
  89.             cout << "\n> Now enter the word-answer: ";
  90.             cin.clear();
  91.             fflush(stdin);
  92.             cin.get(temp, 80);
  93.  
  94.             for (int i = 0; temp[i]; i++)
  95.                 temp[i] = tolower(temp[i]);
  96.  
  97.             if (!(strcmp(Answ[numQ - 1], temp))) {
  98.                 cout << "\n> You are right!\n\n";
  99.                 system("pause");
  100.                 switch (numQ) {
  101.                 case 1:
  102.                     isAnswered[0][0] = 'D';
  103.                     isAnswered[0][1] = 'A';
  104.                     isAnswered[0][2] = 't';
  105.                     isAnswered[0][3] = 'a';
  106.                     break;
  107.                 case 2:
  108.                     isAnswered[2][1] = 'R';
  109.                     isAnswered[2][2] = 'e';
  110.                     isAnswered[2][3] = 'S';
  111.                     isAnswered[2][4] = 'i';
  112.                     isAnswered[2][5] = 'z';
  113.                     isAnswered[2][6] = 'e';
  114.                     break;
  115.                 case 3:
  116.                     isAnswered[4][3] = 'P';
  117.                     isAnswered[4][4] = 'o';
  118.                     isAnswered[4][5] = 'i';
  119.                     isAnswered[4][6] = 'n';
  120.                     isAnswered[4][7] = 'T';
  121.                     isAnswered[4][8] = 'e';
  122.                     isAnswered[4][9] = 'r';
  123.                     break;
  124.                 case 4:
  125.                     isAnswered[0][1] = 'A';
  126.                     isAnswered[1][1] = 'r';
  127.                     isAnswered[2][1] = 'R';
  128.                     isAnswered[3][1] = 'a';
  129.                     isAnswered[4][1] = 'y';
  130.                     break;
  131.                 case 5:
  132.                     isAnswered[2][3] = 'S';
  133.                     isAnswered[3][3] = 'u';
  134.                     isAnswered[4][3] = 'P';
  135.                     isAnswered[5][3] = 'e';
  136.                     isAnswered[6][3] = 'r';
  137.                     break;
  138.                 case 6:
  139.                     isAnswered[4][7] = 'T';
  140.                     isAnswered[5][7] = 'a';
  141.                     isAnswered[6][7] = 'b';
  142.                     isAnswered[7][7] = 'l';
  143.                     isAnswered[8][7] = 'e';
  144.                     break;
  145.                 }
  146.                 rightAns++;
  147.             }
  148.             else {
  149.                 cout << "\n> You are wrong!\n\n";
  150.                 system("pause");
  151.             }
  152.         }
  153.     } while (rightAns < 6);
  154.  
  155.     drawCros();
  156.  
  157.     cout << "\n\n\n\t\t\tCongratulation! You're won!\n\n\n";
  158.  
  159.     cout << "\n";
  160.     system("pause");
  161.     return 0;
  162. }
  163.  
  164. void drawCros()
  165. {
  166.     system("cls");
  167.  
  168.     cout << "\t\t\t\t~Crossword~\n\n";
  169.  
  170.     for (int i = 0; i < 9; i++) {
  171.         // Top border
  172.         cout << "                                                 ";
  173.         for (int j = 0; j < 10; j++) {
  174.             if (srcTable[i][j])
  175.                 cout << (char)218 << (char)196 << (char)191;
  176.             else
  177.                 cout << "   ";
  178.         }
  179.         cout << "\n";
  180.  
  181.         // Middle
  182.         cout << Quest[i];
  183.         for (int j = 0; j < 10; j++) {
  184.             if (srcTable[i][j]) {
  185.                 if (isAnswered[i][j] != '0')
  186.                     cout << (char)179 << isAnswered[i][j] << (char)179;
  187.                 else {
  188.                     if (srcTable[i][j] < 0)  // draw void cell
  189.                         cout << (char)179 << FILLER << (char)179;
  190.                     else                     // draw number of question
  191.                         cout << (char)179 << srcTable[i][j] << (char)179;
  192.                 }
  193.             }
  194.             else
  195.                 cout << "   ";
  196.         }
  197.         cout << "\n";
  198.  
  199.         // Bottom border
  200.         cout << "                                                 ";
  201.         for (int j = 0; j < 10; j++) {
  202.             if (srcTable[i][j])
  203.                 cout << (char)192 << (char)196 << (char)217;
  204.             else
  205.                 cout << "   ";
  206.         }
  207.         cout << "\n";
  208.     }
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement