home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / games / tbridge.zip / DISPLAY.BR < prev    next >
Text File  |  1986-06-01  |  24KB  |  973 lines

  1. {  ╔══════════════════════════════════════════════════════╗
  2.    ║          DISPLAY.BR  Module of BRIDGE.PAS            ║                                                      ║
  3.    ║                                                      ║
  4.    ║               Last modified 10/29/85                 ║                                                      ║
  5.    ║                                                      ║
  6.    ║  This module prints the game information onto the    ║
  7.    ║  screen and to the 'BRIDGE' script file.             ║
  8.    ╚══════════════════════════════════════════════════════╝
  9. }
  10.                { Names of hands, Suits and values }
  11. const
  12.   HandName  :  array[HandType] of string[5] =
  13.                  ('North', 'East', 'South', 'West');
  14.   TrumpName :  array[TrumpType] of string[2] =
  15.                 ('Cl', 'Di', 'He', 'Sp', 'NT');
  16.   ValueName :  array[ValueType] of CHAR =
  17.                ('2', '3', '4', '5', '6', '7', '8',
  18.                  '9', 'T', 'J', 'Q', 'K', 'A');
  19. var
  20.   TrumpStr :  array[TrumpType] of string[2];
  21.  
  22. procedure InitTrumpStr;
  23. begin
  24.   TrumpStr[Club   ] := chr(5);
  25.   TrumpStr[Diamond] := chr(4);
  26.   TrumpStr[Heart  ] := chr(3);
  27.   TrumpStr[Spade  ] := chr(6);
  28.   TrumpStr[NT     ] := 'NT';
  29. end; { InitTrumpStr }
  30.  
  31. { Colors }
  32. type
  33.   TextColorType = record
  34.                     Background,
  35.                     Color : 0..15;
  36.                   end;
  37.  
  38.   ScreenPos = record
  39.                 x, y : integer;
  40.                 Color, background : 0..15;
  41.               end;
  42.  
  43. const           { Type constants for screen colors }
  44.   NormalColor   : TextColorType =
  45.                    (background : Cyan;   Color : Black);
  46.   LightColor    : TextColorType =
  47.                    (Background : Cyan; Color : White);
  48.   HandNameColor : TextColorType =
  49.                    (background : LightGray;   Color : Yellow);
  50.   HeadingColor  : TextColorType =
  51.                    (background : LightGray;   Color : Blue);
  52.   BoardColor    : TextColorType =
  53.                    (background : Green;       Color : Brown);
  54.   MessageColor  : TextColorType =
  55.                    (Background : Red; Color : White);
  56.   BorderColor   : TextColorType =
  57.                    (Background : Blue; Color : Black);
  58.   ScoreBrdColor : TextColorType =
  59.                    (Background : LightGray; Color : Black);
  60.   ScoreColor    : TextColorType =
  61.                    (Background : Blue; Color : White);
  62.   TrumpColor    : array[TrumpType] of TextColorType =
  63.                    ((background: LightGray;   Color: Black),
  64.                     (background: LightGray;   Color: Red),
  65.                     (background: LightGray;   Color: Red),
  66.                     (background: LightGray;   Color: Black),
  67.                     (background: LightGray;   Color: Blue));
  68.   MenuPos    : ScreenPos =
  69.                  (x : 51; y : 18;
  70.                   Color : Black; background : Cyan);
  71.   CommandPos : ScreenPos =
  72.                  (x : 51; y : 21;
  73.                   Color : Black; background : LightGray);
  74.   ErrorPos   : ScreenPos =
  75.                  (x : 51; y : 22;
  76.                   Color : White; background : Red);
  77.  
  78. procedure SetColor(ScreenColor: TextColorType);
  79. begin
  80.    TextBackground(ScreenColor.Background);
  81.    TextColor(ScreenColor.Color);
  82. end; { SetColor }
  83.  
  84. procedure GotoPos(CurPos : ScreenPos;
  85.                   Xoffset, Yoffset : integer);
  86. { Goes to the passed in screen position and offset and sets the color
  87.   for this field on the screen }
  88. begin
  89.   with CurPos do
  90.   begin
  91.     TextColor(Color);
  92.     TextBackground(Background);
  93.     GotoXY(x + Xoffset, y + Yoffset);
  94.   end;
  95. end; { GotoPos }
  96.  
  97. type
  98.   WindowString = string[25];
  99.  
  100. procedure FlushBuffer;
  101. { flushes the keyboard buffer }
  102. var
  103.   Null : char;
  104. begin
  105.   while KeyPressed do
  106.     Read(KBD, Null);
  107. end; { FlushBuffer }
  108.  
  109. function EqBid(a, b: BidType): BOOLEAN;
  110. begin
  111.   EqBid := (a.Level = b.Level) and (a.Trump = b.Trump);
  112. end; { EqBid }
  113.  
  114. function DistPoints(Hand: HandType): integer;
  115. { Count distribution points for Player
  116.   (Void Suit 3, Singleton 2, Doubleton 1) used for bidding }
  117. var
  118.   Pts  : integer;
  119.   s    : SuitType;
  120. begin
  121.   Pts := 0;
  122.   with Sdata[Hand] do
  123.     for s := Club to Spade do
  124.       if l[s] <= 2 then
  125.         Pts := Pts + 3 - l[s];
  126.   DistPoints := Pts;
  127. end; { DistPoints }
  128.  
  129. type
  130.   str4 = string[4];
  131.  
  132. function BidStr(Bid: BidType): str4;
  133. { Converts a Bid to a string }
  134. begin
  135.   if EqBid(Bid, Pass) then
  136.     BidStr := 'Pass'
  137.   else
  138.     if EqBid(Bid, Dbl) then
  139.       BidStr := 'Dbl'
  140.     else
  141.       if EqBid(Bid, RDbl) then
  142.         BidStr := 'RDbl'
  143.       else
  144.         with Bid do
  145.           BidStr := chr(Ord('0') + Level) + ' ' + TrumpStr[Trump];
  146. end; { BidStr }
  147.  
  148. function CardStr(Card: CardType): str4;
  149. { Converts a Card to a string }
  150. begin
  151.   with Card do
  152.     CardStr := ValueName[Value] + ' ' + TrumpStr[Suit];
  153. end; { CardStr }
  154.  
  155. function AsciiBidStr(Bid: BidType): str4;
  156. { BidStr with ascii characters for output file }
  157. begin
  158.   with Bid do
  159.     if Level=0 then
  160.       AsciiBidStr := BidStr(Bid)
  161.     else
  162.       AsciiBidStr := chr(Ord('0') + Level) + ' ' + TrumpName[Trump];
  163. end; { AsciiBidStr }
  164.  
  165. function AsciiCardStr(Card: CardType): str4;
  166. { CardStr with ascii characters for output file }
  167. begin
  168.   with Card do
  169.     AsciiCardStr := ValueName[Value] + ' ' + TrumpName[Suit];
  170. end; { AsciiCardStr }
  171.  
  172. procedure Frame(x1, y1, x2, y2: integer);
  173. { Print the frame of the card table }
  174. var
  175.   x, y: integer;
  176. type
  177.   str3 = string[3];
  178.  
  179. procedure Line(y: integer;   s: str3);
  180. begin
  181.   GotoXY(x1, y);
  182.   Write(s[1]);
  183.   for x := x1 + 1 to x2-1 do
  184.     Write(s[2]);
  185.   Write(s[3]);
  186. end; { Line }
  187.  
  188. begin
  189.   Line(y1, '█▀█');   for y := y1 + 1 to y2-1 do
  190.   Line(y , '█ █');
  191.   Line(y2, '█▄█');
  192. end; { Frame }
  193.  
  194. var
  195.   TopHand: HandType;
  196.  
  197. procedure GotoHand(Hand: HandType;   x1, y1 : integer);
  198. { go to the hand position on the screen }
  199. const
  200.   HandPos: array[0..3] of record
  201.                             x, y: integer;
  202.                           end =
  203.                                ((x: 33; y:  1),
  204.                                 (x: 51; y:  6),
  205.                                 (x: 33; y: 13),
  206.                                 (x:  3; y:  6));
  207. begin
  208.   with HandPos[(Hand-TopHand) and 3] do
  209.     GotoXY(x + x1, y + y1);
  210. end; { GotoHand }
  211.  
  212. procedure ClearHand(Hand : HandType);
  213. begin
  214.   GotoHand(Hand, 0, 0);
  215.   SetColor(NormalColor);
  216.   Window(WhereX, WhereY, WhereX + 28, WhereY + 4);
  217.   ClrScr;
  218.   Window(1, 1, 80, 25);
  219. end; { ClearHand }
  220.  
  221. procedure GotoCardPos(Hand: HandType);
  222. { goto the hands Card position on the screen }
  223. const
  224.   CardPos: array[0..3] of record
  225.                             x, y: integer;
  226.                           end =
  227.                                ((x: 38; y:  8),
  228.                                 (x: 41; y:  9),
  229.                                 (x: 38; y: 10),
  230.                                 (x: 35; y:  9));
  231. begin
  232.   with CardPos[(Hand-TopHand) and 3] do
  233.     GotoXY(x, y);
  234. end; { GotoCardPos }
  235.  
  236. const
  237.   WindowLine = 20;
  238. var
  239.   WindowHand : HandType;
  240.       InfoNo : integer;
  241.  
  242. procedure PrintNames(Hand: HandType);
  243. { Reset the information Window and print the names of the 4 hands }
  244. var
  245.   h, StartX, StartY : integer;
  246. begin
  247.   StartX := WhereX;
  248.   StartY := WhereY;
  249.   WindowHand := Hand;
  250.   InfoNo := 0;
  251.   SetColor(HandNameColor);
  252.   for h := 0 to 3 do
  253.   begin
  254.     GotoXY(h*8 + 3, WindowLine);
  255.     Write(HandName[(Hand + h) and 3]);
  256.   end;
  257.   GotoXY(StartX, StartY);
  258. end; { PrintNames }
  259.  
  260. procedure OutputNames(Hand: HandType);
  261. { Output the names of the 4 hands on the OutputFile }
  262. var
  263.   h: integer;
  264. begin
  265.   Writeln(OutputFile);
  266.   for h := 0 to 3 do
  267.     Write(OutputFile, HandName[(Hand + h) and 3],
  268.                      '':8-Length(HandName[(Hand + h) and 3]));
  269. end; { OutputNames }
  270.  
  271. procedure ClearBidWindow;
  272. begin
  273.   Window(1, WindowLine + 1, 40, 25);
  274.   SetColor(NormalColor);
  275.   ClrScr;
  276.   Window(1, 1, 80, 25);
  277. end; { ClearBidWindow }
  278.  
  279. procedure ClearBidScreen;
  280. begin
  281.   Window(1, WindowLine, 40, 25);
  282.   SetColor(NormalColor);
  283.   ClrScr;
  284.   Window(1, 1, 80, 25);
  285. end; { ClearBidScreen }
  286.  
  287. type
  288.   str6 = string[6];
  289.  
  290. procedure PrintInfo(Hand: HandType;   Trump: TrumpType;
  291.                           CardString : str6; Bidding : boolean);
  292. { Print information in the information Window }
  293.  
  294. function NextHand(Hand : HandType): HandType;
  295. { Calculates the Hand to the 'left' of the current Hand }
  296. begin
  297.   if Hand = West then
  298.     NextHand := North
  299.   else NextHand := Succ(Hand);
  300. end; { NextHand }
  301.  
  302. var
  303.   LineNo: integer;
  304. begin  { PrintInfo }
  305.   LineNo := WindowLine + InfoNo div 4 + 1;
  306.   if (LineNo > 24) then
  307.   begin
  308.     LineNo := 24;
  309.     if InfoNo and 3 = 0 then
  310.     begin
  311.       SetColor(NormalColor);
  312.       GotoXY(3, WindowLine + 1);
  313.       Window(3, WindowLine + 1, 40, 25);
  314.       DelLine;
  315.       Window(1, 1, 80, 25);
  316.     end;
  317.   end;
  318.   if Bidding then
  319.   begin
  320.     SetColor(BoardColor);
  321.     GotoCardPos(NextHand(Hand));
  322.     Write('    ');
  323.   end;
  324.   GotoXY(((Hand-WindowHand) and 3) * 8 + 3, LineNo);
  325.   SetColor(TrumpColor[Trump]);
  326.   Write(CardString);
  327.   GotoCardPos(Hand);
  328.   Write(CardString);
  329.   InfoNo := InfoNo + 1;
  330. end; { PrintInfo }
  331.  
  332. procedure OutputInfo(Str: str6);
  333. { Output information on the OutputFile }
  334. begin
  335.   Write(OutputFile, Str, '':8-Length(Str));
  336. end; { OutputInfo }
  337.  
  338. procedure PrintBid(Hand: HandType;   Bid: BidType);
  339. { Print and output a Bid }
  340. const
  341.   Bidding : boolean = true;
  342. begin
  343.   PrintInfo(Hand, Bid.Trump, BidStr(Bid), Bidding);
  344.   if (InfoNo and 3 = 1) then
  345.     Writeln(OutputFile);
  346.   OutputInfo(AsciiBidStr(Bid));
  347. end; { PrintBid }
  348.  
  349. procedure StopGames; forward;
  350.  
  351. procedure ReadOne;
  352. var
  353.   ch : char;
  354. begin
  355.   repeat until KeyPressed;
  356.   Read(KBD, ch);
  357.   case ch of
  358.    ^C : StopGames;
  359.    ^[ : if KeyPressed then
  360.           FlushBuffer;
  361.   end;
  362. end; { ReadOne }
  363.  
  364. procedure ClearMenu; forward;
  365.  
  366. procedure ClearTblMsg;
  367. begin
  368.   ClearMenu;
  369.   FlushBuffer;
  370.   GotoPos(MenuPos, 0, 0);
  371.   Write('Hit any key to clear table');
  372.   ReadOne;
  373. end; { ClearTblMsg }
  374.  
  375. procedure ClearTable;
  376. { Clears the cards off the table }
  377. var
  378.   Hand  : HandType;
  379. begin
  380.   SetColor(BoardColor);
  381.   for Hand := North to West do
  382.   begin
  383.     GotoCardPos(Hand);
  384.     Write('    ');
  385.   end;
  386. end; { ClearTable }
  387.  
  388. procedure PrintCard(Hand: HandType;   Card: CardType);
  389. { Print and output a Card }
  390. const
  391.   Bidding : boolean = false;
  392. var
  393.   i   : integer;
  394.   r   : IndexType;
  395.   Str : str6;
  396. begin
  397.   PrintInfo(Hand, Card.Suit, CardStr(Card), Bidding);
  398.   with Sim do
  399.     if Round and 3=0 then
  400.     begin
  401.       Writeln(OutputFile);
  402.       for i := 0 to 3 do
  403.         for r := Round-4 to Round-1 do
  404.           with Game[r] do if Hand=(Dummy-1 + i) and 3 then
  405.           begin
  406.             Str := AsciiCardStr(Sdist[Hand, No]);
  407.             if Hand=BestHand then
  408.               Str := Str + '*';
  409.             OutputInfo(Str);
  410.           end;
  411.     end;
  412. end; { PrintCard }
  413.  
  414. var
  415.   PrintAll : BOOLEAN;   { Print All hands on screen }
  416.  
  417. function AutoGame : boolean;
  418. { Returns true if the computer is playing all the hands }
  419. var
  420.   CurHand : HandType;
  421. begin
  422.   AutoGame := true;
  423.   for CurHand := North to West do
  424.    if not Computer[CurHand] then
  425.      AutoGame := false;
  426. end; { AutoGame }
  427.  
  428. function HandKnown(Hand: HandType): BOOLEAN;
  429. { Indicates whether the Hand should be printed on the screen }
  430. begin
  431.   HandKnown := PrintAll or not Computer[Hand]
  432.                         or (Rel.Round>0) and
  433.                         ((Hand = Dummy) {or not Computer[Dummy]})
  434.                         or AutoGame;
  435. end; { HandKown }
  436.  
  437. procedure PrintSuit(Hand: HandType;   s: SuitType);
  438. { Print the cards of the Hand in the Suit }
  439. var
  440.  i : CardNoType;
  441. begin
  442.   if HandKnown(Hand) then
  443.   begin
  444.     GotoHand(Hand, 0, 4-Ord(s));
  445.     SetColor(TrumpColor[s]);
  446.     Write(TrumpStr[s]);
  447.     for i := 0 to 12 do
  448.       with Sdist[Hand, i] do
  449.         if not Played and (Suit=s) then
  450.           Write(ValueName[Value]:2);
  451.     SetColor(NormalColor);
  452.     Write('  ');
  453.   end;
  454. end; { PrintSuit }
  455.  
  456. procedure PrintHand(Hand: HandType);
  457. { Print the Hand on the screen }
  458. var
  459.   s : SuitType;
  460. begin
  461.   ClearHand(Hand);
  462.   GotoHand(Hand, 0, 0);
  463.   SetColor(HandNameColor);
  464.   Write(HandName[Hand]);
  465.   for s := Club to Spade do
  466.     PrintSuit(Hand, s);
  467. end; { PrintHand }
  468.  
  469. procedure NewScreen;
  470. { Clears screen and prints header information and card table }
  471. begin
  472.   SetColor(NormalColor);
  473.   ClrScr;
  474.   GotoXY(3, 1);
  475.   SetColor(HeadingColor);
  476.   Write('TURBO - BRIDGE');
  477.   SetColor(BoardColor);
  478.   Frame(33, 6, 45, 12);
  479. end; { NewScreen }
  480.  
  481. procedure ClearInfoArea;
  482. begin
  483.   Window(51, 1, 79, 5);
  484.   SetColor(NormalColor);
  485.   ClrScr;
  486.   Window(1, 1, 80, 25);
  487. end; { ClearInfoArea }
  488.  
  489. procedure ClearIt;
  490. { Clears table and bid screen }
  491. begin
  492.   ClearTable;
  493.   ClearBidScreen;
  494. end; { ClearIt }
  495.  
  496. procedure PrintScreen(FirstHand: HandType);
  497. { Setup the screen picture with the Known hands }
  498. var
  499.   Hand: HandType;
  500. begin
  501.   TopHand := FirstHand;
  502.   for Hand := North to West do
  503.     PrintHand(Hand);
  504. end; { PrintScreen }
  505.  
  506. procedure OutputHands;
  507. { Output the hands on the OutputFile }
  508.  
  509. procedure OutputHandName(Hand: HandType);
  510. begin
  511.   if Hand = North then
  512.     Write(OutputFile, 'Game', GameNo:5, '':24-9)
  513.   else
  514.     if Hand = South then
  515.       Write(OutputFile, '':24);
  516.  
  517.   Write(OutputFile, HandName[Hand], '':7 - Length(HandName[Hand]),
  518.                    Sdata[Hand].p - DistPoints(Hand):2, ' + ',
  519.                    DistPoints(Hand):1);
  520.   if (Hand = West) then
  521.     Write(OutputFile, '':48 - 7 - 6)
  522.   else
  523.     Writeln(OutputFile);
  524. end; { OutputHandName }
  525.  
  526. procedure OutputSuit(Hand: HandType;   s: SuitType);
  527. var   i : CardNoType;
  528. begin
  529.   if Hand in [North, South] then
  530.     Write(OutputFile, '':24);
  531.   Write(OutputFile, TrumpName[s]);
  532.   for i := 0 to 12 do with Sdist[Hand, i] do
  533.     if not Played and (Suit=s) then
  534.       Write(OutputFile, ValueName[Value]:2);
  535.   if Hand=West then
  536.     Write(OutputFile, '':48-2-Sdata[Hand].l[s] * 2)
  537.   else
  538.     Writeln(OutputFile);
  539. end; { OutputSuit }
  540.  
  541. var
  542.   Suit: SuitType;
  543. begin { OutputHands }
  544.   OutputHandName(North);
  545.   for Suit := Spade downto Club do OutputSuit(North, Suit);
  546.   OutputHandName(West);   OutputHandName(East);
  547.   for Suit := Spade downto Club do
  548.   begin
  549.     OutputSuit(West, Suit);   OutputSuit(East, Suit);
  550.   end;
  551.   OutputHandName(South);
  552.   for Suit := Spade downto Club do
  553.     OutputSuit(South, Suit);
  554. end; { OutputHands }
  555.  
  556. function Partner(CurHand : HandType): HandType;
  557. { returns the team Partner of the passed in Hand }
  558. begin
  559.   if CurHand < South then
  560.     Partner := CurHand + 2
  561.   else
  562.     Partner := CurHand - 2;
  563. end; { Partner }
  564.  
  565. function Opponent(CurHand : HandType): HandType;
  566. { returns an Opponent of the passed in Hand }
  567. begin
  568.   if CurHand < South then
  569.     Opponent := CurHand + 1
  570.   else
  571.      Opponent := CurHand - 1;
  572. end; { Opponent }
  573.  
  574. procedure PrintTeam(Player : HandType);
  575. { Prints the team of the passed in player to the screen }
  576. begin
  577.   if Player < South then
  578.     Write(HandName[Player][1], '/', HandName[Partner(Player)][1])
  579.   else
  580.     Write(HandName[Partner(Player)][1], '/', HandName[Player][1]);
  581. end; { PrintTeam }
  582.  
  583. procedure OutputTeam(Player : HandType);
  584. { Prints the team of the passed in player to the output file }
  585. begin
  586.   if Player < South then
  587.     Write(OutputFile, HandName[Player][1], '/',
  588.           HandName[Partner(Player)][1])
  589.   else
  590.     Write(OutputFile, HandName[Partner(Player)][1], '/',
  591.           HandName[Player][1]);
  592. end; { OutputTeam }
  593.  
  594. procedure OutputContract;
  595. { Prints the contract to the output file }
  596. begin
  597.   Writeln(OutputFile);
  598.   Writeln(OutputFile);
  599.   Write(OutputFile, ' ':10, 'Contract:    ');
  600.   OutputTeam(Dummy);
  601.   Write(OutputFile, ' ':3, AsciiBidStr(Contract));
  602.   case Doubled of
  603.     1: Writeln(OutputFile, ' D');
  604.     2: Writeln(OutputFile, ' RD');
  605.   end;
  606. end; { OutputContract }
  607.  
  608. procedure PrintContract;
  609. { Print the Contract to the screen }
  610. begin
  611.   GotoXY(53, 1);
  612.   SetColor(NormalColor);
  613.   Write('Declarer: ');
  614.   SetColor(MessageColor);
  615.   GotoXY(63, 1);
  616.   PrintTeam(Dummy);
  617.   GotoXY(63, 2);
  618.   SetColor(TrumpColor[Contract.Trump]);
  619.   Write(BidStr(Contract));
  620.   case Doubled of
  621.     1: Write(' D');
  622.     2: Write(' RD');
  623.   end;
  624. end; { PrintContract }
  625.  
  626. procedure Printresult;
  627. { Print and output the Result of the Game }
  628. var
  629.   OverTricks, i : integer;
  630. begin
  631.   with Rel, Contract do
  632.   begin
  633.     for i := 1 to 3 do
  634.       Writeln(OutputFile);
  635.     Write(OutputFile, ' ':10);
  636.     OutputTeam(Dummy);
  637.     SetColor(MessageColor);
  638.     if WonTricks >= Level + 6 then
  639.     begin
  640.       GotoXY(52, 4);
  641.       Write(' ');
  642.       PrintTeam(Dummy);
  643.       Write(' Made Contract ');
  644.       Write(OutputFile, ' made contract ');
  645.       OverTricks := WonTricks - (Level + 6);
  646.       if OverTricks > 0 then
  647.       begin
  648.         GotoXY(61, 5);
  649.         Write(' with ', OverTricks, ' overtrick');
  650.         Write(OutputFile, 'with ', OverTricks, ' overtrick');
  651.         if OverTricks > 1 then
  652.         begin
  653.           Write('s');
  654.           Writeln(OutputFile, 's');
  655.         end;
  656.         Write(' ');
  657.        end;
  658.     end
  659.     else
  660.     begin
  661.       GotoXY(61, 4);
  662.       Write(' ');
  663.       PrintTeam(Dummy);
  664.       Write(' down ', Level + 6-WonTricks, ' ');
  665.       Writeln(OutputFile, ' down ', Level + 6-WonTricks);
  666.     end;
  667.   end; { with }
  668.   Writeln(OutputFile);
  669. end; { Printresult }
  670.  
  671. procedure PrintwonTricks;
  672. { Print Number of Tricks for each side }
  673. begin
  674.   SetColor(MessageColor);
  675.   GotoXY(71, 1);
  676.   PrintTeam(Dummy);
  677.   GotoXY(77, 1);
  678.   PrintTeam(Opponent(Dummy));
  679.   SetColor(NormalColor);
  680.   GotoXY(72, 2);
  681.   with Rel do
  682.     Write(WonTricks:2, '  - ', TrickNo-WonTricks:2);
  683. end; { PrintwonTricks }
  684.  
  685. procedure ClearEol;
  686. begin
  687.   SetColor(NormalColor);
  688.   ClrEol;
  689. end;  { ClearEol }
  690.  
  691. procedure ClearTopMenu;
  692. var
  693.   CurY : integer;
  694. begin
  695.   for CurY := 0 to 2 do
  696.   begin
  697.     GotoPos(MenuPos, 0, CurY);
  698.     ClearEol;
  699.   end;
  700. end; { ClearTopMenu }
  701.  
  702. procedure ClearCommand;
  703. { Clears the area on the screen of the user prompt }
  704. var
  705.   CurY : integer;
  706. begin
  707.   for CurY := 0 to 1 do
  708.   begin
  709.     GotoPos(CommandPos, 0, CurY);
  710.     ClearEol;
  711.   end;
  712. end; { ClearCommand }
  713.  
  714. procedure ClearHelp;
  715. { Clears Help Window on screen }
  716. var
  717.   CurY : integer;
  718. begin
  719.   for CurY := 2 to 4 do
  720.   begin
  721.     GotoPos(CommandPos, 0, CurY);
  722.     ClearEol;
  723.   end;
  724. end; { ClearHelp }
  725.  
  726. procedure ClearBottomMenu;
  727. begin
  728.   ClearCommand;
  729.   ClearHelp;
  730. end; { ClearBottomMenu }
  731.  
  732. procedure ClearMenu;
  733. begin
  734.   ClearTopMenu;
  735.   ClearBottomMenu;
  736. end; { ClearMenu }
  737.  
  738. procedure ReClear;
  739. { Clears Menu but not the command linc }
  740. begin
  741.   ClearTopMenu;
  742.   ClearHelp;
  743. end;
  744.  
  745. type
  746.   PrintString = string[30];
  747.  
  748. procedure LightFirst(Message : PrintString; CurPos : ScreenPos);
  749. { Prints pased in string highlighting the first character }
  750. var
  751.  i : integer;
  752. begin
  753.   SetColor(LightColor);
  754.   Write(Message[1]);
  755.   if Length(Message) > 1 then
  756.   begin
  757.     TextColor(CurPos.Color);
  758.     TextBackground(CurPos.background);
  759.     for i := 2 to Length(Message) do
  760.       Write(Message[i]);
  761.   end;
  762. end; { LightFirst }
  763.  
  764. procedure BidHelp;
  765. { Help lines show the user how to make legal bid }
  766. var
  767.   StartX, StartY : integer;
  768. begin
  769.   StartX := WhereX;
  770.   StartY := WhereY;
  771.   ClearHelp;
  772.   GotoPos(CommandPos, 0, 2);
  773.   Write(' Bid Number of Tricks 1..7 ');
  774.   GotoPos(CommandPos, 0, 3);
  775.   Write(' ');
  776.   LightFirst('Double   ', CommandPos);
  777.   LightFirst('Redouble   ', CommandPos);
  778.   LightFirst('Pass  ', CommandPos);
  779.   GotoPos(CommandPos, 0, 4);
  780.   Write(' ':27);
  781.   GotoXY(StartX, StartY);   { Restore cursor }
  782. end; { BidHelp }
  783.  
  784. procedure SuitHelp;
  785. { Shows user how to legally specify the card suits }
  786. begin
  787.   ClearTopMenu;
  788.   ClearHelp;
  789.   GotoPos(MenuPos, 6, 0);
  790.   LightFirst('Clubs    ', MenuPos);
  791.   LightFirst('Diamonds', MenuPos);
  792.   GotoPos(MenuPos, 6, 1);
  793.   LightFirst('Hearts   ', MenuPos);
  794.   LightFirst('Spades', MenuPos);
  795. end; { SuitHelp }
  796.  
  797. procedure BidSuitHelp;
  798. var
  799.   StartX, StartY : integer;
  800. begin
  801.   StartX := WhereX;
  802.   StartY := WhereY;
  803.   SuitHelp;
  804.   GotoPos(MenuPos, 11, 2);
  805.   LightFirst('NoTrump', MenuPos);
  806.   GotoXY(StartX, StartY);   { Restore cursor }
  807. end; { BidSuitHelp }
  808.  
  809. procedure BidMenu;
  810. var
  811.   StartX, StartY : integer;
  812. begin
  813.   StartX := WhereX;
  814.   StartY := WhereY;
  815.   ReClear;
  816.   GotoPos(MenuPos, 3, 0);
  817.   LightFirst('ClearBids   ', MenuPos);
  818.   LightFirst('NewDeal', MenuPos);
  819.   GotoPos(MenuPos, 3, 1);
  820.   LightFirst('Score      ', MenuPos);
  821.   Write('e');
  822.   LightFirst('Xit ', MenuPos);
  823.   BidHelp;
  824.   GotoXY(StartX, StartY);       { Restore cursor position }
  825. end; { BidMenu }
  826.  
  827. function Lead : boolean;
  828. { True if the current hand is to lead }
  829. begin
  830.   Lead := Rel.Round and 3 = 0;
  831. end;
  832.  
  833. procedure PlaySuitHelp;
  834. var
  835.   StartX, StartY : integer;
  836. begin
  837.   StartX := WhereX;
  838.   StartY := WhereY;
  839.   SuitHelp;
  840.   if not Lead then
  841.   begin
  842.     GotoPos(CommandPos, 0, 3);
  843.     Write('or hit <RETURN> for lead Suit');
  844.   end;
  845.   GotoXY(StartX, StartY);   { Restore cursor }
  846. end; { PlaySuitHelp }
  847.  
  848. procedure RankHelp;
  849. { Help mesage on how to enter Card ranks }
  850. var
  851.   StartX, StartY : integer;
  852. begin
  853.   StartX := WhereX;
  854.   StartY := WhereY;
  855.   ClearHelp;
  856.   GotoPos(CommandPos, 0, 2);
  857.   Write(' Card ranks: 2..9,T,J,Q,K,A  ');
  858.   if not Lead then
  859.   begin
  860.     GotoPos(CommandPos, 0, 3);
  861.     Write(' or hit <RETURN> to discard  ');
  862.   end;
  863.   GotoXY(StartX, StartY);
  864. end; { RankHelp }
  865.  
  866. procedure PlayMenu;
  867. var
  868.   StartX, StartY : integer;
  869. begin
  870.   StartX := WhereX;
  871.   StartY := WhereY;
  872.   ReClear;
  873.   GotoPos(MenuPos, 2, 0);
  874.   Write('Aut');
  875.   LightFirst('Oplay', MenuPos);
  876.   GotoPos(MenuPos, 16, 0);
  877.   LightFirst('NewGame', MenuPos);
  878.   GotoPos(MenuPos, 5, 1);
  879.   LightFirst('Score', MenuPos);
  880.   GotoPos(MenuPos, 16, 1);
  881.   LightFirst('Hint',MenuPos);
  882.   GotoPos(MenuPos, 10, 2);
  883.   Write(' e');
  884.   LightFirst('Xit ', MenuPos);
  885.   RankHelp;
  886.   GotoXY(StartX, StartY);
  887. end; { PlayMenu }
  888.  
  889. procedure PlayMessage(Hand : HandType; Hint : boolean );
  890. { Lets user know that the Computer is playing the Hand }
  891. begin
  892.   ClearMenu;
  893.   GotoPos(CommandPos, 4, -3);
  894.   case Hand of
  895.     North : Write(' North');
  896.     East  : Write(' East');
  897.     South : Write(' South');
  898.     West  : Write(' West');
  899.   end;
  900.   Write(' to ');
  901.   if Hint then Write('find hint ')
  902.   else
  903.   begin
  904.     if Lead then Write('Lead ')
  905.     else Write('Play ');
  906.   end;
  907. end; { PlayMessage }
  908.  
  909. procedure HintHelp;
  910. { Tells user options on hint }
  911. var
  912.   StartX, StartY : integer;
  913. begin
  914.   StartX := WhereX;
  915.   StartY := WhereY;
  916.   ClearHelp;
  917.   GotoPos(CommandPos, 0, 2);
  918.   Write(' Hit <RETURN> to play hint ');
  919.   GotoPos(CommandPos, 0, 3);
  920.   Write('   <BACKSPACE> clears hint ');
  921.   GotoXY(StartX, StartY);   { Restore cursor }
  922. end; { HintHelp }
  923.  
  924. procedure CleanUpBids;
  925. begin
  926.   Delay(800);      { Gives user time to look at the last Bid }
  927.   ClearTable;
  928.   ClearBidScreen;
  929. end; { CleanUpBids }
  930.  
  931. procedure Beep;
  932. { Sounded when an error is detected }
  933. begin
  934.    Sound(220);
  935.    Delay(250);
  936.    NoSound;
  937. end;
  938.  
  939. type
  940.  MessageString = string[80];
  941.  
  942. procedure ClearError;
  943. { Clears out the error message area }
  944. var
  945.   StartX, StartY : integer;
  946. begin
  947.   StartX := WhereX;
  948.   StartY := WhereY;
  949.   GotoPos(ErrorPos, 0, 0);
  950.   ClearEol;
  951.   GotoXY(StartX, StartY);            { Restore cursor position }
  952. end; { ClearError }
  953.  
  954. procedure Message(CurMessage : MessageString);
  955. var
  956.   StartX, StartY : integer;
  957. begin
  958.   StartX := WhereX;
  959.   StartY := WhereY;
  960.   ClearError;
  961.   GotoPos(ErrorPos, 6, 0);
  962.   Write(CurMessage);
  963.   GotoXY(StartX, StartY);
  964. end; { Message }
  965.  
  966. procedure Error(CurError : MessageString);
  967. { Prints passed in Error message }
  968. begin
  969.   Beep;
  970.   Message(CurError);
  971. end; { Error }
  972.  
  973. { end DISPLAY.BR }