Changeset 34


Ignore:
Timestamp:
Oct 13, 2019, 2:08:10 PM (5 years ago)
Author:
chronos
Message:
  • Fixed: Create new random tile only if board is moved.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r33 r34  
    717717begin
    718718  Result := False;
     719  if Direction = drNone then Exit;
    719720  Area := GetMoveArea(Direction);
    720721  for I := 0 to Max(Board.Size.X, Board.Size.Y) - 1 do begin
     
    878879  NewTile: TTile;
    879880begin
    880   HighestValue := Board.GetHighestTileValue;
    881   MoveAllAnimate(Direction);
    882 
    883   NewTile := FillRandomTile;
    884   HistoryMove := THistoryMove.Create;
    885   HistoryMove.Direction := Direction;
    886   HistoryMove.NewItemPos := NewTile.Index;
    887   HistoryMove.NewItemValue := NewTile.Value;
    888   History.Moves.Add(HistoryMove);
    889 
    890   if not CanMove and (Board.GetEmptyTilesCount = 0) then
    891     GameOver;
    892   if (HighestValue < WinScore) and
    893   (Board.GetHighestTileValue >= WinScore) then Win;
     881  if CanMoveDirection(Direction) then begin
     882    HighestValue := Board.GetHighestTileValue;
     883    MoveAllAnimate(Direction);
     884
     885    NewTile := FillRandomTile;
     886    HistoryMove := THistoryMove.Create;
     887    HistoryMove.Direction := Direction;
     888    HistoryMove.NewItemPos := NewTile.Index;
     889    HistoryMove.NewItemValue := NewTile.Value;
     890    History.Moves.Add(HistoryMove);
     891
     892    if not CanMove and (Board.GetEmptyTilesCount = 0) then
     893      GameOver;
     894    if (HighestValue < WinScore) and
     895    (Board.GetHighestTileValue >= WinScore) then Win;
     896  end;
    894897end;
    895898
Note: See TracChangeset for help on using the changeset viewer.