Changeset 15 for trunk/UGame.pas


Ignore:
Timestamp:
Feb 19, 2014, 11:13:36 PM (11 years ago)
Author:
chronos
Message:
  • Added: Size of map can be adjusted in New game dialog.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r14 r15  
    3030    MovesTo: TObjectList;
    3131    function GetColor: TColor;
     32    function GetAvialPower: Integer;
    3233    constructor Create;
    3334    destructor Destroy; override;
     
    112113  end;
    113114
     115const
     116  PlayerModeText: array[TPlayerMode] of string = ('Human', 'Computer');
     117
    114118
    115119implementation
     
    166170  if Assigned(Player) then Result := Player.Color
    167171    else Result := clGray;
     172end;
     173
     174function TCell.GetAvialPower: Integer;
     175var
     176  I: Integer;
     177begin
     178  Result := Power;
     179  for I := 0 to MovesFrom.Count - 1 do
     180    Result := Result - TMove(MovesFrom[I]).CountOnce;
     181  if Result < 0 then Result := 0;
    168182end;
    169183
     
    249263  for I := Moves.Count - 1 downto 0 do
    250264  if (TMove(Moves[I]).CellFrom.Player = Player) and
    251     (TMove(Moves[I]).CountOnce = 0) and (TMove(Moves[I]).CountRepeat = 0) then
     265    (TMove(Moves[I]).CountOnce = 0) and (TMove(Moves[I]).CountRepeat = 0) then begin
     266    TMove(Moves[I]).CellFrom.MovesFrom.Remove(TMove(Moves[I]));
     267    TMove(Moves[I]).CellTo.MovesTo.Remove(TMove(Moves[I]));
    252268    Moves.Delete(I);
     269  end;
    253270end;
    254271
     
    276293      else begin
    277294        TMove(Moves[I]).CountOnce := CountOnce;
    278          TMove(Moves[I]).CountOnce := CountOnce;
     295        TMove(Moves[I]).CountOnce := CountOnce;
    279296      end;
    280297  end else begin
     
    286303      NewMove.CountOnce := CountOnce;
    287304      NewMove.CountRepeat := CountRepeat;
     305      CellFrom.MovesFrom.Add(NewMove);
     306      CellTo.MovesTo.Add(NewMove);
    288307    end;
    289308  end;
     
    317336  Map := THexMap.Create;
    318337  Map.Game := Self;
     338  Map.Size := Point(20, 20);
    319339  Moves := TObjectList.Create;
    320340end;
     
    335355  StartCell: TCell;
    336356begin
    337   Map.Size := Point(20, 20);
     357  Moves.Clear;
     358  Map.ClearCellMoves;
    338359  for Y := 0 to Map.Size.Y - 1 do
    339360  for X := 0 to Map.Size.X - 1 do
     
    346367  with TPlayer(Players[I]) do begin
    347368    SelectedCell := nil;
    348     StartCell := Map.Cells[Random(Map.Size.Y), Random(Map.Size.X)];
    349     StartCell.Terrain := ttNormal;
    350     StartCell.Player := TPlayer(Players[I]);
     369    if (Map.Size.X > 0) and (Map.Size.Y > 0) then begin
     370      StartCell := Map.Cells[Random(Map.Size.Y), Random(Map.Size.X)];
     371      StartCell.Terrain := ttNormal;
     372      StartCell.Player := TPlayer(Players[I]);
     373    end;
    351374  end;
    352375  CurrentPlayer := TPlayer(Players[0]);
     
    379402    for Y := 0 to FSize.Y - 1 do
    380403    for X := 0 to FSize.X - 1 do begin
    381       Cells[Y, X].Destroy;
     404      TCell(Cells[Y, X]).Destroy;
    382405    end;
    383406    FSize := AValue;
    384407    // Allocate and init new
    385     SetLength(Cells, FSize.X, FSize.Y);
     408    SetLength(Cells, FSize.Y, FSize.X);
    386409    for Y := 0 to FSize.Y - 1 do
    387410    for X := 0 to FSize.X - 1 do begin
     
    499522          Pen.Color := clBlack;
    500523          PaintHexagon(X * CellSize.X - Frac(Rect.Left / CellSize.X) * CellSize.X,
    501             Y * CellSize.Y - Frac(Rect.Top / CellSize.Y) * CellSize.Y, IntToStr(Cell.Power));
     524            Y * CellSize.Y - Frac(Rect.Top / CellSize.Y) * CellSize.Y, IntToStr(Cell.GetAvialPower));
    502525          // Draw arrows
    503526          Pen.Color := clCream;
Note: See TracChangeset for help on using the changeset viewer.