Legend:
- Unmodified
- Added
- Removed
-
trunk/UCore.pas
r23 r25 89 89 FormMain.Redraw; 90 90 while Game.Running and (Game.CurrentPlayer.Mode <> pmHuman) do begin 91 if Game.CurrentPlayer.Mode = pmComputer then 92 Game.CurrentPlayer.ComputerTurn; 91 93 Game.NextTurn; 92 94 FormMain.Redraw; -
trunk/UFormMain.pas
r23 r25 73 73 procedure TFormMain.PaintBox1Paint(Sender: TObject); 74 74 begin 75 if Core.Game.Running then 75 //if Core.Game.Running then 76 if Assigned(Core.Game.CurrentPlayer) then 76 77 with Core.Game.CurrentPlayer do begin 77 78 View.DestRect := Bounds(0, 0, PaintBox1.Width, PaintBox1.Height); -
trunk/UGame.pas
r24 r25 39 39 destructor Destroy; override; 40 40 end; 41 42 TCellArray = array of TCell; 41 43 42 44 { TMap } … … 77 79 DefaultCellSize: TPoint; 78 80 Cells: array of array of TCell; 81 function IsValidIndex(Index: TPoint): Boolean; 82 function GetCellNeighbours(Cell: TCell): TCellArray; 79 83 function PosToCell(Pos: TPoint; View: TView): TCell; 80 84 function CellToPos(Cell: TCell; View: TView): TPoint; … … 309 313 310 314 procedure TPlayer.ComputerTurn; 311 begin 312 315 var 316 Cells: TCellArray; 317 X, Y: Integer; 318 Target: TCell; 319 MinPower: Integer; 320 I: Integer; 321 begin 322 for Y := 0 to Game.Map.Size.Y - 1 do 323 for X := 0 to Game.Map.Size.Y - 1 do 324 with TCell(Game.Map.Cells[Y, X]) do begin 325 if Player = Self then begin 326 // Search not own neighbour with lowes power 327 Cells := Game.Map.GetCellNeighbours(Game.Map.Cells[Y, X]); 328 Target := nil; 329 for I := 0 to Length(Cells) - 1 do 330 if (Cells[I].Terrain <> ttVoid) and (Cells[I].Player <> Self) then begin 331 if I = 0 then begin 332 MinPower := Cells[I].Power; 333 Target := Cells[I]; 334 end else if Cells[I].Power < MinPower then begin 335 MinPower := Cells[I].Power; 336 Target := Cells[I]; 337 end; 338 end; 339 // Attack if target is weaker 340 if Assigned(Target) and (Target.Power < Power) then 341 Game.SetMove(Game.Map.Cells[Y, X], Target); 342 end; 343 end; 313 344 end; 314 345 … … 415 446 CountOnce := TMove(Moves[I]).CountOnce; 416 447 CountRepeat := TMove(Moves[I]).CountRepeat; 417 if Assigned(FOnMove) then FOnMove(CellFrom, CellTo, CountOnce, CountRepeat, True); 448 if Assigned(CurrentPlayer) and (CurrentPlayer.Mode = pmHuman) and 449 Assigned(FOnMove) then FOnMove(CellFrom, CellTo, CountOnce, CountRepeat, True); 418 450 end else begin 419 451 CountOnce := CellFrom.Power; 420 452 CountRepeat := 0; 421 if Assigned(FOnMove) then FOnMove(CellFrom, CellTo, CountOnce, CountRepeat, False); 453 if Assigned(CurrentPlayer) and (CurrentPlayer.Mode = pmHuman) and 454 Assigned(FOnMove) then FOnMove(CellFrom, CellTo, CountOnce, CountRepeat, False); 422 455 end; 423 456 if I < Moves.Count then begin … … 599 632 Cells[Y, X] := NewCell; 600 633 end; 634 end; 635 end; 636 637 function THexMap.IsValidIndex(Index: TPoint): Boolean; 638 begin 639 Result := (Index.X >= 0) and (Index.X < Size.X) and 640 (Index.Y >= 0) and (Index.Y < Size.Y); 641 end; 642 643 function THexMap.GetCellNeighbours(Cell: TCell): TCellArray; 644 var 645 X, Y: Integer; 646 begin 647 SetLength(Result, 0); 648 for Y := -1 to 1 do 649 for X := -1 to 1 do 650 if IsValidIndex(Point(Cell.Pos.X + X, Cell.Pos.Y + Y)) and 651 IsCellsNeighbor(Cell, Cells[Cell.Pos.Y + Y, Cell.Pos.X + X]) then begin 652 SetLength(Result, Length(Result) + 1); 653 Result[Length(Result) - 1] := Cells[Cell.Pos.Y + Y, Cell.Pos.X + X]; 601 654 end; 602 655 end;
Note:
See TracChangeset
for help on using the changeset viewer.