home *** CD-ROM | disk | FTP | other *** search
/ ftp.gamers.org / ftp.gamers.org.zip / ftp.gamers.org / pub / games / uwp-uml / misc / gomoku.exe / GO-HELP.INC next >
Text File  |  1987-12-21  |  8KB  |  302 lines

  1. {                             GO-HELP.INC
  2.                               GO-MOKU 4.0
  3.             Copyright (c) 1985, 87 by Borland International, Inc.
  4.  
  5.   Note: To incorporate this system into other programs,  modify
  6.         and include this file and all statements in GO-MOKU.PAS
  7.         marked with a comment contain:  ... Help system ...
  8. }
  9.  
  10. procedure Help;
  11. const
  12.   MaxLines = 50;                 { Max # lines read into help screen }
  13.   FirstCol = 50;                            { Inside the help window }
  14.   FirstRow =  8;
  15.   LastCol  = 75;
  16.   LastRow  = 21;
  17.   HelpFileName : string[20] = 'GO-MOKU.HLP';
  18.  
  19. type
  20.   RowType     = string[25];
  21.   ScreenArray = array[1..MaxLines] of RowType;    { Stores help text }
  22.  
  23. var
  24.   HelpFile : Text;                                   { The help file }
  25.   HelpText : ScreenArray;                { Storage for the help file }
  26.   LastLineRead : integer;    { The last line read from the help file }
  27.   BorderTop, BorderBottom,           { Help screen border boundaries }
  28.   BorderLeft, BorderRight : byte;
  29.  
  30. procedure DrawBorder;
  31. { Draw a border around the help window }
  32. const
  33.   VerticalBorder = #186; HorizontalBorder = #205;
  34.   UpLeft         = #201; UpRight          = #187;
  35.   DownLeft       = #200; DownRight        = #188;
  36. var
  37.   Row, Col : integer;
  38. begin
  39.   BorderTop := 1;  BorderBottom := 16;
  40.   BorderLeft := 1; BorderRight := 29;
  41.   ClrScr;
  42.   TextColor(NormalColor - 8);
  43.   GotoXY(BorderLeft, BorderTop);
  44.   Write(UpLeft);
  45.   for Col := BorderLeft + 1 to BorderRight - 22 do
  46.     Write(HorizontalBorder);
  47.   TextColor(NormalColor);
  48.   Write(' GOMOKU HELP ');
  49.   TextColor(NormalColor - 8);
  50.   for Col := BorderLeft + 20 to BorderRight - 1 do
  51.     Write(HorizontalBorder);
  52.   Write(UpRight);
  53.   for Row := BorderTop + 1 to BorderBottom - 1 do
  54.   begin
  55.     GotoXY(BorderLeft, Row);
  56.     Write(VerticalBorder);
  57.     GotoXY(BorderRight, Row);
  58.     Write(VerticalBorder);
  59.   end;
  60.   GotoXY(BorderLeft, BorderBottom);
  61.   Write(DownLeft);
  62.   for Col := BorderLeft + 1 to BorderRight - 1 do
  63.     Write(HorizontalBorder);
  64.   Write(DownRight);
  65. end; { DrawBorder }
  66.  
  67. procedure DrawHelpLine;
  68. { Draws a help line below the help window }
  69. begin
  70.   GotoXY(BorderLeft + 1, BorderBottom + 1);
  71.   WriteHelp(#24 + #196, 1);
  72.   WriteHelp(#25 + #196 + 'Scroll   ', 1);
  73.   WriteHelp('PgUp' + #196, 4);
  74.   WriteHelp('PgDn' + #196 + 'Page', 4);
  75. end; { DrawHelpLine }
  76.  
  77. function ReadHelpFile : boolean;
  78. { Reads in the help file and returns
  79.   true if the read was successful    }
  80. var
  81.   Ch : char;
  82.  
  83. procedure LoadArray;
  84. { Stores the help file into an array }
  85. begin
  86.   GotoXY(1, 2);
  87.   ClrEOL;
  88.   WriteLn(' Reading Text . . .');
  89.   FillChar(HelpText, SizeOf(HelpText), #0); { Initialize array }
  90.   LastLineRead := 0;
  91.   while not EOF(HelpFile) and (LastLineRead < MaxLines) do
  92.   begin
  93.     LastLineRead := LastLineRead + 1;
  94.     ReadLn(HelpFile, HelpText[LastLineRead]);
  95.   end;
  96.   if not EOF(HelpFile) then
  97.   begin
  98.     WriteLn;
  99.     WriteLn;
  100.     WriteLn('Sorry, this program only');
  101.     WriteLn('reads ', MaxLines, ' lines of text.');
  102.   end;
  103. end; { LoadArray }
  104.  
  105. begin { ReadHelpFile }
  106.   Window(FirstCol, FirstRow, LastCol, LastRow);
  107.   GotoXY(1, 1);
  108.   ClrScr;
  109.   GotoXY(1, 1);
  110.   WriteLn;
  111.   Write('Looking for ', HelpFileName);
  112.   Assign(HelpFile, HelpFileName);
  113.   {$I-}
  114.   Reset(HelpFile);
  115.   {$I+}
  116.   if IOresult <> 0 then
  117.   begin
  118.     GotoXY(1, 2);
  119.     ClrEOL;
  120.     WriteLn(HelpFileName, ' not found.');
  121.     Write('Press <ESC> ');
  122.     Ch := ReadKey;
  123.     ReadHelpFile := false;
  124.   end
  125.   else
  126.   begin
  127.     LoadArray;
  128.     if LastLineRead < 1 then
  129.     begin
  130.       ClrScr;
  131.       GotoXY(1, 2);
  132.       ClrEOL;
  133.       WriteLn('The help file is empty.');
  134.       Write('Press <ESC> ');
  135.       Ch := ReadKey;
  136.       ReadHelpFile := false;
  137.     end
  138.     else
  139.     begin
  140.       ReadHelpFile := true;
  141.       FileRead := true;
  142.     end;
  143.   end;
  144. end; { ReadHelpFile }
  145.  
  146. procedure Displayfile;
  147. { Display the help file in the help window }
  148. const
  149.   PgDn   = #81;
  150.   PgUp   = #73;
  151.   ScrlDn = #80;
  152.   ScrlUp = #72;
  153.   Esc    = #27;
  154.   NullKey   = #0;
  155. var
  156.   TopLine, BottomLine, MaxRows   : integer;
  157.   PgCommand                      : char;
  158.  
  159. procedure DisplayPage(TopLine, BottomLine : integer);
  160. { Display a page of text in the help window }
  161. var
  162.   Row : integer;
  163. begin
  164.   ClrScr;
  165.   for Row := TopLine to BottomLine do
  166.   begin
  167.     if Row <> BottomLine then
  168.       WriteLn(HelpText[row])
  169.     else
  170.       Write(HelpText[row]);
  171.   end;
  172.   GotoXY(1, LastRow);
  173. end; { DisplayPage }
  174.  
  175. procedure PageDown(var TopLine, BottomLine : integer);
  176. { Page down in the help window }
  177. begin
  178.   if BottomLine + 1 <= LastLineRead then
  179.   begin
  180.     if (BottomLine + MaxRows) > LastLineRead then
  181.       BottomLine := LastLineRead
  182.     else
  183.       BottomLine := BottomLine + MaxRows;
  184.     if (BottomLine - MaxRows + 1) >= 1 then
  185.       TopLine := (BottomLine - MaxRows + 1)
  186.     else
  187.       TopLine := 1;
  188.     DisplayPage(TopLine, BottomLine);
  189.   end;
  190. end; { PageDown }
  191.  
  192. procedure PageUp(var TopLine, BottomLine : integer);
  193. { Page up in the help window }
  194. begin
  195.   if TopLine > 1 then
  196.   begin
  197.     if (TopLine - MaxRows) > 1 then                 { Set TopLine    }
  198.       TopLine := TopLine - MaxRows
  199.     else
  200.       TopLine := 1;
  201.     if (TopLine + MaxRows - 1) > LastLineRead then  { Set BottomLine }
  202.       BottomLine := LastLineRead
  203.     else
  204.       BottomLine := TopLine + MaxRows - 1;
  205.     DisplayPage(TopLine, BottomLine);
  206.   end;
  207. end; { PageUp }
  208.  
  209. procedure ScrollUp(var TopLine, BottomLine : integer);
  210. { Scroll the help screen up one line }
  211. begin
  212.   if TopLine > 1 then
  213.   begin
  214.     if (BottomLine - TopLine + 1) >= MaxRows then  { screen was full }
  215.       BottomLine := BottomLine - 1;
  216.     TopLine := TopLine - 1;
  217.     GotoXY(1, MaxRows);
  218.     DelLine;
  219.     GotoXY(1, 1);
  220.     InsLine;
  221.     Write(HelpText[TopLine]);
  222.     GotoXY(1, MaxRows);
  223.   end;
  224. end; { ScrollUp }
  225.  
  226. procedure ScrollDown(var TopLine, BottomLine : integer);
  227. { Scroll the help screen down one line }
  228. begin
  229.   if BottomLine < LastLineRead then
  230.   begin
  231.     TopLine := TopLine + 1;
  232.     BottomLine := BottomLine + 1;
  233.     GotoXY(1, 1);
  234.     DelLine;
  235.     GotoXY(1, MaxRows);
  236.     InsLine;
  237.     Write(HelpText[BottomLine]);
  238.     GotoXY(1, MaxRows);
  239.   end;
  240. end; { ScrollDown }
  241.  
  242. procedure Init;
  243. { Initialization routine }
  244. begin
  245.   MaxRows := LastRow - FirstRow + 1;
  246.   TopLine := 1;
  247.   if MaxRows > LastLineRead then
  248.     BottomLine := LastLineRead
  249.   else
  250.     BottomLine := MaxRows;
  251.   DisplayPage(TopLine, BottomLine);  { Show first page }
  252. end; { Init }
  253.  
  254. begin { Displayfile }
  255.   Init;
  256.   repeat
  257.     PgCommand := ReadKey;
  258.     PgCommand := UpCase(PgCommand);
  259.     if (PgCommand = CtrlC) or (PgCommand = 'Q') then
  260.       Abort;
  261.     if (PgCommand = NullKey) then
  262.     begin
  263.       PgCommand := ReadKey;
  264.       PgCommand := UpCase(PgCommand);
  265.       case PgCommand of
  266.         PgDn   : PageDown(TopLine, BottomLine);
  267.         PgUp   : PageUp(TopLine, BottomLine);
  268.         ScrlDn : ScrollDown(TopLine, BottomLine);
  269.         ScrlUp : ScrollUp(TopLine, BottomLine);
  270.       end;
  271.     end;
  272.   until (PgCommand = Esc);
  273. end; { Displayfile }
  274.  
  275. begin { Help }
  276.   GotoXY(49, 5);                     { Display help commands }
  277.   WriteHelp('ESC-Exits Help', 3);
  278.   Window(FirstCol - 2, FirstRow - 1, LastCol + 1, LastRow + 2);
  279.   GotoXY(1, 1);
  280.   DrawBorder;
  281.   DrawHelpLine;
  282.   if FileRead then                            { Display help }
  283.   begin
  284.     Window(FirstCol, FirstRow, LastCol, LastRow);
  285.     GotoXY(1, 1);
  286.     Displayfile;
  287.   end
  288.   else
  289.   if ReadHelpFile then                { Help read from disk?  }
  290.     Displayfile;
  291.   Window(FirstCol - 2, FirstRow - 1,           { Close window }
  292.          LastCol + 1, LastRow + 2);
  293.   GotoXY(1, 1);
  294.   ClrScr;
  295.   Window(1, 1, 80, 25);                      { Restore screen }
  296.   GotoXY(1, 1);
  297.   GotoXY(49, 5);
  298.   WriteHelp('?-for Help    ', 1);              { Restore menu }
  299. end; { Help }
  300.  
  301. { ================ End Of On-Line Help Module =============== }
  302.