Changeset 12 for trunk/UGame.pas
- Timestamp:
- Feb 18, 2014, 8:47:40 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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;
Note:
See TracChangeset
for help on using the changeset viewer.