Changeset 15 for trunk/UGame.pas
- Timestamp:
- Feb 19, 2014, 11:13:36 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGame.pas
r14 r15 30 30 MovesTo: TObjectList; 31 31 function GetColor: TColor; 32 function GetAvialPower: Integer; 32 33 constructor Create; 33 34 destructor Destroy; override; … … 112 113 end; 113 114 115 const 116 PlayerModeText: array[TPlayerMode] of string = ('Human', 'Computer'); 117 114 118 115 119 implementation … … 166 170 if Assigned(Player) then Result := Player.Color 167 171 else Result := clGray; 172 end; 173 174 function TCell.GetAvialPower: Integer; 175 var 176 I: Integer; 177 begin 178 Result := Power; 179 for I := 0 to MovesFrom.Count - 1 do 180 Result := Result - TMove(MovesFrom[I]).CountOnce; 181 if Result < 0 then Result := 0; 168 182 end; 169 183 … … 249 263 for I := Moves.Count - 1 downto 0 do 250 264 if (TMove(Moves[I]).CellFrom.Player = Player) and 251 (TMove(Moves[I]).CountOnce = 0) and (TMove(Moves[I]).CountRepeat = 0) then 265 (TMove(Moves[I]).CountOnce = 0) and (TMove(Moves[I]).CountRepeat = 0) then begin 266 TMove(Moves[I]).CellFrom.MovesFrom.Remove(TMove(Moves[I])); 267 TMove(Moves[I]).CellTo.MovesTo.Remove(TMove(Moves[I])); 252 268 Moves.Delete(I); 269 end; 253 270 end; 254 271 … … 276 293 else begin 277 294 TMove(Moves[I]).CountOnce := CountOnce; 278 295 TMove(Moves[I]).CountOnce := CountOnce; 279 296 end; 280 297 end else begin … … 286 303 NewMove.CountOnce := CountOnce; 287 304 NewMove.CountRepeat := CountRepeat; 305 CellFrom.MovesFrom.Add(NewMove); 306 CellTo.MovesTo.Add(NewMove); 288 307 end; 289 308 end; … … 317 336 Map := THexMap.Create; 318 337 Map.Game := Self; 338 Map.Size := Point(20, 20); 319 339 Moves := TObjectList.Create; 320 340 end; … … 335 355 StartCell: TCell; 336 356 begin 337 Map.Size := Point(20, 20); 357 Moves.Clear; 358 Map.ClearCellMoves; 338 359 for Y := 0 to Map.Size.Y - 1 do 339 360 for X := 0 to Map.Size.X - 1 do … … 346 367 with TPlayer(Players[I]) do begin 347 368 SelectedCell := nil; 348 StartCell := Map.Cells[Random(Map.Size.Y), Random(Map.Size.X)]; 349 StartCell.Terrain := ttNormal; 350 StartCell.Player := TPlayer(Players[I]); 369 if (Map.Size.X > 0) and (Map.Size.Y > 0) then begin 370 StartCell := Map.Cells[Random(Map.Size.Y), Random(Map.Size.X)]; 371 StartCell.Terrain := ttNormal; 372 StartCell.Player := TPlayer(Players[I]); 373 end; 351 374 end; 352 375 CurrentPlayer := TPlayer(Players[0]); … … 379 402 for Y := 0 to FSize.Y - 1 do 380 403 for X := 0 to FSize.X - 1 do begin 381 Cells[Y, X].Destroy;404 TCell(Cells[Y, X]).Destroy; 382 405 end; 383 406 FSize := AValue; 384 407 // Allocate and init new 385 SetLength(Cells, FSize. X, FSize.Y);408 SetLength(Cells, FSize.Y, FSize.X); 386 409 for Y := 0 to FSize.Y - 1 do 387 410 for X := 0 to FSize.X - 1 do begin … … 499 522 Pen.Color := clBlack; 500 523 PaintHexagon(X * CellSize.X - Frac(Rect.Left / CellSize.X) * CellSize.X, 501 Y * CellSize.Y - Frac(Rect.Top / CellSize.Y) * CellSize.Y, IntToStr(Cell. Power));524 Y * CellSize.Y - Frac(Rect.Top / CellSize.Y) * CellSize.Y, IntToStr(Cell.GetAvialPower)); 502 525 // Draw arrows 503 526 Pen.Color := clCream;
Note:
See TracChangeset
for help on using the changeset viewer.