home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1993 September / September 93.iso / Archives / Games / Strategy / Puzzle / GameMaster / GM Dev Kit / Rulebook Sources / Chess / ChessDrawing.p < prev    next >
Encoding:
Text File  |  1991-12-05  |  3.8 KB  |  126 lines  |  [TEXT/PJMM]

  1. unit ChessDrawing;
  2.  
  3. { ©1991 [RHS] and Quinn "The Eskimo" }
  4.  
  5. interface
  6.  
  7.     uses
  8.         QuickDrawRules, ChessTypes, DialogSubs, Failure, GraphSubs,{}
  9.         ChessSubs, ChessBoardSubs;
  10.  
  11.     procedure DrawBoard (var game: gameRecord; var globals: globalsRecord);
  12.     procedure BoardUserItem (dlg: WindowPeek; itemNo: integer);
  13.     procedure LineUserItem (dlg: DialogPtr; itemNo: integer);
  14.     procedure MorgueUserItem (dlg: DialogPtr; itemNo: integer);
  15.  
  16. implementation
  17.  
  18.     procedure DrawBoard (var game: gameRecord; var globals: globalsRecord);
  19.         var
  20.             x: boardXNdx;
  21.             y: boardYNdx;
  22.             r: rect;
  23.             where: boardCoord;
  24.             ps: penState;
  25.     begin
  26. { Draw (most of) the vertical lines }
  27.         for x := 0 to kBoardXMax do begin
  28.             MoveTo(game.boardXOrg + x * kCellXPitch, game.boardYOrg);
  29.             LineTo(game.boardXOrg + x * kCellXPitch, game.boardYOrg + kBoardYMax * kCellYPitch + kCellYPitch);
  30.         end; { for }
  31. { Draw (most of) the horizontal lines }
  32.         for y := 0 to kBoardYMax do begin
  33.             MoveTo(game.boardXOrg, y * kCellYPitch + game.boardYOrg);
  34.             LineTo(game.boardXOrg + kBoardXMax * kCellXPitch + kCellXPitch, y * kCellYPitch + game.boardYOrg);
  35.         end; { for }
  36. { Draw the remaining two lines (bottom and right) }
  37.         MoveTo(game.boardXOrg, game.boardYOrg + (kBoardYMax + 1) * kCellYPitch);
  38.         LineTo(game.boardXOrg + (kBoardXMax + 1) * kCellXPitch, game.boardYOrg + (kBoardYMax + 1) * kCellYPitch);
  39.         LineTo(game.boardYOrg + (kBoardYMax + 1) * kCellYPitch, game.boardYOrg);
  40. { Plot the piece icons }
  41.         for x := 0 to kBoardXMax do begin
  42.             where.x := x;
  43.             for y := 0 to kBoardYMax do begin
  44.                 where.y := y;
  45.                 GetRect(game, where, r);
  46.                 PlotIcon(r, globals.icons[game.board[x, y].colour, game.board[x, y].occupant]);
  47.             end; { for }
  48.         end; { for }
  49.         if game.playstate = ps_Pawning then begin
  50.             GetPawningRect(game, r);
  51.             GetPenState(ps);
  52.             PenNormal;
  53.             PenSize(kPawningXBorder, kPawningYBorder);
  54.             FrameRect(r);
  55.             where.y := kPawningY;
  56.             for x := kPawningX to kPawningXMax do begin
  57.                 where.x := x;
  58.                 GetRect(game, where, r);
  59.                 PlotIcon(r, globals.icons[Cwhite, PlayerPiece(game.playertomove, globals.pawnpieces[x])]);
  60.             end; { for }
  61.             SetPenState(ps);
  62.         end; { if }
  63.     end; { DrawBoard }
  64.  
  65.     procedure BoardUserItem (dlg: WindowPeek; itemNo: integer);
  66.         var
  67.             ps: PenState;
  68.             s1, s2: signedByte;
  69.             gameh, globalsh: Handle;
  70.     begin
  71.         GetPenState(ps);
  72.         gameh := Handle(dlg^.refcon);
  73.         s1 := HGetState(gameh);
  74.         HLock(gameh);
  75.         globalsh := Handle(gamePeek(gameh)^^.globals);
  76.         s2 := HGetState(globalsh);
  77.         HLock(globalsh);
  78.         DrawBoard(gamePeek(gameh)^^, globalsPeek(globalsh)^^);
  79.         HSetState(gameh, s1);
  80.         HSetState(globalsh, s2);
  81.         SetPenState(ps);
  82.     end; { BoardUserItem }
  83.  
  84.     procedure LineUserItem (dlg: DialogPtr; itemNo: integer);
  85.         var
  86.             r: Rect;
  87.             ps: PenState;
  88.     begin
  89.         GetPenState(ps);
  90.         PenPat(QDGlobals^.gray);
  91.         GetDRect(dlg, itemNo, r);
  92.         MoveTo(r.left, r.top);
  93.         LineTo(r.right, r.top);
  94.         SetPenState(ps);
  95.     end; { LineUser }
  96.  
  97.     procedure MorgueUserItem (dlg: DialogPtr; itemNo: integer);
  98.         var
  99.             morguerect, plotrect: Rect;
  100.             player: playerType;
  101.             body: morgueNdx;
  102.     begin
  103.         case itemNo of
  104.             dit_blk_pieces: 
  105.                 player := Pblack;
  106.             dit_wht_pieces: 
  107.                 player := Pwhite;
  108.             otherwise
  109.                 Failure('This is not a known morgue');
  110.         end; { case }
  111.         GetDRect(dlg, itemNo, morguerect);
  112.         plotrect.topleft := morguerect.topleft;
  113.         plotrect.bottom := plotrect.top + kMorgueYSize;
  114.         plotrect.right := plotrect.left + kMorgueXSize;
  115.         for body := 1 to kMorgueMax do begin
  116.             PlotSICN(plotrect, gamePeek(WindowPeek(dlg)^.refcon)^^.globals^^.deadicons, ord(gamePeek(WindowPeek(dlg)^.refcon)^^.deaths[player][body]));
  117.             if body = (kMorgueXMax + 1) then begin
  118.                 OffsetRect(plotrect, -kMorgueXMax * kMorgueXPitch, kMorgueYPitch);
  119.             end
  120.             else begin
  121.                 OffsetRect(plotrect, kMorgueXPitch, 0);
  122.             end; { if }
  123.         end; { for }
  124.     end; { MorgueUserItem }
  125.  
  126. end. { ChessDrawing }