Changeset 105 for trunk/Game.pas
- Timestamp:
- Dec 9, 2024, 4:40:34 PM (13 days ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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'));
Note:
See TracChangeset
for help on using the changeset viewer.