Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. #include "system/boolean.h"
  3. #include "system/kolibri.h"
  4. #include "system/stdlib.h"
  5. #include "system/string.h"
  6. #include "system/ctype.h"
  7.  
  8. #include "system/console.c"
  9.  
  10. #include "base.h"
  11.  
  12. #define BASE_LEN 10716
  13.  
  14. char cities_used[BASE_LEN];
  15. int user_current;
  16. char name[256];
  17. char last;
  18.  
  19. ///===========================
  20.  
  21. void kol_main();
  22.  
  23. ///===========================
  24.  
  25. int _iswhite(char c)
  26. {
  27. return ((' ' == c) || ('\t' == c) || (13 == c) || (10 == c));
  28. }
  29.  
  30. ///===========================
  31.  
  32. unsigned char _tolower(unsigned char c)
  33. {
  34. unsigned char x = 0;
  35.  
  36. if ((c == (unsigned char)'ñ')||(c == (unsigned char)'ð'))
  37.         return '¥';
  38.  
  39. if ((c > 127) && (c < 144))
  40.         x += 32;
  41.  
  42. if ((c > 143) && (c < 160))
  43.         x += 80;
  44.  
  45. return c+x;
  46. }
  47.  
  48. ///===========================
  49.  
  50. void trim(char string[])
  51. {
  52. int i, j;
  53.  
  54. for (i=0; ;i++)
  55.         if ( !_iswhite(string[i]) )
  56.                 break;
  57. j = 0;
  58. for (;;i++, j++)
  59.         {
  60.         string[j] = string[i];
  61.         if ('\0' == string[i] )
  62.                 break;
  63.         }
  64.  
  65. for (i=0; ;i++)
  66.         if ('\0' == string[i])
  67.                 break;
  68. i--;
  69. for (;i>0;--i)
  70.         if ( _iswhite(string[i]) )
  71.                 string[i] = '\0';
  72.         else
  73.                 break;
  74. }
  75.  
  76. ///===========================
  77.  
  78. void game_new()
  79. {
  80. memset(cities_used, 0, BASE_LEN);
  81. user_current = 0;
  82. last = 32;
  83. }
  84.  
  85. ///===========================
  86.  
  87. int search(char *city)
  88. {
  89. int i;
  90. for ( i = 0; i < BASE_LEN; i++ )
  91.         if ( ! strcmp(cities[i], city) )
  92.                 return i;
  93. return -1;
  94. }
  95.  
  96. ///===========================
  97.  
  98. int last_ok(char c)
  99. {
  100. if ( (c == 'ë')||(c == 'ì'))
  101.         return 0;
  102. else
  103.         return 1;
  104. }
  105.  
  106. ///===========================
  107.  
  108. void kol_main()
  109. {
  110.  
  111. CONSOLE_INIT("mCities by Albom");
  112.  
  113.  
  114. printf("%s", "\
  115. mCities - ¨£à  ¢ £®à®¤ . ‚¥àá¨ï 0.1.\n\
  116. €¢â®à: €«¥ªá ­¤à ®£®¬ § aka Albom (albom85@yandex.ru)\n\n\
  117. \
  118. “¯à ¢«¥­¨¥:\n\
  119. ª®¬ ­¤  * - ­®¢ ï ¨£à \n\
  120. ª®¬ ­¤  ! - ᯨ᮪ ­ §¢ ­­ëå £®à®¤®¢\n\n\
  121. ");
  122.  
  123. game_new();
  124. int i, s;
  125.  
  126. for (;;)
  127.         {
  128.         for (;;)
  129.                 {
  130.                 printf("ˆ£à®ª %d > ", user_current+1);
  131.                 gets(name, 32);
  132.                
  133.                 if (*name == 0)
  134.                         {
  135.                         _exit(1);
  136.                         kol_exit();
  137.                         }
  138.  
  139.                 trim(name);
  140.  
  141.                 if (!strcmp(name, "*"))
  142.                         {
  143.                         printf("\n\n");
  144.                         game_new();
  145.                         continue;
  146.                         }
  147.  
  148.                 if (!strcmp(name, "!"))
  149.                         {
  150.                         for (i = 0; i < BASE_LEN; i++)
  151.                                 if (cities_used[i] == 1)
  152.                                         printf("%s  ", cities[i]);
  153.                         printf("\n");
  154.                         continue;
  155.                         }
  156.  
  157.                 for (i = 0; i < strlen(name); i++ )
  158.                         name[i] = _tolower(name[i]);
  159.  
  160.                 if ( (last!=name[0])&&(last!=32) )
  161.                         {
  162.                         printf("ã¦­® ­ §¢ âì £®à®¤ ­  ¡ãª¢ã \'%c\'!\n", last);
  163.                         continue;
  164.                         }
  165.                 s = search(name);
  166.  
  167.                 if (cities_used[s] == 1)
  168.                         {
  169.                         printf("â®â £®à®¤ 㦥 ­ §ë¢ «áï!\n");
  170.                         continue;
  171.                         }
  172.                        
  173.  
  174.                 if ( s == -1 )
  175.                         printf("¥ §­ î â ª®£® £®à®¤ !\n");
  176.                 else
  177.                         {
  178.  
  179.                         cities_used[s] = 1;
  180.  
  181.                         if ( last_ok(name[strlen(name)-1]) )
  182.                                 last = name[strlen(name)-1];
  183.                         else
  184.                                 last = name[strlen(name)-2];
  185.                         break;
  186.                         }
  187.                 }
  188.  
  189.         if ( user_current == 0)
  190.                 user_current = 1;
  191.         else
  192.                 user_current = 0;
  193.  
  194.  
  195.         }
  196.  
  197. }
  198.  
  199. ///===========================
  200.