home *** CD-ROM | disk | FTP | other *** search
/ synchro.net / synchro.net.tar / synchro.net / main / BBS / D32_01.ZIP / sample.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-07-25  |  2.2 KB  |  108 lines

  1. Program Sample;
  2.  
  3. {$IFDEF MSDOS}
  4.   {$M 40000,0,100000}
  5. {$ENDIF}
  6.  
  7. Uses
  8.   CRT,
  9.   Door32;
  10.  
  11. Function Int2Str (N: LongInt): String;
  12. Var
  13.   T : String;
  14. Begin
  15.   Str(N, T);
  16.   Int2Str := T;
  17. End;
  18.  
  19. Function Str2Int (Str: String): LongInt;
  20. Var
  21.   I   : {$IFNDEF VIRTUALPASCAL} Word; {$ELSE} LongInt; {$ENDIF}
  22.   Temp: LongInt;
  23. Begin
  24.   Val(Str, Temp, i);
  25.   Str2Int := Temp;
  26. End;
  27.  
  28. Procedure PlayGame;
  29. Var
  30.   Winner : Boolean;
  31.   Number : Word;
  32.   Guess  : Word;
  33.   A      : Word;
  34.   Ch     : Char;
  35. Begin
  36.   Randomize;
  37.  
  38.   Repeat
  39.     Winner := False;
  40.     Number := Random(999) + 1;
  41.  
  42.     SendCLS;
  43.     SendLn ('|14Guess a number between 1 and 1000 - you have 10 guesses!');
  44.  
  45.     For Guess := 1 to 10 Do Begin
  46.       Send ('|CR|09Guess #' + Int2Str(Guess) + ': ');
  47.  
  48.       A := Str2Int(Input(0, 4, inNumber, ''));
  49.  
  50.       SendLn ('');
  51.  
  52.       If Number > A Then
  53.         SendLn ('|10The number is greater than |15' + Int2Str(A))
  54.       Else
  55.       If Number < A Then
  56.         SendLn ('|10The number is less than |15' + Int2Str(A))
  57.       Else Begin
  58.         Winner := True;
  59.         Break;
  60.       End;
  61.     End;
  62.  
  63.     If Winner Then
  64.       SendLn ('|12You won!  And it only took you ' + Int2Str(Guess) + ' guesses!')
  65.     Else
  66.       SendLn ('|09You lost.  The number was ' + Int2Str(Number));
  67.  
  68.     Send ('|11Play again? (Y/N): ');
  69.     If OneKey('YN', True) = 'N' Then Break;
  70.   Until False;
  71. End;
  72.  
  73. Var
  74.   Res : Byte;
  75.   Str : String;
  76. Begin
  77.   WriteLn;
  78.  
  79.   If ParamCount <> 1 Then Begin
  80.     WriteLn ('SAMPLE.EXE : A simple sample door program');
  81.     WriteLn;
  82.     WriteLn ('Syntax  : SAMPLE <Path and filename of drop file>');
  83.     {$IFNDEF MSDOS}
  84.       WriteLn ('Example : SAMPLE C:\BBS\DOOR32.SYS');
  85.     {$ELSE}
  86.       WriteLn ('Example : SAMPLE C:\BBS\DORINFO1.DEF');
  87.       WriteLn ('          SAMPLE C:\BBS\DOOR.SYS');
  88.       WriteLn ('          SAMPLE C:\BBS\CHAIN.TXT');
  89.     {$ENDIF}
  90.     Halt;
  91.   End;
  92.  
  93.   Res := OpenDOOR(ParamStr(1));
  94.  
  95.   Case Res of
  96.     1 : WriteLn ('ERROR: Drop file not found.');
  97.     2 : WriteLn ('ERROR: Error reading drop file');
  98.     3 : WriteLn ('ERROR: Unknown drop file type');
  99.     4 : WriteLn ('ERROR: Unable to open communications port');
  100.   End;
  101.  
  102.   If Res <> 0 Then Halt;
  103.  
  104.   PlayGame;
  105.  
  106.   CloseDOOR;
  107. End.
  108.