Changeset 3 for trunk


Ignore:
Timestamp:
Dec 6, 2018, 11:39:27 PM (6 years ago)
Author:
chronos
Message:
  • Added: Draw cells with background color.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r1 r3  
    3030    FRunning: Boolean;
    3131    FSize: TPoint;
     32    function GetCellColor(Value: Integer): TColor;
    3233    procedure SetSize(AValue: TPoint);
    3334    procedure GetEmptyCells(EmptyCells: TCells);
     
    4748    procedure MoveCell(SourceCell, TargetCell: TCell);
    4849    function IsValidPos(Pos: TPoint): Boolean;
     50    constructor Create;
    4951    property Size: TPoint read FSize write SetSize;
    5052    property Running: Boolean read FRunning write FRunning;
     
    204206  Canvas.Font.Height := Trunc(CellSize.Y * 0.7);
    205207  for Y := 0 to Size.Y - 1 do
    206     for X := 0 to Size.X - 1 do
    207     if Cells[Y, X].Value <> 0 then begin
    208       ValueStr := IntToStr(Cells[Y, X].Value);
    209       Canvas.TextOut(X * CellSize.X + CellSize.X div 2 -
    210         Canvas.TextWidth(ValueStr) div 2, Y * CellSize.Y, ValueStr);
     208    for X := 0 to Size.X - 1 do begin
     209      Canvas.Brush.Color := GetCellColor(Cells[Y, X].Value);
     210      Canvas.Brush.Style := bsSolid;
     211      Canvas.FillRect(Rect(X * CellSize.X, Y * CellSize.Y,
     212        (X + 1) * CellSize.X, (Y + 1) * CellSize.Y));
     213      if Cells[Y, X].Value <> 0 then begin
     214        ValueStr := IntToStr(Cells[Y, X].Value);
     215        Canvas.TextOut(X * CellSize.X + CellSize.X div 2 -
     216          Canvas.TextWidth(ValueStr) div 2, Y * CellSize.Y, ValueStr);
     217      end;
    211218    end;
    212219
     
    305312end;
    306313
     314constructor TGame.Create;
     315begin
     316end;
     317
     318function TGame.GetCellColor(Value: Integer): TColor;
     319begin
     320  case Value of
     321    0: Result := $f2f6f9;
     322    2: Result := $dae4ee;
     323    4: Result := $c8e0ed;
     324    8: Result := $79b1f2;
     325    16: Result := $6395f5;
     326    32: Result := $5f7cf6;
     327    64: Result := $3b5ef6;
     328    128: Result := $72cfed;
     329    256: Result := $61cced;
     330    512: Result := $50c8ed;
     331    1024: Result := $3fc5ed;
     332    2048: Result := $2ec2ed;
     333    else Result := $323a3c;
     334  end;
     335end;
     336
    307337end.
    308338
Note: See TracChangeset for help on using the changeset viewer.