mirror of
https://github.com/KolibriOS/kolibrios.git
synced 2024-12-24 07:36:48 +03:00
221b16cc14
git-svn-id: svn://kolibrios.org@2655 a494cfbc-eb01-0410-851d-a64ba20cac60
200 lines
2.9 KiB
C
200 lines
2.9 KiB
C
|
||
#include "system/boolean.h"
|
||
#include "system/kolibri.h"
|
||
#include "system/stdlib.h"
|
||
#include "system/string.h"
|
||
#include "system/ctype.h"
|
||
|
||
#include "system/console.c"
|
||
|
||
#include "base.h"
|
||
|
||
#define BASE_LEN 10716
|
||
|
||
char cities_used[BASE_LEN];
|
||
int user_current;
|
||
char name[256];
|
||
char last;
|
||
|
||
///===========================
|
||
|
||
void kol_main();
|
||
|
||
///===========================
|
||
|
||
int _iswhite(char c)
|
||
{
|
||
return ((' ' == c) || ('\t' == c) || (13 == c) || (10 == c));
|
||
}
|
||
|
||
///===========================
|
||
|
||
unsigned char _tolower(unsigned char c)
|
||
{
|
||
unsigned char x = 0;
|
||
|
||
if ((c == (unsigned char)'ñ')||(c == (unsigned char)'ð'))
|
||
return '¥';
|
||
|
||
if ((c > 127) && (c < 144))
|
||
x += 32;
|
||
|
||
if ((c > 143) && (c < 160))
|
||
x += 80;
|
||
|
||
return c+x;
|
||
}
|
||
|
||
///===========================
|
||
|
||
void trim(char string[])
|
||
{
|
||
int i, j;
|
||
|
||
for (i=0; ;i++)
|
||
if ( !_iswhite(string[i]) )
|
||
break;
|
||
j = 0;
|
||
for (;;i++, j++)
|
||
{
|
||
string[j] = string[i];
|
||
if ('\0' == string[i] )
|
||
break;
|
||
}
|
||
|
||
for (i=0; ;i++)
|
||
if ('\0' == string[i])
|
||
break;
|
||
i--;
|
||
for (;i>0;--i)
|
||
if ( _iswhite(string[i]) )
|
||
string[i] = '\0';
|
||
else
|
||
break;
|
||
}
|
||
|
||
///===========================
|
||
|
||
void game_new()
|
||
{
|
||
memset(cities_used, 0, BASE_LEN);
|
||
user_current = 0;
|
||
last = 32;
|
||
}
|
||
|
||
///===========================
|
||
|
||
int search(char *city)
|
||
{
|
||
int i;
|
||
for ( i = 0; i < BASE_LEN; i++ )
|
||
if ( ! strcmp(cities[i], city) )
|
||
return i;
|
||
return -1;
|
||
}
|
||
|
||
///===========================
|
||
|
||
int last_ok(char c)
|
||
{
|
||
if ( (c == 'ë')||(c == 'ì'))
|
||
return 0;
|
||
else
|
||
return 1;
|
||
}
|
||
|
||
///===========================
|
||
|
||
void kol_main()
|
||
{
|
||
|
||
CONSOLE_INIT("mCities by Albom");
|
||
|
||
|
||
printf("%s", "\
|
||
mCities - ¨£à ¢ £®à®¤ . ‚¥àá¨ï 0.1.\n\
|
||
€¢â®à: €«¥ªá ¤à <20>®£®¬ § aka Albom (albom85@yandex.ru)\n\n\
|
||
\
|
||
“¯à ¢«¥¨¥:\n\
|
||
ª®¬ ¤ * - ®¢ ï ¨£à \n\
|
||
ª®¬ ¤ ! - ᯨ᮪ §¢ ëå £®à®¤®¢\n\n\
|
||
");
|
||
|
||
game_new();
|
||
int i, s;
|
||
|
||
for (;;)
|
||
{
|
||
for (;;)
|
||
{
|
||
printf("ˆ£à®ª %d > ", user_current+1);
|
||
gets(name, 32);
|
||
|
||
if (*name == 0)
|
||
{
|
||
_exit(1);
|
||
kol_exit();
|
||
}
|
||
|
||
trim(name);
|
||
|
||
if (!strcmp(name, "*"))
|
||
{
|
||
printf("\n\n");
|
||
game_new();
|
||
continue;
|
||
}
|
||
|
||
if (!strcmp(name, "!"))
|
||
{
|
||
for (i = 0; i < BASE_LEN; i++)
|
||
if (cities_used[i] == 1)
|
||
printf("%s ", cities[i]);
|
||
printf("\n");
|
||
continue;
|
||
}
|
||
|
||
for (i = 0; i < strlen(name); i++ )
|
||
name[i] = _tolower(name[i]);
|
||
|
||
if ( (last!=name[0])&&(last!=32) )
|
||
{
|
||
printf("<EFBFBD>㦮 §¢ âì £®à®¤ ¡ãª¢ã \'%c\'!\n", last);
|
||
continue;
|
||
}
|
||
s = search(name);
|
||
|
||
if (cities_used[s] == 1)
|
||
{
|
||
printf("<EFBFBD>â®â £®à®¤ 㦥 §ë¢ «áï!\n");
|
||
continue;
|
||
}
|
||
|
||
|
||
if ( s == -1 )
|
||
printf("<EFBFBD>¥ § î â ª®£® £®à®¤ !\n");
|
||
else
|
||
{
|
||
|
||
cities_used[s] = 1;
|
||
|
||
if ( last_ok(name[strlen(name)-1]) )
|
||
last = name[strlen(name)-1];
|
||
else
|
||
last = name[strlen(name)-2];
|
||
break;
|
||
}
|
||
}
|
||
|
||
if ( user_current == 0)
|
||
user_current = 1;
|
||
else
|
||
user_current = 0;
|
||
|
||
|
||
}
|
||
|
||
}
|
||
|
||
///===========================
|