Changeset 33


Ignore:
Timestamp:
Oct 13, 2019, 2:17:02 AM (5 years ago)
Author:
chronos
Message:
  • Modified: Fixed tiles move animation.
  • Fixed: Missing game over handler.
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormSettings.lfm

    r19 r33  
    2525    Top = 16
    2626    Width = 240
    27     Max = 100
     27    Max = 1000
    2828    Position = 0
    2929    Anchors = [akTop, akLeft, akRight]
  • trunk/UCore.pas

    r31 r33  
    8080  Game.OnChange := GameChange;
    8181  Game.OnWin := GameWin;
     82  Game.OnGameOver := GameOver;
    8283  LoadConfig;
    8384end;
  • trunk/UGame.pas

    r32 r33  
    103103    procedure SetScore(AValue: Integer);
    104104    procedure DoChange;
    105     procedure RenderTile(Canvas: TCanvas; Tile: TTile; TileRect: TRect);
     105    procedure RenderTile(Canvas: TCanvas; Tile: TTile; TileRect: TRect; WithText: Boolean);
    106106    procedure GameOver;
    107107    procedure Win;
     
    608608        Frame.Top + Y * TileSize.Y + TileMargin,
    609609        TileSize.X - 2 * TileMargin, TileSize.Y - 2 * TileMargin);
    610       RenderTile(Canvas, Board.Tiles[Y, X], TileRect);
     610      RenderTile(Canvas, Board.Tiles[Y, X], TileRect, not Board.Tiles[Y, X].Moving);
    611611    end;
    612612
     
    621621        Frame.Top + Y * TileSize.Y + Trunc(Board.Tiles[Y, X].Shift.Y / 100 * TileSize.Y + TileMargin),
    622622        TileSize.X - 2 * TileMargin, TileSize.Y - 2 * TileMargin);
    623       RenderTile(Canvas, Board.Tiles[Y, X], TileRect);
     623      RenderTile(Canvas, Board.Tiles[Y, X], TileRect, True);
    624624    end;
    625625end;
     
    674674end;
    675675
    676 procedure TGame.RenderTile(Canvas: TCanvas; Tile: TTile; TileRect: TRect);
     676procedure TGame.RenderTile(Canvas: TCanvas; Tile: TTile; TileRect: TRect; WithText: Boolean);
    677677var
    678678  ValueStr: string;
     
    680680begin
    681681  Canvas.FillRect(TileRect);
    682   if Tile.Value <> 0 then begin
     682  if WithText and (Tile.Value <> 0) then begin
    683683    ValueStr := IntToStr(Tile.Value);
    684684    Canvas.Brush.Style := bsClear;
     
    704704    FCanUndo := False;
    705705    FRunning := CanMove;
     706    History.Moves.Delete(History.Moves.Count - 1);
    706707    DoChange;
    707708  end;
     
    784785  Part: Double;
    785786  Area: TArea;
     787  TileMoved: Boolean;
    786788begin
    787789  if Direction = drNone then Exit;
     
    799801      end;
    800802
     803    TileMoved := False;
    801804    P := Area.P1;
    802805    while P.Y <> Area.P2.Y + Area.Increment.Y do begin
     
    812815              Board.Tiles[P.Y, P.X].NewValue := 0;
    813816              Board.Tiles[P.Y, P.X].Merged := False;
     817              TileMoved := True;
    814818            end else
    815819            if (not Board.Tiles[P.Y, P.X].Merged) and (not Board.Tiles[PNew.Y, PNew.X].Merged) and
     
    821825              Board.Tiles[P.Y, P.X].Merged := False;
    822826              Score := Score + Board.Tiles[PNew.Y, PNew.X].NewValue;
     827              TileMoved := True;
    823828            end;
    824829          end;
     
    828833      Inc(P.Y, Area.Increment.Y);
    829834    end;
     835    if not TileMoved then Break;
    830836
    831837    // Animate tiles move
     
    851857    for Y := 0 to Board.Size.Y - 1 do
    852858      for X := 0 to Board.Size.X - 1 do begin
    853         Board.Tiles[Y, X].Shift := Point(0, 0);
    854         Board.Tiles[Y, X].Moving := False;
    855859        Board.Tiles[Y, X].Value := Board.Tiles[Y, X].NewValue;
    856860      end;
    857     DoChange;
    858   end;
     861  end;
     862
     863  // Set final tiles values
     864  for Y := 0 to Board.Size.Y - 1 do
     865    for X := 0 to Board.Size.X - 1 do begin
     866      Board.Tiles[Y, X].Shift := Point(0, 0);
     867      Board.Tiles[Y, X].Moving := False;
     868      Board.Tiles[Y, X].Value := Board.Tiles[Y, X].NewValue;
     869    end;
     870  DoChange;
    859871  FMoving := False;
    860872end;
Note: See TracChangeset for help on using the changeset viewer.