Changeset 105 for trunk/Game.pas


Ignore:
Timestamp:
Dec 9, 2024, 4:40:34 PM (13 days ago)
Author:
chronos
Message:
  • Added: Set number of randomly generated disabled tiles in new game form.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Game.pas

    r104 r105  
    3939    FColorPalette: TColorPalette;
    4040    FSkin: TTileSkin;
     41    FDisabledTilesCount: Integer;
    4142    function GetTileColor(Value: Integer): TColor;
    4243    procedure SetRecordHistory(AValue: Boolean);
     
    5253    procedure Win;
    5354    function FillRandomTile: TTile;
     55    function DisableRandomTile: TTile;
    5456    function GetMoveArea(Direction: TMoveDirection): TArea;
    5557    procedure MoveAllAnimate(Direction: TMoveDirection);
     
    9698    property Skin: TTileSkin read FSkin write SetSkin;
    9799    property ColorPalette: TColorPalette read FColorPalette write SetColorPalette;
     100    property DisabledTilesCount: Integer read FDisabledTilesCount write FDisabledTilesCount;
    98101  end;
    99102
     
    225228    Result.Value := NewValue;
    226229    Result.Action := taAppear;
     230  end;
     231  EmptyTiles.Free;
     232end;
     233
     234function TGame.DisableRandomTile: TTile;
     235var
     236  EmptyTiles: TTiles;
     237begin
     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;
    227244  end;
    228245  EmptyTiles.Free;
     
    276293  Running := True;
    277294  History.Clear;
     295  for I := 0 to DisabledTilesCount - 1 do
     296    DisableRandomTile;
     297
    278298  if RecordHistory then begin
    279299    for I := 0 to InitialTileCount - 1 do begin
     
    365385      if (Board.Tiles[Y, X].Action <> taNone) then MetaCanvas.Brush.Color := GetTileColor(0)
    366386        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;
    368389      TileRect := Bounds(
    369390        Frame.Left + X * TileSize.X + TileMargin,
     
    459480      while P.X <> Area.P2.X + Area.Increment.X do begin
    460481        PNew := P + DirectionDiff[Direction];
    461         if IsValidPos(PNew) then begin
     482        if IsValidPos(PNew) and not Board.Tiles[PNew.Y, PNew.X].Disabled then begin
    462483          SrcTile := Board.Tiles[P.Y, P.X];
    463484          DstTile := Board.Tiles[PNew.Y, PNew.X];
     
    496517  TextSize: TSize;
    497518begin
     519  if Canvas.Brush.Style = bsClear then Exit;
     520
    498521  Canvas.Pen.Style := psClear;
    499522  Canvas.RoundRect(TileRect, ScaleX(TileRect.Width div 20, 96), ScaleY(TileRect.Height div 20, 96));
    500   if WithText and (Tile.Value <> 0) then begin
     523  if (WithText and (Tile.Value <> 0)) then begin
    501524    ValueStr := GetTileSkinValue(Tile.Value);
    502525    Canvas.Brush.Style := bsClear;
     
    626649      if IsValidPos(PNew) then begin
    627650        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
    630654            Result := True;
    631655            Break;
     
    673697      while P.X <> Area.P2.X + Area.Increment.X do begin
    674698        PNew := P + DirectionDiff[Direction];
    675         if IsValidPos(PNew) then begin
     699        if IsValidPos(PNew) and not Board.Tiles[PNew.Y, PNew.X].Disabled then begin
    676700          if (Board.Tiles[P.Y, P.X].NewValue <> 0) then begin
    677701            if (Board.Tiles[PNew.Y, PNew.X].NewValue = 0) then begin
     
    934958    WriteInteger('Skin', Integer(Skin));
    935959    WriteInteger('ColorPalette', Integer(ColorPalette));
     960    WriteInteger('DisabledTilesCount', DisabledTilesCount);
    936961    FBoardUndo.SaveToRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\BoardUndo'));
    937962    Board.SaveToRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\Board'));
     
    959984    Skin := TTileSkin(ReadIntegerWithDefault('Skin', Integer(tsPowerOfTwo)));
    960985    ColorPalette := TColorPalette(ReadIntegerWithDefault('ColorPalette', Integer(cpOrangeYellow)));
     986    DisabledTilesCount := ReadIntegerWithDefault('DisabledTilesCount', DisabledTilesCount);
    961987    FBoardUndo.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\BoardUndo'));
    962988    Board.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\Board'));
Note: See TracChangeset for help on using the changeset viewer.