Changeset 12 for trunk/UGame.pas


Ignore:
Timestamp:
Feb 18, 2014, 8:47:40 PM (11 years ago)
Author:
chronos
Message:
  • Added: Form where move parameters can be adjusted.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r11 r12  
    7474  { TGame }
    7575
     76  TMoveEvent = procedure(CellFrom, CellTo: TCell; var CountOnce, CountRepeat: Integer) of object;
     77
    7678  TGame = class
    7779  private
     80    FOnMove: TMoveEvent;
    7881    procedure MoveAll(Player: TPlayer);
    79     procedure SetMove(CellFrom, CellTo: TCell; Count: Integer);
     82    procedure SetMove(CellFrom, CellTo: TCell);
    8083  public
    8184    Players: TObjectList; // TList<TPlayer>
     
    8891    destructor Destroy; override;
    8992    procedure New;
     93  published
     94    property OnMove: TMoveEvent read FOnMove write FOnMove;
    9095  end;
    9196
     
    162167    if IsCellsNeighbor(NewSelectedCell, SelectedCell) then begin
    163168      Game.SetMove(TCell(Game.Map.Cells[SelectedCell.Y, SelectedCell.X]),
    164         TCell(Game.Map.Cells[NewSelectedCell.Y, NewSelectedCell.X]),
    165         TCell(Game.Map.Cells[SelectedCell.Y, SelectedCell.X]).Power);
     169        TCell(Game.Map.Cells[NewSelectedCell.Y, NewSelectedCell.X]));
    166170      SelectedCell := Point(-1, -1);
    167171    end else
     
    221225end;
    222226
    223 procedure TGame.SetMove(CellFrom, CellTo: TCell; Count: Integer);
     227procedure TGame.SetMove(CellFrom, CellTo: TCell);
    224228var
    225229  NewMove: TMove;
    226230  I: Integer;
     231  CountOnce: Integer;
     232  CountRepeat: Integer;
    227233begin
    228234  I := 0;
    229   while (I < Moves.Count) and (TMove(Moves[I]).CellFrom <> CellFrom) and
    230     (TMove(Moves[I]).CellTo <> CellTo) do Inc(I);
     235  while (I < Moves.Count) and ((TMove(Moves[I]).CellFrom <> CellFrom) or
     236    (TMove(Moves[I]).CellTo <> CellTo)) do Inc(I);
     237  if I < Moves.Count then begin
     238    CountOnce := TMove(Moves[I]).CountOnce;
     239    CountRepeat := TMove(Moves[I]).CountRepeat;
     240  end else begin
     241    CountOnce := CellFrom.Power;
     242    CountRepeat := 0;
     243  end;
     244  if Assigned(FOnMove) then FOnMove(CellFrom, CellTo, CountOnce, CountRepeat);
    231245  if I < Moves.Count then begin
    232246    // Already have such move
    233     if Count = 0 then Moves.Delete(I)
    234       else TMove(Moves[I]).CountOnce := Count;
     247    if (CountOnce = 0) and (CountRepeat = 0) then Moves.Delete(I)
     248      else begin
     249        TMove(Moves[I]).CountOnce := CountOnce;
     250         TMove(Moves[I]).CountOnce := CountOnce;
     251      end;
    235252  end else begin
    236253    // Add new move
    237     if Count > 0 then begin
     254    if (CountOnce > 0) or (CountRepeat > 0) then begin
    238255      NewMove := TMove(Moves[Moves.Add(TMove.Create)]);
    239256      NewMove.CellFrom := CellFrom;
    240257      NewMove.CellTo := CellTo;
    241       NewMove.CountOnce := Count;
     258      NewMove.CountOnce := CountOnce;
     259      NewMove.CountRepeat := CountRepeat;
    242260    end;
    243261  end;
Note: See TracChangeset for help on using the changeset viewer.