- Timestamp:
- Oct 13, 2019, 5:14:50 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormMain.lfm
r31 r36 37 37 Action = Core.AComputer 38 38 end 39 object MenuItem 5: TMenuItem39 object MenuItemMovesHistory: TMenuItem 40 40 Action = Core.AHistory 41 41 end -
trunk/Forms/UFormMain.pas
r35 r36 19 19 MenuItem3: TMenuItem; 20 20 MenuItem4: TMenuItem; 21 MenuItem 5: TMenuItem;21 MenuItemMovesHistory: TMenuItem; 22 22 MenuItemTools: TMenuItem; 23 23 MenuItemNew: TMenuItem; … … 88 88 Core.PersistentForm1.Load(Self); 89 89 UpdateInterface; 90 if Core.Game.Board.GetEmptyTilesCount > Core.Game.Board.Size.X * Core.Game.Board.Size.Y - 2 then 91 Core.Game.New; 90 92 end; 91 93 … … 108 110 ToolsVisible: Boolean; 109 111 begin 112 MenuItemMovesHistory.Visible := Core.Game.RecordHistory; 110 113 ToolsVisible := False; 111 114 for I := 0 to MenuItemTools.Count - 1 do -
trunk/Forms/UFormNew.lfm
r31 r36 1 1 object FormNew: TFormNew 2 2 Left = 703 3 Height = 2 124 Top = 7485 Width = 4873 Height = 266 4 Top = 694 5 Width = 501 6 6 Caption = 'New game' 7 ClientHeight = 2 128 ClientWidth = 4877 ClientHeight = 266 8 ClientWidth = 501 9 9 DesignTimePPI = 144 10 10 OnClose = FormClose … … 45 45 Left = 120 46 46 Height = 38 47 Top = 15847 Top = 212 48 48 Width = 113 49 49 Anchors = [akLeft, akBottom] … … 55 55 Left = 280 56 56 Height = 38 57 Top = 15857 Top = 212 58 58 Width = 113 59 59 Anchors = [akLeft, akBottom] … … 70 70 TabOrder = 3 71 71 end 72 object CheckBoxRecordHistory: TCheckBox 73 Left = 16 74 Height = 30 75 Top = 88 76 Width = 210 77 Caption = 'Record moves history' 78 TabOrder = 4 79 end 72 80 end -
trunk/Forms/UFormNew.lrj
r28 r36 4 4 {"hash":77089212,"name":"tformnew.buttoncancel.caption","sourcebytes":[67,97,110,99,101,108],"value":"Cancel"}, 5 5 {"hash":1339,"name":"tformnew.buttonok.caption","sourcebytes":[79,75],"value":"OK"}, 6 {"hash":260260820,"name":"tformnew.checkboxundoenabled.caption","sourcebytes":[85,110,100,111,32,101,110,97,98,108,101,100],"value":"Undo enabled"} 6 {"hash":260260820,"name":"tformnew.checkboxundoenabled.caption","sourcebytes":[85,110,100,111,32,101,110,97,98,108,101,100],"value":"Undo enabled"}, 7 {"hash":146862089,"name":"tformnew.checkboxrecordhistory.caption","sourcebytes":[82,101,99,111,114,100,32,109,111,118,101,115,32,104,105,115,116,111,114,121],"value":"Record moves history"} 7 8 ]} -
trunk/Forms/UFormNew.pas
r31 r36 16 16 ButtonCancel: TButton; 17 17 ButtonOk: TButton; 18 CheckBoxRecordHistory: TCheckBox; 18 19 CheckBoxUndoEnabled: TCheckBox; 19 20 ComboBoxSize: TComboBox; … … 60 61 ComboBoxSize.ItemIndex := Game.Board.Size.X - 2; 61 62 CheckBoxUndoEnabled.Checked := Game.UndoEnabled; 63 CheckBoxRecordHistory.Checked := Game.RecordHistory; 62 64 end; 63 65 … … 66 68 Game.Board.Size := Point(2 + ComboBoxSize.ItemIndex, 2 + ComboBoxSize.ItemIndex); 67 69 Game.UndoEnabled := CheckBoxUndoEnabled.Checked; 70 Game.RecordHistory := CheckBoxRecordHistory.Checked; 68 71 end; 69 72 -
trunk/Forms/UFormSettings.pas
r15 r36 62 62 Core.Translator1.Language := TLanguage(ComboBoxLanguage.Items.Objects[ComboBoxLanguage.ItemIndex]); 63 63 end; 64 Close;64 ModalResult := mrOk; 65 65 end; 66 66 -
trunk/Game2048.lpi
r31 r36 173 173 <RangeChecks Value="True"/> 174 174 <OverflowChecks Value="True"/> 175 <StackChecks Value="True"/>176 175 </Checks> 177 176 <VerifyObjMethodCallValidity Value="True"/> -
trunk/Languages/Game2048.cs.po
r32 r36 126 126 msgstr "Nová hra" 127 127 128 #: tformnew.checkboxrecordhistory.caption 129 msgctxt "tformnew.checkboxrecordhistory.caption" 130 msgid "Record moves history" 131 msgstr "Zaznamenávat historii pohybů" 132 128 133 #: tformnew.checkboxundoenabled.caption 129 134 msgid "Undo enabled" -
trunk/Languages/Game2048.po
r32 r36 116 116 msgstr "" 117 117 118 #: tformnew.checkboxrecordhistory.caption 119 msgctxt "tformnew.checkboxrecordhistory.caption" 120 msgid "Record moves history" 121 msgstr "" 122 118 123 #: tformnew.checkboxundoenabled.caption 119 124 msgid "Undo enabled" -
trunk/Packages/Common/URegistry.pas
r7 r36 133 133 begin 134 134 {$IFDEF Linux} 135 CloseKey;135 //CloseKey; 136 136 {$ENDIF} 137 137 Result := inherited OpenKey(Key, CanCreate); -
trunk/UCore.pas
r33 r36 88 88 FormSettings := TFormSettings.Create(nil); 89 89 try 90 FormSettings.ShowModal; 90 if FormSettings.ShowModal = mrOk then begin 91 FormMain.UpdateInterface; 92 UpdateInterface; 93 end; 91 94 finally 92 95 FreeAndNil(FormSettings); … … 153 156 FormNew.Save(Core.Game); 154 157 Game.New; 158 UpdateInterface; 159 FormMain.UpdateInterface; 155 160 end; 156 161 finally … … 184 189 begin 185 190 AUndo.Enabled := Game.CanUndo; 191 AHistory.Enabled := Game.RecordHistory; 186 192 {$IFDEF DEBUG} 187 193 AComputer.Enabled := True; -
trunk/UGame.pas
r35 r36 61 61 InitialTilesPos: array of TPoint; 62 62 procedure GetStep(GameStep: TGame; Step: Integer); 63 procedure Clear; 63 64 constructor Create; 64 65 destructor Destroy; override; … … 96 97 FOnGameOver: TNotifyEvent; 97 98 FOnWin: TNotifyEvent; 99 FRecordHistory: Boolean; 98 100 FRunning: Boolean; 99 101 FScore: Integer; … … 101 103 FBoardUndo: TBoard; 102 104 function GetTileColor(Value: Integer): TColor; 105 procedure SetRecordHistory(AValue: Boolean); 103 106 procedure SetScore(AValue: Integer); 104 107 procedure DoChange; … … 138 141 property OnGameOver: TNotifyEvent read FOnGameOver write FOnGameOver; 139 142 property Moving: Boolean read FMoving; 143 property RecordHistory: Boolean read FRecordHistory write SetRecordHistory; 140 144 end; 141 145 … … 173 177 var 174 178 I: Integer; 175 C: Integer;176 HistoryMove: THistoryMove;177 179 begin 178 180 with Reg do begin 179 181 CurrentContext := RegContext; 180 C := ReadIntegerWithDefault('Count', 0); 181 for I := 0 to C - 1 do begin 182 HistoryMove := THistoryMove.Create; 183 Add(HistoryMove); 184 HistoryMove.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '/' + IntToStr(I))); 182 Count := ReadIntegerWithDefault('Count', 0); 183 for I := 0 to Count - 1 do begin 184 Items[I] := THistoryMove.Create; 185 THistoryMove(Items[I]).LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '/' + IntToStr(I))); 185 186 end; 186 187 end; … … 229 230 else raise Exception.Create('Tile should be empty'); 230 231 end; 232 end; 233 234 procedure THistory.Clear; 235 begin 236 Moves.Clear; 237 SetLength(InitialTilesPos, 0); 231 238 end; 232 239 … … 475 482 Result := EmptyTiles[Random(EmptyTiles.Count)]; 476 483 Result.Value := NewValue; 484 if RecordHistory then begin 485 SetLength(History.InitialTilesPos, Length(History.InitialTilesPos) + 1); 486 History.InitialTilesPos[Length(History.InitialTilesPos) - 1] := Result.Index; 487 end; 477 488 end; 478 489 EmptyTiles.Free; … … 512 523 var 513 524 I: Integer; 514 NewTile: TTile;515 525 begin 516 526 FCanUndo := False; … … 518 528 Score := 0; 519 529 Running := True; 520 with History do begin 521 Moves.Clear; 522 523 SetLength(InitialTilesPos, 0); 524 for I := 0 to 1 do begin 525 NewTile := FillRandomTile(0); 526 SetLength(InitialTilesPos, Length(InitialTilesPos) + 1); 527 InitialTilesPos[Length(InitialTilesPos) - 1] := NewTile.Index; 528 end; 529 end; 530 History.Clear; 531 for I := 0 to 1 do 532 FillRandomTile(0); 530 533 DoChange; 531 534 end; … … 860 863 861 864 NewTile := FillRandomTile; 862 HistoryMove := THistoryMove.Create; 863 HistoryMove.Direction := Direction; 864 HistoryMove.NewItemPos := NewTile.Index; 865 HistoryMove.NewItemValue := NewTile.Value; 866 History.Moves.Add(HistoryMove); 865 if RecordHistory then begin 866 HistoryMove := THistoryMove.Create; 867 HistoryMove.Direction := Direction; 868 HistoryMove.NewItemPos := NewTile.Index; 869 HistoryMove.NewItemValue := NewTile.Value; 870 History.Moves.Add(HistoryMove); 871 end; 867 872 868 873 if not CanMove and (Board.GetEmptyTilesCount = 0) then … … 902 907 WriteBool('CanUndo', FCanUndo); 903 908 WriteBool('UndoEnabled', UndoEnabled); 909 WriteBool('RecordHistory', RecordHistory); 904 910 FBoardUndo.SaveToRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\BoardUndo')); 905 911 Board.SaveToRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\Board')); … … 924 930 FCanUndo := ReadBoolWithDefault('CanUndo', False); 925 931 UndoEnabled := ReadBoolWithDefault('UndoEnabled', True); 932 RecordHistory := ReadBoolWithDefault('RecordHistory', False); 926 933 FBoardUndo.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\BoardUndo')); 927 934 Board.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\Board')); … … 970 977 end; 971 978 979 procedure TGame.SetRecordHistory(AValue: Boolean); 980 begin 981 if FRecordHistory = AValue then Exit; 982 FRecordHistory := AValue; 983 if not FRecordHistory then History.Clear; 984 end; 985 972 986 procedure TGame.SetScore(AValue: Integer); 973 987 begin
Note:
See TracChangeset
for help on using the changeset viewer.