Changeset 12 for trunk


Ignore:
Timestamp:
Feb 18, 2014, 8:47:40 PM (11 years ago)
Author:
chronos
Message:
  • Added: Form where move parameters can be adjusted.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/UFormMain.pas

    r11 r12  
    5858    MoveActive: Boolean;
    5959    RedrawPending: Boolean;
     60    procedure DoOnMove(CellFrom, CellTo: TCell; var CountOnce, CountRepeat: Integer);
    6061  public
    6162    Game: TGame;
     
    6970
    7071uses
    71   UFormNew;
     72  UFormNew, UFormMove;
    7273
    7374{$R *.lfm}
     
    9798end;
    9899
     100procedure TFormMain.DoOnMove(CellFrom, CellTo: TCell; var CountOnce,
     101  CountRepeat: Integer);
     102begin
     103  FormMove.SpinEditOnce.Value := CountOnce;
     104  FormMove.SpinEditRepeat.Value := CountRepeat;
     105  if FormMove.ShowModal = mrOk then begin
     106    CountOnce := FormMove.SpinEditOnce.Value;
     107    CountRepeat := FormMove.SpinEditRepeat.Value;
     108  end;
     109end;
     110
    99111procedure TFormMain.Redraw;
    100112begin
     
    105117begin
    106118  Game := TGame.Create;
     119  Game.OnMove := DoOnMove;
    107120end;
    108121
  • 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;
  • trunk/xtactics.lpi

    r6 r12  
    3333      </Item1>
    3434    </RequiredPackages>
    35     <Units Count="4">
     35    <Units Count="5">
    3636      <Unit0>
    3737        <Filename Value="xtactics.lpr"/>
     
    5959        <UnitName Value="UFormNew"/>
    6060      </Unit3>
     61      <Unit4>
     62        <Filename Value="UFormMove.pas"/>
     63        <IsPartOfProject Value="True"/>
     64        <ComponentName Value="FormMove"/>
     65        <ResourceBaseClass Value="Form"/>
     66        <UnitName Value="UFormMove"/>
     67      </Unit4>
    6168    </Units>
    6269  </ProjectOptions>
  • trunk/xtactics.lpr

    r6 r12  
    88  {$ENDIF}{$ENDIF}
    99  Interfaces, // this includes the LCL widgetset
    10   Forms, UFormMain, UGame, UFormNew
     10  Forms, UFormMain, UGame, UFormNew, UFormMove
    1111  { you can add units after this };
    1212
     
    1818  Application.CreateForm(TFormMain, FormMain);
    1919  Application.CreateForm(TFormNew, FormNew);
     20  Application.CreateForm(TFormMove, FormMove);
    2021  Application.Run;
    2122end.
Note: See TracChangeset for help on using the changeset viewer.