Changeset 28 for trunk/UGame.pas
- Timestamp:
- Oct 5, 2019, 11:29:11 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGame.pas
r27 r28 64 64 procedure GameOver; 65 65 procedure Win; 66 function FillRandomTile : Integer;66 function FillRandomTile(Value4Change: Double = 0.1): Integer; 67 67 public 68 68 Board: TBoard; … … 70 70 AnimationDuration: Integer; 71 71 WinScore: Integer; 72 UndoEnabled: Boolean; 72 73 function CanUndo: Boolean; 73 74 procedure Undo; … … 268 269 end; 269 270 270 function TGame.FillRandomTile : Integer;271 function TGame.FillRandomTile(Value4Change: Double = 0.1): Integer; 271 272 var 272 273 EmptyTiles: TTiles; 274 NewValue: Integer; 273 275 begin 274 276 Result := 0; … … 276 278 Board.GetEmptyTiles(EmptyTiles); 277 279 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; 279 282 Result := 1; 280 283 end; … … 304 307 Score := 0; 305 308 Running := True; 306 for I := 0 to 1 do FillRandomTile ;309 for I := 0 to 1 do FillRandomTile(0); 307 310 DoChange; 308 311 end; … … 399 402 function TGame.CanUndo: Boolean; 400 403 begin 401 Result := FCanUndo;404 Result := UndoEnabled and FCanUndo; 402 405 end; 403 406 404 407 procedure TGame.Undo; 405 408 begin 406 if CanUndo then begin409 if UndoEnabled and CanUndo then begin 407 410 Board.Assign(FBoardUndo); 408 411 FCanUndo := False; … … 629 632 WriteBool('GameRunning', FRunning); 630 633 WriteBool('CanUndo', FCanUndo); 634 WriteBool('UndoEnabled', UndoEnabled); 631 635 finally 632 636 Free; … … 646 650 FRunning := ReadBoolWithDefault('GameRunning', False); 647 651 FCanUndo := ReadBoolWithDefault('CanUndo', False); 652 UndoEnabled := ReadBoolWithDefault('UndoEnabled', True); 648 653 finally 649 654 Free;
Note:
See TracChangeset
for help on using the changeset viewer.