home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Pascal / BPASCAL.700 / D12 / CHESSTV.ZIP / CHESSST.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-01  |  1.5 KB  |  62 lines

  1. unit ChessSt;
  2. interface
  3. {$IFDEF DLL}
  4. uses Objects, Views, Menus, Drivers, ChessDLL;
  5. {$ELSE}
  6. uses Objects, Views, Menus, Drivers, ChessInf;
  7. {$ENDIF}
  8.  
  9. type
  10.   PChessStatusLine = ^TChessStatusLine;
  11.   TChessStatusLine = object(TStatusLine)
  12.     ChessStatus: TChessStatus;
  13.     MateInMoves: Longint;
  14.     procedure Draw; virtual;
  15.     function Hint(Ctx: Word): String; virtual;
  16.     procedure SetStatus(AChessStatus: TChessStatus; Count: Integer);
  17.   end;
  18.  
  19. implementation
  20.  
  21. procedure TChessStatusLine.Draw;
  22. var
  23.   B: TDrawBuffer;
  24.   CNormal: Word;
  25.   StatBuf: String;
  26. begin
  27.   CNormal := GetColor($0301);
  28.   MoveChar(B, ' ', Byte(CNormal), Size.X);
  29.   StatBuf := Hint(0);
  30.   if Length(StatBuf) > Size.X then StatBuf[0] := Char(Size.X);
  31.   MoveStr(B, StatBuf, Byte(CNormal));
  32.   WriteLine(0, 0, Size.X, 1, B);
  33. end;
  34.  
  35. function TChessStatusLine.Hint(Ctx: Word): String;
  36. var
  37.   S: String;
  38. begin
  39.   case ChessStatus of
  40.     csNormal: Hint := '';
  41.     csCheck: Hint := 'Check!';
  42.     csCheckMate: Hint := 'Checkmate!';
  43.     csStaleMate: Hint := 'Stalemate!';
  44.     csResigns: Hint := 'Resigns!';
  45.     csMateFound:
  46.       begin
  47.         FormatStr(S, 'Checkmate in %d moves', MateInMoves);
  48.         Hint := S;
  49.       end;
  50.     csFiftyMoveRule: Hint := 'Fifty move rule!';
  51.     csRepetitionRule: Hint := 'Repetition rule!';
  52.   end;
  53. end;
  54.  
  55. procedure TChessStatusLine.SetStatus(AChessStatus: TChessStatus; Count: Integer);
  56. begin
  57.   ChessStatus := AChessStatus;
  58.   MateInMoves := Count;
  59.   DrawView;
  60. end;
  61.  
  62. end.