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

  1.  {  ╔══════════════════════════════════════════════════════╗
  2.     ║        DEFAULTS.BR  Module of BRIDGE.PAS             ║                                                      ║
  3.     ║                                                      ║
  4.     ║            Last modified 10/29/85                    ║
  5.     ║                                                      ║
  6.     ║  Gets the users playing defaults : which hands to    ║
  7.     ║  play, which hands to show, let the computer cheat.  ║
  8.     ╚══════════════════════════════════════════════════════╝
  9.  }
  10. type
  11.   DefaultRec = record
  12.                  Computer : PlayerHand;
  13.                  PrintAll, Cheat, OK : boolean;
  14.                end;
  15. var
  16.   Defaults : DefaultRec;
  17.  
  18. procedure InitDefaults;
  19. { init default values }
  20. begin
  21.   Defaults.Computer[North] := false;
  22.   Defaults.Computer[South] := true;
  23.   Defaults.Computer[East] := false;
  24.   Defaults.Computer[West] := false;
  25.   Defaults.PrintAll := false;
  26.   Defaults.Cheat := false;
  27. end; { InitDefaults }
  28.  
  29. procedure GetDefaults;
  30. const
  31.   LeftX  = 7;
  32.   LeftY  = 3;
  33.   RightX = 72;
  34.   RightY = 20;
  35.   North  = 0;
  36.   East   = 1;
  37.   South  = 2;
  38.   West   = 3;
  39.  
  40. type
  41.   MaxString = string[255];
  42.   PositionRec  = record
  43.                    X, Y, Color, Background : byte;
  44.                  end;
  45.  
  46.   ScreenPositions = (Box, Title, PlayHands,
  47.                      ShowHands, Cheat1, Cheat2,
  48.                      NorthHand, EastHand, SouthHand, WestHand,
  49.                      Showing, Cheating, Play);
  50.   CursorRec = record
  51.     StartLine, EndLine : integer;
  52.   end;
  53.  
  54. const
  55.   Positions : array[Box..Play] of PositionRec = (
  56.    { Box }       (X : LeftX;  Y : LeftY;
  57.                   Color : Black; Background : LightGray),
  58.    { Title }     (X : 24; Y : 4;
  59.                   Color : LightGreen; Background : Black),
  60.    { PlayHands } (X : 4; Y : 8;
  61.                   Color : Yellow; Background : Black),
  62.    { ShowHands } (X : 4; Y : 10;
  63.                   Color : Yellow; Background : Black),
  64.    { Cheat1 }    (X : 4; Y : 12;
  65.                   Color : Yellow; Background : Black),
  66.    { Cheat2 }    (X : 4; Y : 13;
  67.                   Color : Yellow; Background : Black),
  68.    { NorthHand } (X : 35;  Y : 8;                        { PlayHands.y }
  69.                   Color : LightGray; Background : Black),
  70.    { EastHand }  (X : 43;  Y : 8;                        { PlayHands.y }
  71.                   Color : LightGray; Background : Black),
  72.    { SouthHand } (X : 50;  Y : 8;                        { PlayHands.y }
  73.                   Color : LightGray; Background : Black),
  74.    { WestHand }  (X : 58;  Y : 8;                        { PlayHands.y }
  75.                   Color : LightGray; Background : Black),
  76.    { Showing }   (X : 35;  Y : 10;                        { ShowHands.y }
  77.                   Color : LightGray; Background : Black),
  78.    { Cheating }  (X : 35;  Y : 13;                        { Cheat2.y }
  79.                   Color : LightGray; Background : Black),
  80.    { Play }      (X : 57; Y : 16;
  81.                   Color : LightGray; Background : Black));
  82.  
  83. var
  84.   Item : ScreenPositions;
  85.  
  86. var
  87.   LastCursor : CursorRec;
  88.  
  89. { ================= begin cursor control module ================== }
  90. procedure Cursor(On : boolean; var LastCursor : CursorRec);
  91.  
  92. procedure SetCursor(StartLine, EndLine : integer);
  93. type
  94.   Registers = record
  95.               ax, bx, cx, dx, bp, si, di, ds, es, flags: integer;
  96.             end;
  97. var
  98.   RegPack : Registers;
  99.   CXRegArray : array[1..2] of byte;
  100.   CXReg      : integer absolute CXRegArray;
  101. begin
  102.   CXREgArray[2] := Lo(StartLine);
  103.   CXREgArray[1] := Lo(EndLine);
  104.   with RegPack do
  105.   begin
  106.     ax := $0100;  { cursor interrupt }
  107.     bx := $0;     { page #           }
  108.     cx := CXReg;
  109.     intr($10, RegPack);
  110.   end;
  111. end; { SetCursor }
  112.  
  113. procedure GetCursor(var StartLine, EndLine : integer);
  114. type
  115.   Registers = record
  116.               ax, bx, cx, dx, bp, si, di, ds, es, flags: integer;
  117.             end;
  118. var
  119.   RegPack : Registers;
  120. begin
  121.   with RegPack do
  122.   begin
  123.     ax := $0300;  { cursor interrupt }
  124.     bx := $0;     { page #           }
  125.     intr($10, RegPack);
  126.   end;
  127.   StartLine := Hi(RegPack.cx);
  128.   EndLine := Lo(RegPack.cx);
  129. end; { GetCursor }
  130.  
  131. begin { Cursor }
  132.   if On then
  133.   begin
  134.     with LastCursor do
  135.       SetCursor(StartLine, EndLine)
  136.   end
  137.   else
  138.   begin
  139.     with LastCursor do                    { save original cursor type }
  140.       GetCursor(StartLine, Endline);
  141.     SetCursor(32, 0);
  142.   end;
  143. end; { Cursor }
  144. { ================= Cursor control module ================== }
  145.  
  146. procedure RestoreScreen;
  147. begin
  148.   LowVideo;
  149.   Window(1, 1, 80, 25);
  150.   GoToXY(1, 24);
  151.   Cursor(true, LastCursor);
  152. end; { RestoreScreen }
  153.  
  154. procedure Abort;
  155. begin
  156.   RestoreScreen;
  157.   Halt;
  158. end; { Abort }
  159.  
  160. procedure DrawBox;
  161. var
  162.   i : integer;
  163.  
  164. procedure DrawHelpLine;
  165.  
  166. procedure WriteHelp(s : MaxString; No : byte);
  167. begin
  168.   TextBackground(Positions[Box].Color);
  169.   TextColor(Positions[Box].Background);
  170.   Write(Copy(s, 1, No));
  171.   Delete(s, 1, No);
  172.   TextBackground(Positions[Box].Background);
  173.   TextColor(Positions[Box].Color);
  174.   Write(s);
  175. end; { WriteHelp }
  176.  
  177. begin
  178.   GoToXY(LeftX, RightY + 1);                       { help line }
  179.   Write(' ':RightX - LeftX + 1);
  180.   GoToXY(LeftX + 3, RightY + 1);
  181.   WriteHelp(^[ + '-', 1);
  182.   WriteHelp(^Z + '-Move blinking arrows  ', 1);
  183.   WriteHelp('SPACE-Selects  ', 5);
  184.   WriteHelp('Play-Begins game', 4);
  185. end; { DrawHelpLine }
  186.  
  187. begin
  188.   NormVideo;
  189.   ClrScr;
  190.   TextColor(Positions[Box].Color);
  191.   TextBackground(Positions[Box].Background);
  192.   GoToXY(LeftX, LeftY);
  193.   Write('╓');                                  { top line }
  194.   for i := LeftX + 1 to RightX - 1 do
  195.     Write('─');
  196.   Write('╖');
  197.   for i := LeftY + 1 to RightY - 1 do          { sides }
  198.   begin
  199.     GoToXY(LeftX, i);
  200.     Write('║');
  201.     GoToXY(RightX, i);
  202.     Write('║');
  203.   end;
  204.   GoToXY(LeftX, RightY);                       { bottom line }
  205.   Write('╙');
  206.   for i := LeftX + 1 to RightX - 1 do
  207.     Write('─');
  208.   Write('╜');
  209.   DrawHelpLine;
  210. end; { DrawBox }
  211.  
  212. procedure DisPlayText;
  213.  
  214. procedure Paint(Item : PositionRec; s : MaxString);
  215. begin
  216.   with Item do
  217.   begin
  218.     GoToXY(x, y);
  219.     TextColor(Color);
  220.     TextBackground(Background);
  221.     Write(s);
  222.   end;
  223. end; { Paint }
  224.  
  225. begin { DisPlayText }
  226.   Window(LeftX, LeftY, RightX, RightY + 2);
  227.   Paint(Positions[Title], 'T U R B O - B R I D G E');
  228.   Paint(Positions[PlayHands], 'Select hands you wish to Play:');
  229.   Paint(Positions[ShowHands], 'Display all 4 hands?');
  230.   Paint(Positions[Cheat1], 'Should the program cheat');
  231.   Paint(Positions[Cheat2], 'and look at your cards?');
  232.   TextColor(Positions[Box].Background);                   { inverse of border }
  233.   TextBackground(Positions[Box].Color);
  234.   GoToXY(Positions[Play].X - 1, Positions[Play].Y - 1);
  235.   Write('┌──────┐');
  236.   GoToXY(Positions[Play].X - 1, Positions[Play].Y);
  237.   Write('│      │');
  238.   GoToXY(Positions[Play].X - 1, Positions[Play].Y + 1);
  239.   Write('└──────┘');
  240. end; { DisplayText }
  241.  
  242. procedure ShowSetting(Item : PositionRec;
  243.                          s : MaxString;
  244.                        On,
  245.                   Selected : boolean);
  246. var
  247.   c, b : byte;
  248. begin
  249.   with Item do
  250.   begin
  251.     GoToXY(x, y);
  252.     if On then            { inverse video }
  253.     begin
  254.       b := Color;
  255.       c := Background;
  256.     end
  257.     else                  { normal video }
  258.     begin
  259.       b := Background;
  260.       c := Color;
  261.     end;
  262.   end;
  263.   TextColor(c);
  264.   TextBackground(b);
  265.   if Selected then
  266.   begin
  267.     TextColor(c + blink);
  268.     Write(^P);
  269.     TextColor(c);
  270.   end
  271.   else
  272.     Write(' ');
  273.   Write(s);
  274.   if s = 'NO' then
  275.   begin
  276.     Write('  ');
  277.     GoToXY(whereX - 2, whereY);
  278.   end;
  279.   if Selected then
  280.   begin
  281.     TextColor(c + blink);
  282.     Write(^Q);
  283.   end
  284.   else
  285.     Write(' ');
  286. end; { ShowSetting }
  287.  
  288. procedure ShowDefaults(Position : ScreenPositions;
  289.                        Defaults : DefaultRec;
  290.                        Selected : boolean);
  291.  
  292. function ToggleString(On : boolean) : MaxString;
  293. begin
  294.   if On then ToggleString := 'YES'
  295.   else ToggleString := 'NO';
  296. end; { ToggleString }
  297.  
  298. begin
  299.   with Defaults do
  300.   begin
  301.     case Position of
  302.       NorthHand : ShowSetting(Positions[NorthHand], 'NORTH',
  303.                                   Computer[North], Selected);
  304.       EastHand  : ShowSetting(Positions[EastHand], 'EAST',
  305.                                   Computer[East], Selected);
  306.       SouthHand : ShowSetting(Positions[SouthHand], 'SOUTH',
  307.                                   Computer[South], Selected);
  308.       WestHand  : ShowSetting(Positions[WestHand], 'WEST',
  309.                                   Computer[West], Selected);
  310.       Showing   : ShowSetting(Positions[Showing], ToggleString(PrintAll),
  311.                                   false, Selected);
  312.       Cheating  : ShowSetting(Positions[Cheating], ToggleString(Cheat),
  313.                                   false, Selected);
  314.       Play      : ShowSetting(Positions[Succ(Cheating)], 'Play',
  315.                                   OK, Selected);
  316.     end; { case }
  317.   end; { with }
  318. end; { ShowDefaults }
  319.  
  320. procedure SelectDefaults;
  321. var
  322.   Curr, Last : ScreenPositions;
  323.  
  324. procedure GetCommand(var Curr : ScreenPositions);
  325. var
  326.   ch : char;
  327.  
  328. procedure Toggle(Curr : ScreenPositions; var Defaults : DefaultRec);
  329. begin
  330.   with Defaults do
  331.     case Curr of
  332.       NorthHand..WestHand : begin
  333.                               Computer[Ord(Curr) - Ord(NorthHand)] :=
  334.                                  not Computer[Ord(Curr)- Ord(NorthHand)];
  335.                             end;
  336.       Showing : PrintAll := not PrintAll;
  337.       Cheating : Cheat := not Cheat;
  338.       Play : OK := true;
  339.     end; { case }
  340.   ShowDefaults(Curr, Defaults, true);
  341. end; { Toggle }
  342.  
  343. begin { GetCommand }
  344.   Read(KBD, ch);
  345.   case UpCase(ch) of
  346.     #13, #32 : Toggle(Curr, Defaults);                 { toggle current }
  347.     'N'      : case Curr of                            { north, no }
  348.                  NorthHand..WestHand : begin
  349.                                          Curr := NorthHand;
  350.                                          Toggle(Curr, Defaults);
  351.                                        end;
  352.                  Showing             : if Defaults.PrintAll then
  353.                                         begin
  354.                                           Curr := Showing;
  355.                                           Toggle(Curr, Defaults);
  356.                                          end;
  357.                  Cheating            : if Defaults.Cheat then
  358.                                        begin
  359.                                          Curr := Cheating;
  360.                                          Toggle(Curr, Defaults);
  361.                                        end;
  362.                end; { case }
  363.     'Y'      : case Curr of
  364.                  Showing             : if not Defaults.PrintAll then
  365.                                         begin
  366.                                           Curr := Showing;
  367.                                           Toggle(Curr, Defaults);
  368.                                          end;
  369.                  Cheating            : if not Defaults.Cheat then
  370.                                        begin
  371.                                          Curr := Cheating;
  372.                                          Toggle(Curr, Defaults);
  373.                                        end;
  374.                end; { case }
  375.     'E'      : if Curr in [NorthHand..WestHand] then     { east }
  376.                begin
  377.                  Curr := EastHand;
  378.                  Toggle(Curr, Defaults);
  379.                end;
  380.     'S'      : if Curr in [NorthHand..WestHand] then     { south }
  381.                begin
  382.                  Curr := SouthHand;
  383.                  Toggle(Curr, Defaults);
  384.                end;
  385.     'W'      : if Curr in [NorthHand..WestHand] then     { west }
  386.                begin
  387.                  Curr := WestHand;
  388.                  Toggle(Curr, Defaults);
  389.                end;
  390.     'P'      : begin                                   { Play }
  391.                  Curr := Play;
  392.                  Toggle(Curr, Defaults);
  393.                end;
  394.     ^C, 'Q'  : Abort;                                  { abort }
  395.     ^[       : begin                     { ESC or function/arrow key }
  396.                  if not KeyPressed then Abort
  397.                  else
  398.                  begin
  399.                    Read(KBD, ch);
  400.                    case ch of
  401.                      'K' : Curr := Pred(Curr);  { left arrow }
  402.                      'M' : Curr := Succ(Curr);  { right arrow}
  403.                      'H' : case Curr of         { up arrow }
  404.                              NorthHand..WestHand : Curr := Play;
  405.                              Showing             : Curr := NorthHand;
  406.                              Cheating            : Curr := Showing;
  407.                              Play                : Curr := Cheating;
  408.                            end;
  409.                      'P' : case Curr of           { down arrow}
  410.                              NorthHand..WestHand : Curr := Showing;
  411.                              Showing             : Curr := Cheating;
  412.                              Cheating            : Curr := Play;
  413.                              Play                : Curr := NorthHand;
  414.                            end;
  415.                    end; { case }
  416.                  end;
  417.                end;
  418.   end; { case }
  419.   if Curr > Play then Curr := NorthHand
  420.   else
  421.     if Curr < NorthHand then Curr := Play;
  422. end; { GetCommand }
  423.  
  424. begin { SelectDefaults }
  425.   Last := NorthHand;
  426.   Curr := Play;
  427.   repeat
  428.     if Curr <> Last then
  429.     begin
  430.       ShowDefaults(Last, Defaults, false);
  431.       ShowDefaults(Curr, Defaults, true);
  432.       Last := Curr;
  433.     end;
  434.     GetCommand(Curr);
  435.   until Defaults.Ok = true;
  436. end; { SelectDefaults }
  437.  
  438. begin { OpeningScreen }
  439.   FlushBuffer;
  440.   Cursor(false, LastCursor);
  441.   Defaults.Ok := false;
  442.   ShowTricks := true;
  443.   DrawBox;                                { paint screen }
  444.   DisplayText;
  445.   for Item := NorthHand to Cheating do
  446.     ShowDefaults(Item, Defaults, false);  { Display toggle switches }
  447.   SelectDefaults;
  448.   Computer[North] := not Defaults.Computer[North];
  449.   Computer[South] := not Defaults.Computer[South];
  450.   Computer[East]  := not Defaults.Computer[East];
  451.   Computer[West]  := not Defaults.Computer[West];
  452.   PrintAll := Defaults.PrintAll;
  453.   Cheat := Defaults.Cheat;
  454.   RestoreScreen;                          { restore screen, do not abort }
  455. end; { GetDefaults }
  456.  
  457. { end DEFAULTS.BR }