Changeset 36 for trunk/UGame.pas
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 5 5 xtactics.dbg 6 6 heaptrclog.trc 7 Config.xml
-
- Property svn:ignore
-
trunk/UGame.pas
r35 r36 6 6 7 7 uses 8 Classes, SysUtils, ExtCtrls, Graphics, Contnrs ;8 Classes, SysUtils, ExtCtrls, Graphics, Contnrs, XMLConf; 9 9 10 10 const … … 29 29 30 30 TCell = class 31 private 32 FPower: Integer; 33 procedure SetPower(AValue: Integer); 34 public 31 35 Pos: TPoint; 32 36 Terrain: TTerrainType; 33 Power: Integer;34 37 Player: TPlayer; 35 38 MovesFrom: TObjectList; … … 39 42 constructor Create; 40 43 destructor Destroy; override; 44 property Power: Integer read FPower write SetPower; 41 45 end; 42 46 … … 176 180 Moves: TObjectList; // TList<TMove> 177 181 TurnCounter: Integer; 178 182 procedure SaveConfig(Config: TXmlConfig; Path: string); 183 procedure LoadConfig(Config: TXmlConfig; Path: string); 179 184 procedure ComputePlayerStats; 180 185 function GetAlivePlayers: TPlayerArray; … … 362 367 363 368 { TCell } 369 370 procedure TCell.SetPower(AValue: Integer); 371 begin 372 if FPower = AValue then Exit; 373 if AValue < 0 then 374 raise Exception.Create('Not allowed to substract power under zero do negative value'); 375 FPower := AValue; 376 end; 364 377 365 378 function TCell.GetColor: TColor; … … 568 581 DefenderRoll: Integer; 569 582 begin 583 if AttackPower < 1 then 584 raise Exception.Create('Attacker power have to be higher then 0.'); 585 if DefendPower < 0 then 586 raise Exception.Create('Defender power have to be higher then or equal to 0.'); 570 587 while (AttackPower > 0) and (DefendPower > 0) do begin 571 588 // Earch side do dice roll and compare result. Defender wins tie … … 590 607 if CellTo.Player = Player then begin 591 608 // Inner move 592 CellTo.Power := CellTo.Power + CountOnce;593 609 end else begin 594 610 AttackerPower := CountOnce; … … 705 721 end; 706 722 723 procedure TGame.SaveConfig(Config: TXmlConfig; Path: string); 724 begin 725 with Config do begin 726 SetValue(Path + '/VoidEnabled', VoidEnabled); 727 SetValue(Path + '/VoidPercentage', VoidPercentage); 728 SetValue(Path + '/MapSizeX', Map.Size.X); 729 SetValue(Path + '/MapSizeY', Map.Size.Y); 730 end; 731 end; 732 733 procedure TGame.LoadConfig(Config: TXmlConfig; Path: string); 734 begin 735 with Config do begin 736 VoidEnabled := GetValue(Path + '/VoidEnabled', True); 737 VoidPercentage := GetValue(Path + '/VoidPercentage', 20); 738 Map.Size := Point(GetValue(Path + '/MapSizeX', 15), 739 GetValue(Path + '/MapSizeY', 15)); 740 end; 741 end; 742 707 743 procedure TGame.ComputePlayerStats; 708 744 var … … 796 832 I: Integer; 797 833 StartCell: TCell; 834 Counter: Integer; 798 835 begin 799 836 TurnCounter := 1; … … 811 848 View.Clear; 812 849 if (Map.Size.X > 0) and (Map.Size.Y > 0) then begin 813 StartCell := Map.Cells[Random(Map.Size.Y), Random(Map.Size.X)]; 850 // Try to obtain start cell for each player 851 StartCell := nil; 852 Counter := 0; 853 while not Assigned(StartCell) or Assigned(StartCell.Player) do begin 854 StartCell := Map.Cells[Random(Map.Size.Y), Random(Map.Size.X)]; 855 Inc(Counter); 856 if Counter > 100 then 857 raise Exception.Create('Cannot choose start cell for player'); 858 end; 814 859 StartCell.Terrain := ttNormal; 815 860 StartCell.Player := TPlayer(Players[I]);
Note:
See TracChangeset
for help on using the changeset viewer.