/*-----------------------------------------------------------------*/ /* 25.08.94 */ /* Это программное обеспечение может свободно передаваться любым */ /* лицам и организациям в виде как исходных текстов программ, так */ /* и в виде исполняемых файлов без каких-либо ограничений. */ /* Авторские права: */ /* Текст сюжета - Гарри Гаррисон */ /* Программа-интерпретатор - */ /* Александр Тютюнников (shurick@medlux.msk.su) */ /* Олег Ховайко (olegh@medlux.msk.su) */ /*-----------------------------------------------------------------*/ #include #include "bearat.h" #define N_LINES 22 static long lPos[Chapters + 1]; FILE *fText; NO_CML int rnd() { static long lTime; $gtim(&lTime); return (int)lTime & 1; } void Init() { FILE *fPos; if (!(fPos = fopen(IndexFileName,"rb"))) { printf("?Rat-F-Cannnot open file '%s'\n",IndexFileName); exit(1); } if (!fread(lPos, Chapters + 1, sizeof(long), fPos)) { printf("?Rat-F-Input error '%s'\n",IndexFileName); fclose(fPos); exit(1); } fclose(fPos); } void WaitLF() { while (getchar() != '\n'); } int Dosp(YesOrNo) int YesOrNo; { register int i; static char *cSide[] = {"Орел", "Решка"}; if (YesOrNo) { printf("\nНу чего ты ждешь? Подбрасывай ДОСП!"); WaitLF(); printf("Ага, процесс идет...\n"); sleep(2); printf("\007ДОСП: %s\n", cSide[i = rnd() & 01]); return i; } else { printf("\nЖребий брошен, нажми Enter..."); WaitLF(); return rnd() & 01; } } int Querry(iType, iNumber) int iType, iNumber; { char c; if (iNumber == 1) { printf("\nБыстрее нажимай "); WaitLF(); printf("\n"); return 0; } switch (iType) { case '%': printf("\n"); do { printf("Введи свой выбор [A%c%c]: ", (iNumber > 2)? '-' : ',', iNumber + 'A' - 1); scanf("%c", &c); WaitLF(); if ((c == 'Q')||(c == 'q')) return 6; c = (c & 0337) - 'A'; } while ((c >= iNumber) || (c < 0)); return c; case '$': return Dosp(0); case '&': return Dosp(1); default: printf("Error Querry %c\n", iType); } return 0; } int WriteItem(iPos) int iPos; { register c, iLines, i; static int iType, iNext[7] = {0, 0, 0 ,0 ,0 ,0, 0}; static int iOldPos = 0; int iNum; for (i = 36; i--; putchar('-')); printf("<%4d >", iPos); for (i = 36; i--; putchar('-')); printf("\n"); for (iLines = i = 0; (c = fgetc(fText)) != EOF; ) { switch (c) { case '\n': putchar(c); if (++iLines >= N_LINES) { printf(" Нажмите Enter...\r"); WaitLF(); iLines = 0; } break; case '%': case '$': case '&': iType = c; do { for (iNum = 0; ((c = fgetc(fText)) >= '0') && (c <= '9'); iNum = iNum * 10 + (int)c - '0') ; iNext[i++] = iNum; } while ((c == '%') || (c == '$') || (c == '&')); iOldPos = iPos; return (iNext[Querry(iType, i)]); case '<': i = iOldPos; iOldPos = iPos; return i; default: putchar(c); break; } } } void main() { static int iNextItem; char c; Init(); if (!(fText = fopen(DataFileName, "rb"))) { printf("?Rat-F-Cannot open text file '%s'\n",DataFileName); exit(1); } for ( ; (c = fgetc(fText)) != '#'; putchar(c)) ; WaitLF(); do { printf("С какого пункта начинаем играть? [0-%d]. 0 - Сначала. > ", Chapters); scanf("%d", &iNextItem); WaitLF(); } while ((iNextItem < 0) || (iNextItem > Chapters)); do { fseek(fText, lPos[iNextItem], SEEK_SET); iNextItem = WriteItem(iNextItem); } while (iNextItem); fclose(fText); }