- Timestamp:
- Feb 18, 2014, 8:47:40 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UFormMain.pas
r11 r12 58 58 MoveActive: Boolean; 59 59 RedrawPending: Boolean; 60 procedure DoOnMove(CellFrom, CellTo: TCell; var CountOnce, CountRepeat: Integer); 60 61 public 61 62 Game: TGame; … … 69 70 70 71 uses 71 UFormNew ;72 UFormNew, UFormMove; 72 73 73 74 {$R *.lfm} … … 97 98 end; 98 99 100 procedure TFormMain.DoOnMove(CellFrom, CellTo: TCell; var CountOnce, 101 CountRepeat: Integer); 102 begin 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; 109 end; 110 99 111 procedure TFormMain.Redraw; 100 112 begin … … 105 117 begin 106 118 Game := TGame.Create; 119 Game.OnMove := DoOnMove; 107 120 end; 108 121 -
trunk/UGame.pas
r11 r12 74 74 { TGame } 75 75 76 TMoveEvent = procedure(CellFrom, CellTo: TCell; var CountOnce, CountRepeat: Integer) of object; 77 76 78 TGame = class 77 79 private 80 FOnMove: TMoveEvent; 78 81 procedure MoveAll(Player: TPlayer); 79 procedure SetMove(CellFrom, CellTo: TCell ; Count: Integer);82 procedure SetMove(CellFrom, CellTo: TCell); 80 83 public 81 84 Players: TObjectList; // TList<TPlayer> … … 88 91 destructor Destroy; override; 89 92 procedure New; 93 published 94 property OnMove: TMoveEvent read FOnMove write FOnMove; 90 95 end; 91 96 … … 162 167 if IsCellsNeighbor(NewSelectedCell, SelectedCell) then begin 163 168 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])); 166 170 SelectedCell := Point(-1, -1); 167 171 end else … … 221 225 end; 222 226 223 procedure TGame.SetMove(CellFrom, CellTo: TCell ; Count: Integer);227 procedure TGame.SetMove(CellFrom, CellTo: TCell); 224 228 var 225 229 NewMove: TMove; 226 230 I: Integer; 231 CountOnce: Integer; 232 CountRepeat: Integer; 227 233 begin 228 234 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); 231 245 if I < Moves.Count then begin 232 246 // 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; 235 252 end else begin 236 253 // Add new move 237 if Count > 0then begin254 if (CountOnce > 0) or (CountRepeat > 0) then begin 238 255 NewMove := TMove(Moves[Moves.Add(TMove.Create)]); 239 256 NewMove.CellFrom := CellFrom; 240 257 NewMove.CellTo := CellTo; 241 NewMove.CountOnce := Count; 258 NewMove.CountOnce := CountOnce; 259 NewMove.CountRepeat := CountRepeat; 242 260 end; 243 261 end; -
trunk/xtactics.lpi
r6 r12 33 33 </Item1> 34 34 </RequiredPackages> 35 <Units Count=" 4">35 <Units Count="5"> 36 36 <Unit0> 37 37 <Filename Value="xtactics.lpr"/> … … 59 59 <UnitName Value="UFormNew"/> 60 60 </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> 61 68 </Units> 62 69 </ProjectOptions> -
trunk/xtactics.lpr
r6 r12 8 8 {$ENDIF}{$ENDIF} 9 9 Interfaces, // this includes the LCL widgetset 10 Forms, UFormMain, UGame, UFormNew 10 Forms, UFormMain, UGame, UFormNew, UFormMove 11 11 { you can add units after this }; 12 12 … … 18 18 Application.CreateForm(TFormMain, FormMain); 19 19 Application.CreateForm(TFormNew, FormNew); 20 Application.CreateForm(TFormMove, FormMove); 20 21 Application.Run; 21 22 end.
Note:
See TracChangeset
for help on using the changeset viewer.