Changeset 14


Ignore:
Timestamp:
Oct 5, 2019, 11:42:10 AM (5 years ago)
Author:
chronos
Message:
  • Fixed: Correct placement of numbers inside cells.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Languages/Game2048.cs.po

    r13 r14  
    134134msgstr "Konec hry!"
    135135
     136#: ugame.sscore
     137msgid "Score"
     138msgstr "Skóre"
     139
     140#: ugame.stopscore
     141msgid "Top score"
     142msgstr "Nejvyšší skóre"
     143
    136144#: ugame.swincaption
    137145msgid "Win"
  • trunk/Languages/Game2048.po

    r13 r14  
    124124msgstr ""
    125125
     126#: ugame.sscore
     127msgid "Score"
     128msgstr ""
     129
     130#: ugame.stopscore
     131msgid "Top score"
     132msgstr ""
     133
    126134#: ugame.swincaption
    127135msgid "Win"
  • trunk/UGame.pas

    r12 r14  
    4242    procedure DoChange;
    4343    procedure ClearMerged;
     44    procedure RenderCell(Canvas: TCanvas; Cell: TCell; CellRect: TRect);
    4445  public
    4546    Cells: array of array of TCell;
     
    7980  SWinCaption = 'Win';
    8081  SWinMessage = 'You won! Do you want to continue to play?';
    81 
     82  SScore = 'Score';
     83  STopScore = 'Top score';
    8284
    8385implementation
     
    248250  Frame: TRect;
    249251  CellRect: TRect;
    250   TextSize: TSize;
    251252  TopBarHeight: Integer;
    252253  CellMargin: Integer;
     
    258259  Canvas.FillRect(0, 0, Canvas.Width, Canvas.Height);
    259260
    260   ValueStr := 'Score: ' + IntToStr(Score);
     261  ValueStr := SScore + ': ' + IntToStr(Score);
    261262  Canvas.Font.Color := clWhite;
    262263  Canvas.Font.Height := Trunc(TopBarHeight * 0.7);
    263264  Canvas.TextOut(ScaleY(16, 96), (TopBarHeight - Canvas.TextHeight(ValueStr)) div 2, ValueStr);
    264265
    265   ValueStr := 'Top score: ' + IntToStr(TopScore);
     266  ValueStr := STopScore + ': ' + IntToStr(TopScore);
    266267  Canvas.Font.Color := clWhite;
    267268  Canvas.Font.Height := Trunc(TopBarHeight * 0.7);
     
    279280    Frame.Top + Frame.Height div 2 + (Size.Y * CellSize.Y) div 2);
    280281
    281   {  for Y := 0 to Size.Y - 1 do begin
    282     Canvas.MoveTo(Frame.Left, Frame.Top + Y * CellSize.Y);
    283     Canvas.LineTo(Frame.Left + Size.X * CellSize.X, Frame.Top + Y * CellSize.Y);
    284   end;
    285   for X := 0 to Size.X - 1 do begin
    286     Canvas.MoveTo(Frame.Left + X * CellSize.X, Frame.Top);
    287     Canvas.LineTo(Frame.Left + X * CellSize.X, Frame.Top + Size.Y * CellSize.Y);
    288   end;
    289   }
    290282  Canvas.Brush.Style := bsSolid;
    291283  Canvas.Brush.Color := clGray;
     
    293285
    294286  Canvas.Font.Color := clBlack;
     287
    295288  // Draw static cells
    296289  for Y := 0 to Size.Y - 1 do
     
    303296        Frame.Top + Y * CellSize.Y + CellMargin,
    304297        CellSize.X - 2 * CellMargin, CellSize.Y - 2 * CellMargin);
    305       Canvas.FillRect(CellRect);
    306       if (Cells[Y, X].Value <> 0) and not Cells[Y, X].Moving then begin
    307         ValueStr := IntToStr(Cells[Y, X].Value);
    308         Canvas.Brush.Style := bsClear;
    309         Canvas.Font.Height := Trunc(CellSize.Y * 0.7); // * (CellSize.X * 0.7) / Canvas.TextWidth(ValueStr));
    310         TextSize := Canvas.TextExtent(ValueStr);
    311         if TextSize.Width > CellSize.X then
    312           Canvas.Font.Height := Trunc(Canvas.Font.Height / TextSize.Width * CellSize.X);
    313         TextSize := Canvas.TextExtent(ValueStr);
    314         Canvas.TextOut(CellRect.Left + CellSize.X div 2 -
    315           TextSize.Width div 2,
    316           CellRect.Top + CellSize.Y div 2 - TextSize.Height div 2, ValueStr);
    317       end;
     298      RenderCell(Canvas, Cells[Y, X], CellRect);
    318299    end;
    319300
     
    328309        Frame.Top + Y * CellSize.Y + Trunc(Cells[Y, X].Shift.Y / 100 * CellSize.Y + CellMargin),
    329310        CellSize.X - 2 * CellMargin, CellSize.Y - 2 * CellMargin);
    330       Canvas.FillRect(CellRect);
    331       if Cells[Y, X].Value <> 0 then begin
    332         ValueStr := IntToStr(Cells[Y, X].Value);
    333         Canvas.Brush.Style := bsClear;
    334         Canvas.Font.Height := Trunc(CellSize.Y * 0.7); // * (CellSize.X * 0.7) / Canvas.TextWidth(ValueStr));
    335         TextSize := Canvas.TextExtent(ValueStr);
    336         if TextSize.Width > CellRect.Width then
    337           Canvas.Font.Height := Trunc(Canvas.Font.Height / TextSize.Width * CellSize.X);
    338         TextSize := Canvas.TextExtent(ValueStr);
    339         Canvas.TextOut(CellRect.Left + CellRect.Width div 2 -
    340           TextSize.Width div 2,
    341           CellRect.Top + CellRect.Height div 2 - TextSize.Height div 2, ValueStr);
    342       end;
    343     end;
    344 end;
     311      RenderCell(Canvas, Cells[Y, X], CellRect);
     312    end;
     313end;
     314
     315procedure TGame.RenderCell(Canvas: TCanvas; Cell: TCell; CellRect: TRect);
     316var
     317  ValueStr: string;
     318  TextSize: TSize;
     319begin
     320  Canvas.FillRect(CellRect);
     321  if Cell.Value <> 0 then begin
     322    ValueStr := IntToStr(Cell.Value);
     323    Canvas.Brush.Style := bsClear;
     324    Canvas.Font.Height := Trunc(CellRect.Height * 0.7);
     325    TextSize := Canvas.TextExtent(ValueStr);
     326    if TextSize.Width > CellRect.Width then
     327      Canvas.Font.Height := Trunc(Canvas.Font.Height / TextSize.Width * CellRect.Width);
     328    TextSize := Canvas.TextExtent(ValueStr);
     329    Canvas.TextOut(CellRect.Left + CellRect.Width div 2 - TextSize.Width div 2,
     330      CellRect.Top + CellRect.Height div 2 - TextSize.Height div 2, ValueStr);
     331  end;
     332end;
     333
    345334
    346335function TGame.MoveAll(Direction: TDirection): Integer;
Note: See TracChangeset for help on using the changeset viewer.