Changeset 27 for trunk


Ignore:
Timestamp:
Oct 5, 2019, 10:55:00 PM (5 years ago)
Author:
chronos
Message:
  • Fixed: Update previous board state for undo only if board is really moved.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r21 r27  
    7676    procedure New;
    7777    procedure Render(Canvas: TCanvas; CanvasSize: TPoint);
    78     function MoveAll(Direction: TDirection): Integer;
     78    procedure MoveAll(Direction: TDirection);
    7979    procedure MoveTile(SourceTile, TargetTile: TTile);
    8080    function IsValidPos(Pos: TPoint): Boolean;
     
    472472end;
    473473
    474 function TGame.MoveAll(Direction: TDirection): Integer;
     474procedure TGame.MoveAll(Direction: TDirection);
    475475var
    476476  StartPoint: TPoint;
     
    481481  PNew: TPoint;
    482482  PI: TPoint;
    483   MovedCount: Integer;
    484483  X, Y: Integer;
    485484  I: Integer;
     
    490489  HighestValue: Integer;
    491490begin
     491  if not CanMoveDirection(Direction) then Exit;
    492492  FMoving := True;
    493493  HighestValue := Board.GetHighestTileValue;
     
    521521    end;
    522522  end;
    523   MovedCount := 0;
    524523  Board.ClearMerged;
    525524  for I := 0 to Max(Board.Size.X, Board.Size.Y) - 1 do begin
     
    545544              Board.Tiles[P.Y, P.X].NewValue := 0;
    546545              Board.Tiles[P.Y, P.X].Merged := False;
    547               Inc(MovedCount);
    548546            end else
    549547            if (not Board.Tiles[P.Y, P.X].Merged) and (not Board.Tiles[PNew.Y, PNew.X].Merged) and
     
    554552              Board.Tiles[P.Y, P.X].NewValue := 0;
    555553              Board.Tiles[P.Y, P.X].Merged := False;
    556               Inc(MovedCount);
    557554              Score := Score + Board.Tiles[PNew.Y, PNew.X].NewValue;
    558555            end;
     
    596593    DoChange;
    597594  end;
    598   Result := MovedCount;
    599595
    600596  // Update state after move
    601   if MovedCount > 0 then FillRandomTile;
     597  FillRandomTile;
    602598  if not CanMove and (Board.GetEmptyTilesCount = 0) then
    603599    GameOver;
Note: See TracChangeset for help on using the changeset viewer.