home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l040 / 10.ddi / CHESS.ZIP / TVCHSTAT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-27  |  1.8 KB  |  71 lines

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