Changeset 28 for trunk/UGame.pas


Ignore:
Timestamp:
Oct 5, 2019, 11:29:11 PM (5 years ago)
Author:
chronos
Message:
  • Added: Help windows with instructions how to play.
  • Added: With 10% chance create new random tile with value 4 instead of 2.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r27 r28  
    6464    procedure GameOver;
    6565    procedure Win;
    66     function FillRandomTile: Integer;
     66    function FillRandomTile(Value4Change: Double = 0.1): Integer;
    6767  public
    6868    Board: TBoard;
     
    7070    AnimationDuration: Integer;
    7171    WinScore: Integer;
     72    UndoEnabled: Boolean;
    7273    function CanUndo: Boolean;
    7374    procedure Undo;
     
    268269end;
    269270
    270 function TGame.FillRandomTile: Integer;
     271function TGame.FillRandomTile(Value4Change: Double = 0.1): Integer;
    271272var
    272273  EmptyTiles: TTiles;
     274  NewValue: Integer;
    273275begin
    274276  Result := 0;
     
    276278  Board.GetEmptyTiles(EmptyTiles);
    277279  if EmptyTiles.Count > 0 then begin
    278     EmptyTiles[Random(EmptyTiles.Count)].Value := 2;
     280    if Random < Value4Change then NewValue := 4 else NewValue := 2;
     281    EmptyTiles[Random(EmptyTiles.Count)].Value := NewValue;
    279282    Result := 1;
    280283  end;
     
    304307  Score := 0;
    305308  Running := True;
    306   for I := 0 to 1 do FillRandomTile;
     309  for I := 0 to 1 do FillRandomTile(0);
    307310  DoChange;
    308311end;
     
    399402function TGame.CanUndo: Boolean;
    400403begin
    401   Result := FCanUndo;
     404  Result := UndoEnabled and FCanUndo;
    402405end;
    403406
    404407procedure TGame.Undo;
    405408begin
    406   if CanUndo then begin
     409  if UndoEnabled and CanUndo then begin
    407410    Board.Assign(FBoardUndo);
    408411    FCanUndo := False;
     
    629632    WriteBool('GameRunning', FRunning);
    630633    WriteBool('CanUndo', FCanUndo);
     634    WriteBool('UndoEnabled', UndoEnabled);
    631635  finally
    632636    Free;
     
    646650    FRunning := ReadBoolWithDefault('GameRunning', False);
    647651    FCanUndo := ReadBoolWithDefault('CanUndo', False);
     652    UndoEnabled := ReadBoolWithDefault('UndoEnabled', True);
    648653  finally
    649654    Free;
Note: See TracChangeset for help on using the changeset viewer.