- Timestamp:
- Feb 18, 2014, 8:15:50 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UFormMain.pas
r10 r11 185 185 Shift: TShiftState; MousePos: TPoint; var Handled: Boolean); 186 186 begin 187 with TPlayer(Game.Players[0])do187 with Game.CurrentPlayer do 188 188 ViewZoom := ViewZoom / ZoomFactor; 189 189 Redraw; … … 193 193 MousePos: TPoint; var Handled: Boolean); 194 194 begin 195 with TPlayer(Game.Players[0])do195 with Game.CurrentPlayer do 196 196 ViewZoom := ViewZoom * ZoomFactor; 197 197 Redraw; -
trunk/UGame.pas
r10 r11 65 65 end; 66 66 67 TMove = class 68 CellFrom: TCell; 69 CellTo: TCell; 70 CountOnce: Integer; 71 CountRepeat: Integer; 72 end; 73 67 74 { TGame } 68 75 69 76 TGame = class 70 Players: TObjectList; 77 private 78 procedure MoveAll(Player: TPlayer); 79 procedure SetMove(CellFrom, CellTo: TCell; Count: Integer); 80 public 81 Players: TObjectList; // TList<TPlayer> 71 82 Map: TMap; 72 83 VoidEnabled: Boolean; 73 84 CurrentPlayer: TPlayer; 85 Moves: TObjectList; // TList<TMove> 74 86 procedure NextTurn; 75 87 constructor Create; … … 149 161 (NewSelectedCell.Y >= 0) and (NewSelectedCell.Y < Length(Game.Map.Cells)) then begin 150 162 if IsCellsNeighbor(NewSelectedCell, SelectedCell) then begin 151 // Attack 152 TCell(Game.Map.Cells[NewSelectedCell.Y, NewSelectedCell.X]).Player := Self; 153 TCell(Game.Map.Cells[NewSelectedCell.Y, NewSelectedCell.X]).Power := 154 TCell(Game.Map.Cells[NewSelectedCell.Y, NewSelectedCell.X]).Power + 155 TCell(Game.Map.Cells[SelectedCell.Y, SelectedCell.X]).Power; 156 TCell(Game.Map.Cells[SelectedCell.Y, SelectedCell.X]).Power := 0; 163 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); 157 166 SelectedCell := Point(-1, -1); 158 167 end else … … 180 189 { TGame } 181 190 191 procedure TGame.MoveAll(Player: TPlayer); 192 var 193 I: Integer; 194 begin 195 for I := 0 to Moves.Count - 1 do 196 with TMove(Moves[I]) do begin 197 if CellFrom.Player = Player then begin 198 if CellTo.Player = Player then begin 199 // Inner move 200 CellTo.Power := CellTo.Power + CountOnce; 201 end else begin 202 // Fight 203 if CellTo.Power > CountOnce then begin 204 // Defender wins 205 CellTo.Power := CellTo.Power - CountOnce; 206 end else begin 207 // Attacker wins 208 CellTo.Power := CountOnce - CellTo.Power; 209 CellTo.Player := Player; 210 end; 211 end; 212 CellFrom.Power := CellFrom.Power - CountOnce; 213 CountOnce := 0; 214 end; 215 end; 216 // Remove empty moves 217 for I := Moves.Count - 1 downto 0 do 218 if (TMove(Moves[I]).CellFrom.Player = Player) and 219 (TMove(Moves[I]).CountOnce = 0) and (TMove(Moves[I]).CountRepeat = 0) then 220 Moves.Delete(I); 221 end; 222 223 procedure TGame.SetMove(CellFrom, CellTo: TCell; Count: Integer); 224 var 225 NewMove: TMove; 226 I: Integer; 227 begin 228 I := 0; 229 while (I < Moves.Count) and (TMove(Moves[I]).CellFrom <> CellFrom) and 230 (TMove(Moves[I]).CellTo <> CellTo) do Inc(I); 231 if I < Moves.Count then begin 232 // Already have such move 233 if Count = 0 then Moves.Delete(I) 234 else TMove(Moves[I]).CountOnce := Count; 235 end else begin 236 // Add new move 237 if Count > 0 then begin 238 NewMove := TMove(Moves[Moves.Add(TMove.Create)]); 239 NewMove.CellFrom := CellFrom; 240 NewMove.CellTo := CellTo; 241 NewMove.CountOnce := Count; 242 end; 243 end; 244 end; 245 182 246 procedure TGame.NextTurn; 183 247 begin 248 MoveAll(CurrentPlayer); 184 249 Map.Grow(CurrentPlayer); 185 250 CurrentPlayer := TPlayer(Players[(Players.IndexOf(CurrentPlayer) + 1) mod Players.Count]); … … 205 270 206 271 Map := TMap.Create; 272 Moves := TObjectList.Create; 207 273 end; 208 274 209 275 destructor TGame.Destroy; 210 276 begin 277 FreeAndNil(Moves); 211 278 FreeAndNil(Players); 212 279 FreeAndNil(Map);
Note:
See TracChangeset
for help on using the changeset viewer.