- Timestamp:
- Dec 9, 2024, 4:40:34 PM (5 weeks ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Board.pas
r104 r105 69 69 for Y := 0 to Size.Y - 1 do 70 70 for X := 0 to Size.X - 1 do 71 if Tiles[Y, X].Value = 0then71 if (Tiles[Y, X].Value = 0) and not Tiles[Y, X].Disabled then 72 72 EmptyTiles.Add(Tiles[Y, X]); 73 73 end; … … 76 76 var 77 77 X, Y: Integer; 78 Value: string;79 78 begin 80 79 with Reg do begin … … 83 82 WriteInteger('SizeX', Size.X); 84 83 WriteInteger('SizeY', Size.Y); 85 Value := '';86 84 for Y := 0 to Size.Y - 1 do begin 87 85 for X := 0 to Size.X - 1 do begin 88 Value := Value + IntToStr(Tiles[Y, X].Value); 89 if X < Size.X - 1 then Value := Value + ','; 86 Tiles[Y, X].SaveToRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\Tile' + IntToStr(X) + 'x' + IntToStr(Y))); 90 87 end; 91 if Y < Size.Y - 1 then Value := Value + ';'92 88 end; 93 WriteString('TileValues', Value);94 89 end; 95 90 end; … … 98 93 var 99 94 X, Y: Integer; 100 Items: TStringList;101 Lines: TStringList;102 Number: Integer;103 95 begin 104 96 with Reg do begin 105 97 CurrentContext := RegContext; 106 98 107 Size := Point(ReadIntegerWithDefault('SizeX', 4), ReadIntegerWithDefault('SizeY', 4)); 108 Items := TStringList.Create; 109 Items.Delimiter := ','; 110 Lines := TStringList.Create; 111 Lines.Delimiter := ';'; 112 Lines.DelimitedText := ReadStringWithDefault('TileValues', ''); 113 for Y := 0 to Lines.Count - 1 do begin 114 Items.DelimitedText := Lines[Y]; 115 for X := 0 to Items.Count - 1 do begin 116 if TryStrToInt(Items[X], Number) and (X < Size.X) and (Y < Size.Y) then 117 Tiles[Y, X].Value := Number; 99 Size := Point(ReadIntegerWithDefault('SizeX', 4), 100 ReadIntegerWithDefault('SizeY', 4)); 101 for Y := 0 to Size.Y - 1 do begin 102 for X := 0 to Size.X - 1 do begin 103 Tiles[Y, X].LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\Tile' + IntToStr(X) + 'x' + IntToStr(Y))); 118 104 end; 119 105 end; 120 Lines.Free;121 Items.Free;122 106 end; 123 107 end; … … 155 139 for Y := 0 to Size.Y - 1 do 156 140 for X := 0 to Size.X - 1 do 157 if Tiles[Y, X].Value = 0then141 if (Tiles[Y, X].Value = 0) and not Tiles[Y, X].Disabled then 158 142 Inc(Result); 159 143 end; … … 175 159 for Y := 0 to Size.Y - 1 do 176 160 for X := 0 to Size.X - 1 do 177 Tiles[Y, X]. Value := 0;161 Tiles[Y, X].Clear; 178 162 end; 179 163 -
trunk/Forms/FormNew.lfm
r103 r105 35 35 Width = 497 36 36 HorzScrollBar.Page = 435 37 VertScrollBar.Page = 1 1837 VertScrollBar.Page = 160 38 38 Anchors = [akTop, akLeft, akRight, akBottom] 39 39 ClientHeight = 245 … … 69 69 Style = csDropDownList 70 70 TabOrder = 0 71 OnChange = ComboBoxSizeChange 71 72 end 72 73 object CheckBoxUndoEnabled: TCheckBox … … 86 87 TabOrder = 2 87 88 end 89 object Label2: TLabel 90 Left = 16 91 Height = 26 92 Top = 122 93 Width = 119 94 Caption = 'Disabled tiles:' 95 end 96 object SpinEditDisabledTiles: TSpinEdit 97 Left = 320 98 Height = 43 99 Top = 117 100 Width = 115 101 MaxValue = 10000 102 TabOrder = 3 103 end 88 104 end 89 105 end -
trunk/Forms/FormNew.lrj
r103 r105 5 5 {"hash":103901194,"name":"tformnew.label1.caption","sourcebytes":[66,111,97,114,100,32,115,105,122,101,58],"value":"Board size:"}, 6 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 {"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"}, 8 {"hash":248990730,"name":"tformnew.label2.caption","sourcebytes":[68,105,115,97,98,108,101,100,32,116,105,108,101,115,58],"value":"Disabled tiles:"} 8 9 ]} -
trunk/Forms/FormNew.pas
r103 r105 5 5 uses 6 6 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 7 Game, FormEx;7 Spin, Game, FormEx, Math; 8 8 9 9 type … … 18 18 ComboBoxSize: TComboBox; 19 19 Label1: TLabel; 20 Label2: TLabel; 20 21 ScrollBox1: TScrollBox; 22 SpinEditDisabledTiles: TSpinEdit; 23 procedure ComboBoxSizeChange(Sender: TObject); 21 24 public 25 procedure UpdateInterface; 22 26 procedure Load(Game: TGame); 23 27 procedure Save(Game: TGame); … … 30 34 31 35 { TFormNew } 36 37 procedure TFormNew.ComboBoxSizeChange(Sender: TObject); 38 begin 39 UpdateInterface; 40 end; 41 42 procedure TFormNew.UpdateInterface; 43 begin 44 SpinEditDisabledTiles.MaxValue := ComboBoxSize.ItemIndex + 2; 45 end; 46 32 47 procedure TFormNew.Load(Game: TGame); 33 48 begin … … 35 50 CheckBoxUndoEnabled.Checked := Game.UndoEnabled; 36 51 CheckBoxRecordHistory.Checked := Game.RecordHistory; 52 SpinEditDisabledTiles.Value := Game.DisabledTilesCount; 53 UpdateInterface; 37 54 end; 38 55 … … 42 59 Game.UndoEnabled := CheckBoxUndoEnabled.Checked; 43 60 Game.RecordHistory := CheckBoxRecordHistory.Checked; 61 Game.DisabledTilesCount := SpinEditDisabledTiles.Value; 44 62 end; 45 63 -
trunk/Game.pas
r104 r105 39 39 FColorPalette: TColorPalette; 40 40 FSkin: TTileSkin; 41 FDisabledTilesCount: Integer; 41 42 function GetTileColor(Value: Integer): TColor; 42 43 procedure SetRecordHistory(AValue: Boolean); … … 52 53 procedure Win; 53 54 function FillRandomTile: TTile; 55 function DisableRandomTile: TTile; 54 56 function GetMoveArea(Direction: TMoveDirection): TArea; 55 57 procedure MoveAllAnimate(Direction: TMoveDirection); … … 96 98 property Skin: TTileSkin read FSkin write SetSkin; 97 99 property ColorPalette: TColorPalette read FColorPalette write SetColorPalette; 100 property DisabledTilesCount: Integer read FDisabledTilesCount write FDisabledTilesCount; 98 101 end; 99 102 … … 225 228 Result.Value := NewValue; 226 229 Result.Action := taAppear; 230 end; 231 EmptyTiles.Free; 232 end; 233 234 function TGame.DisableRandomTile: TTile; 235 var 236 EmptyTiles: TTiles; 237 begin 238 Result := nil; 239 EmptyTiles := TTiles.Create(False); 240 Board.GetEmptyTiles(EmptyTiles); 241 if EmptyTiles.Count > 0 then begin 242 Result := EmptyTiles[Random(EmptyTiles.Count)]; 243 Result.Disabled := True; 227 244 end; 228 245 EmptyTiles.Free; … … 276 293 Running := True; 277 294 History.Clear; 295 for I := 0 to DisabledTilesCount - 1 do 296 DisableRandomTile; 297 278 298 if RecordHistory then begin 279 299 for I := 0 to InitialTileCount - 1 do begin … … 365 385 if (Board.Tiles[Y, X].Action <> taNone) then MetaCanvas.Brush.Color := GetTileColor(0) 366 386 else MetaCanvas.Brush.Color := GetTileColor(Board.Tiles[Y, X].Value); 367 MetaCanvas.Brush.Style := bsSolid; 387 if Board.Tiles[Y, X].Disabled then MetaCanvas.Brush.Style := bsClear 388 else MetaCanvas.Brush.Style := bsSolid; 368 389 TileRect := Bounds( 369 390 Frame.Left + X * TileSize.X + TileMargin, … … 459 480 while P.X <> Area.P2.X + Area.Increment.X do begin 460 481 PNew := P + DirectionDiff[Direction]; 461 if IsValidPos(PNew) then begin482 if IsValidPos(PNew) and not Board.Tiles[PNew.Y, PNew.X].Disabled then begin 462 483 SrcTile := Board.Tiles[P.Y, P.X]; 463 484 DstTile := Board.Tiles[PNew.Y, PNew.X]; … … 496 517 TextSize: TSize; 497 518 begin 519 if Canvas.Brush.Style = bsClear then Exit; 520 498 521 Canvas.Pen.Style := psClear; 499 522 Canvas.RoundRect(TileRect, ScaleX(TileRect.Width div 20, 96), ScaleY(TileRect.Height div 20, 96)); 500 if WithText and (Tile.Value <> 0) then begin523 if (WithText and (Tile.Value <> 0)) then begin 501 524 ValueStr := GetTileSkinValue(Tile.Value); 502 525 Canvas.Brush.Style := bsClear; … … 626 649 if IsValidPos(PNew) then begin 627 650 if (Board.Tiles[P.Y, P.X].Value <> 0) then begin 628 if (Board.Tiles[PNew.Y, PNew.X].Value = 0) or 629 CanMergeTile(Board.Tiles[PNew.Y, PNew.X].Value, Board.Tiles[P.Y, P.X].Value) then begin 651 if ((Board.Tiles[PNew.Y, PNew.X].Value = 0) or 652 CanMergeTile(Board.Tiles[PNew.Y, PNew.X].Value, Board.Tiles[P.Y, P.X].Value)) and 653 not Board.Tiles[PNew.Y, PNew.X].Disabled then begin 630 654 Result := True; 631 655 Break; … … 673 697 while P.X <> Area.P2.X + Area.Increment.X do begin 674 698 PNew := P + DirectionDiff[Direction]; 675 if IsValidPos(PNew) then begin699 if IsValidPos(PNew) and not Board.Tiles[PNew.Y, PNew.X].Disabled then begin 676 700 if (Board.Tiles[P.Y, P.X].NewValue <> 0) then begin 677 701 if (Board.Tiles[PNew.Y, PNew.X].NewValue = 0) then begin … … 934 958 WriteInteger('Skin', Integer(Skin)); 935 959 WriteInteger('ColorPalette', Integer(ColorPalette)); 960 WriteInteger('DisabledTilesCount', DisabledTilesCount); 936 961 FBoardUndo.SaveToRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\BoardUndo')); 937 962 Board.SaveToRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\Board')); … … 959 984 Skin := TTileSkin(ReadIntegerWithDefault('Skin', Integer(tsPowerOfTwo))); 960 985 ColorPalette := TColorPalette(ReadIntegerWithDefault('ColorPalette', Integer(cpOrangeYellow))); 986 DisabledTilesCount := ReadIntegerWithDefault('DisabledTilesCount', DisabledTilesCount); 961 987 FBoardUndo.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\BoardUndo')); 962 988 Board.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\Board')); -
trunk/Languages/Game2048.cs.po
r103 r105 280 280 msgstr "Velikost desky:" 281 281 282 #: tformnew.label2.caption 283 msgid "Disabled tiles:" 284 msgstr "Blokované dlaždice:" 285 282 286 #: tformsettings.buttoncancel.caption 283 287 msgctxt "tformsettings.buttoncancel.caption" -
trunk/Tile.pas
r104 r105 4 4 5 5 uses 6 Classes, SysUtils, Generics.Collections ;6 Classes, SysUtils, Generics.Collections, RegistryEx; 7 7 8 8 type … … 18 18 Action: TTileAction; 19 19 Shift: TPoint; 20 Disabled: Boolean; 21 procedure Clear; 20 22 procedure Assign(Source: TTile); 23 procedure SaveToRegistry(Reg: TRegistryEx; RegContext: TRegistryContext); 24 procedure LoadFromRegistry(Reg: TRegistryEx; RegContext: TRegistryContext); 21 25 end; 22 26 … … 29 33 { TTile } 30 34 35 procedure TTile.Clear; 36 begin 37 Value := 0; 38 Action := taNone;; 39 Disabled := False; 40 end; 41 31 42 procedure TTile.Assign(Source: TTile); 32 43 begin 44 Index := Source.Index; 33 45 Value := Source.Value; 34 46 Merged := Source.Merged; 47 Disabled := Source.Disabled; 35 48 end; 36 49 50 procedure TTile.SaveToRegistry(Reg: TRegistryEx; RegContext: TRegistryContext); 51 begin 52 with Reg do begin 53 CurrentContext := RegContext; 54 55 WriteInteger('Value', Value); 56 WriteBool('Disabled', Disabled); 57 end; 58 end; 59 60 procedure TTile.LoadFromRegistry(Reg: TRegistryEx; RegContext: TRegistryContext 61 ); 62 begin 63 with Reg do begin 64 CurrentContext := RegContext; 65 66 Value := ReadIntegerWithDefault('Value', Value); 67 Disabled := ReadBoolWithDefault('Disabled', Disabled); 68 end; 69 end; 37 70 38 71 end.
Note:
See TracChangeset
for help on using the changeset viewer.