Changeset 107 for trunk/Game.pas


Ignore:
Timestamp:
Dec 9, 2024, 10:39:50 PM (12 days ago)
Author:
chronos
Message:
  • Fixed: Use the same initial board after game restart.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Game.pas

    r106 r107  
    6363  public
    6464    Board: TBoard;
     65    InitialBoard: TBoard;
    6566    TopScore: Integer;
    6667    AnimationDuration: Integer;
     
    7879    function CanMove: Boolean;
    7980    procedure Assign(Source: TGame);
     81    procedure Reset;
    8082    procedure New;
     83    procedure Restart;
    8184    procedure Render(Canvas: TCanvas; CanvasSize: TPoint);
    8285    procedure MoveAll(Direction: TMoveDirection; Animation: Boolean);
     
    310313end;
    311314
    312 procedure TGame.New;
    313 var
    314   I: Integer;
    315   Tile: TTile;
     315procedure TGame.Reset;
    316316const
    317317  Difficulty = 0.7;
     
    323323  Running := True;
    324324  History.Clear;
    325 
     325end;
     326
     327procedure TGame.New;
     328var
     329  I: Integer;
     330  Tile: TTile;
     331begin
     332  Reset;
    326333
    327334  if RecordHistory then begin
     
    351358      FillUnmergeableRandomTile;
    352359  end;
     360  InitialBoard.Assign(Board);
     361  AnimateTiles;
     362  DoChange;
     363  DoPaint;
     364end;
     365
     366procedure TGame.Restart;
     367begin
     368  Reset;
     369  Board.Assign(InitialBoard);
    353370  AnimateTiles;
    354371  DoChange;
     
    10381055    FBoardUndo.SaveToRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\BoardUndo'));
    10391056    Board.SaveToRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\Board'));
     1057    InitialBoard.SaveToRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\InitialBoard'));
    10401058    History.SaveToRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\History'));
    10411059  finally
     
    10651083    FBoardUndo.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\BoardUndo'));
    10661084    Board.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\Board'));
     1085    InitialBoard.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\InitialBoard'));
    10671086    History.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\History'));
    10681087  finally
     
    10791098  WinTileValue := 11; // 2^11 = 2048
    10801099  Board := TBoard.Create;
     1100  InitialBoard := TBoard.Create;
    10811101  FBoardUndo := TBoard.Create;
    10821102  History := THistory.Create;
     
    10891109  FreeAndNil(FBoardUndo);
    10901110  FreeAndNil(Board);
     1111  FreeAndNil(InitialBoard);
    10911112  inherited;
    10921113end;
Note: See TracChangeset for help on using the changeset viewer.