Changeset 105 for trunk/Board.pas


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

Legend:

Unmodified
Added
Removed
  • trunk/Board.pas

    r104 r105  
    6969  for Y := 0 to Size.Y - 1 do
    7070    for X := 0 to Size.X - 1 do
    71       if Tiles[Y, X].Value = 0 then
     71      if (Tiles[Y, X].Value = 0) and not Tiles[Y, X].Disabled then
    7272        EmptyTiles.Add(Tiles[Y, X]);
    7373end;
     
    7676var
    7777  X, Y: Integer;
    78   Value: string;
    7978begin
    8079  with Reg do begin
     
    8382    WriteInteger('SizeX', Size.X);
    8483    WriteInteger('SizeY', Size.Y);
    85     Value := '';
    8684    for Y := 0 to Size.Y - 1 do begin
    8785      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)));
    9087      end;
    91       if Y < Size.Y - 1 then Value := Value + ';'
    9288    end;
    93     WriteString('TileValues', Value);
    9489  end;
    9590end;
     
    9893var
    9994  X, Y: Integer;
    100   Items: TStringList;
    101   Lines: TStringList;
    102   Number: Integer;
    10395begin
    10496  with Reg do begin
    10597    CurrentContext := RegContext;
    10698
    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)));
    118104      end;
    119105    end;
    120     Lines.Free;
    121     Items.Free;
    122106  end;
    123107end;
     
    155139  for Y := 0 to Size.Y - 1 do
    156140    for X := 0 to Size.X - 1 do
    157       if Tiles[Y, X].Value = 0 then
     141      if (Tiles[Y, X].Value = 0) and not Tiles[Y, X].Disabled then
    158142        Inc(Result);
    159143end;
     
    175159  for Y := 0 to Size.Y - 1 do
    176160    for X := 0 to Size.X - 1 do
    177       Tiles[Y, X].Value := 0;
     161      Tiles[Y, X].Clear;
    178162end;
    179163
Note: See TracChangeset for help on using the changeset viewer.