Changeset 222 for trunk/UGame.pas


Ignore:
Timestamp:
Jul 13, 2018, 11:13:12 PM (6 years ago)
Author:
chronos
Message:
  • Fixed: Computer was affecting player cells by its cell moves.
  • Added: Additional consistency checks.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r220 r222  
    3838  private
    3939    FArea: TMapArea;
     40    FId: Integer;
    4041    FMap: TMap;
    4142    FPower: Integer;
    4243    procedure SetArea(AValue: TMapArea);
     44    procedure SetId(AValue: Integer);
    4345    procedure SetPower(AValue: Integer);
    4446  public
    45     Id: Integer;
    4647    PosPx: TPoint;
    4748    Polygon: TPolygon;
     
    5859    Links: TCellLinks;
    5960    Extra: TExtraType;
     61    property Id: Integer read FId write SetId;
    6062    procedure ConnectTo(Cell: TCell);
    6163    procedure DisconnectFrom(Cell: TCell);
     
    226228    procedure CreateLinks;
    227229    procedure Clear;
     230    procedure CheckCells;
    228231    constructor Create; virtual;
    229232    destructor Destroy; override;
     
    16881691end;
    16891692
     1693procedure TMap.CheckCells;
     1694var
     1695  I: Integer;
     1696  J: Integer;
     1697begin
     1698  for I := 0 to Cells.Count - 1 do begin
     1699    for J := I + 1 to Cells.Count - 1 do begin
     1700      if (Cells[I].Id = Cells[J].Id) then
     1701        raise Exception.Create('Duplicate cells ID ' + IntToStr(I) + ' ' + IntToStr(J));
     1702      if (Cells[I].PosPx = Cells[J].PosPx) then
     1703        raise Exception.Create('Duplicate cells position ' + IntToStr(I) + ' ' + IntToStr(J));
     1704    end;
     1705  end;
     1706end;
     1707
    16901708constructor TMap.Create;
    16911709begin
     
    18891907  FArea := AValue;
    18901908  if Assigned(FArea) then FArea.Cells.Add(Self);
     1909end;
     1910
     1911procedure TCell.SetId(AValue: Integer);
     1912begin
     1913  if FId = AValue then Exit;
     1914  FId := AValue;
    18911915end;
    18921916
     
    20372061constructor TCell.Create;
    20382062begin
     2063  FId := -1;
    20392064  Player := nil;
    20402065  Neighbors := TCells.Create;
     
    24512476  Confirm: Boolean;
    24522477begin
     2478  if CellFrom.Player <> Self then
     2479    raise Exception.Create('Can''t set move of other player.');
    24532480  Confirm := True;
    24542481  Result := Moves.SearchByFromTo(CellFrom, CellTo);
     
    27492776  I: Integer;
    27502777begin
     2778  if AttackCount < 0 then raise Exception.Create('Attack power needs to be possitive' + IntToStr(AttackCount));
    27512779  if AttackCount = 0 then begin
    27522780    Result := 0;
    27532781    Exit;
    27542782  end;
     2783  if DefendCount < 0 then raise Exception.Create('Defend power needs to be possitive but is ' + IntToStr(DefendCount));
    27552784  if DefendCount = 0 then begin
    27562785    Result := 1;
     
    31873216  NewPlayerIndex: Integer;
    31883217begin
     3218  {$IFDEF DEBUG}
     3219  Map.CheckCells;
     3220  {$ENDIF}
     3221
    31893222  // Finalize current player
    31903223  CurrentPlayer.MoveAll;
Note: See TracChangeset for help on using the changeset viewer.