Changeset 125 for trunk/UGame.pas
- Timestamp:
- Jun 17, 2017, 2:24:51 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGame.pas
r115 r125 28 28 TCellLinks = class; 29 29 TMapArea = class; 30 TClient = class; 30 31 31 32 TFloatPoint = record … … 248 249 TPlayer = class 249 250 private 251 FClient: TClient; 250 252 FGame: TGame; 253 procedure SetClient(AValue: TClient); 251 254 procedure SetGame(AValue: TGame); 252 255 public … … 254 257 Name: string; 255 258 Color: TColor; 256 View: TView;257 259 Mode: TPlayerMode; 258 260 TotalUnits: Integer; … … 266 268 procedure LoadFromNode(Node: TDOMNode); 267 269 procedure SaveToNode(Node: TDOMNode); 268 procedure Paint(Canvas: TCanvas );270 procedure Paint(Canvas: TCanvas; View: TView); 269 271 constructor Create; 270 272 destructor Destroy; override; 271 273 procedure Assign(Source: TPlayer); 272 274 property Game: TGame read FGame write SetGame; 275 property Client: TClient read FClient write SetClient; 273 276 end; 274 277 … … 333 336 end; 334 337 338 { TClient } 339 340 TClient = class 341 private 342 FGame: TGame; 343 FControlPlayer: TPlayer; 344 procedure SetControlPlayer(AValue: TPlayer); 345 procedure SetGame(AValue: TGame); 346 public 347 Name: string; 348 View: TView; 349 constructor Create; 350 destructor Destroy; override; 351 property ControlPlayer: TPlayer read FControlPlayer write SetControlPlayer; 352 property Game: TGame read FGame write SetGame; 353 end; 354 355 { TClients } 356 357 TClients = class(TObjectList) 358 Game: TGame; 359 procedure New(Name: string); 360 end; 361 335 362 { TGame } 336 363 … … 349 376 FOnMove: TMoveEvent; 350 377 FOnNewTurn: TNotifyEvent; 378 FOnPlayerChange: TNotifyEvent; 351 379 FOnWin: TWinEvent; 352 380 FRunning: Boolean; … … 367 395 public 368 396 Players: TPlayers; 397 Clients: TClients; 369 398 Map: TMap; 370 399 MapImageFileName: string; … … 406 435 property OnWin: TWinEvent read FOnWin write FOnWin; 407 436 property OnNewTurn: TNotifyEvent read FOnNewTurn write FOnNewTurn; 437 property OnPlayerChange: TNotifyEvent read FOnPlayerChange write FOnPlayerChange; 408 438 end; 409 439 … … 509 539 ((((Color shr 16) and $ff) shr 1) shl 16) or 510 540 ((((Color shr 24) and $ff) shr 0) shl 24); 541 end; 542 543 { TClients } 544 545 procedure TClients.New(Name: string); 546 var 547 NewClient: TClient; 548 begin 549 NewClient := TClient.Create; 550 NewClient.Game := Game; 551 NewClient.Name := Name; 552 Add(NewClient); 553 end; 554 555 { TClient } 556 557 procedure TClient.SetGame(AValue: TGame); 558 begin 559 if FGame = AValue then Exit; 560 FGame := AValue; 561 View.Game := AValue; 562 end; 563 564 procedure TClient.SetControlPlayer(AValue: TPlayer); 565 begin 566 if FControlPlayer = AValue then Exit; 567 if Assigned(FControlPlayer) then 568 FControlPlayer.FClient := nil; 569 FControlPlayer := AValue; 570 if Assigned(FControlPlayer) then 571 FControlPlayer.FClient := Self; 572 end; 573 574 constructor TClient.Create; 575 begin 576 View := TView.Create; 577 end; 578 579 destructor TClient.Destroy; 580 begin 581 ControlPlayer := nil; 582 FreeAndNil(View); 583 inherited Destroy; 511 584 end; 512 585 … … 1740 1813 if FGame = AValue then Exit; 1741 1814 FGame := AValue; 1742 View.Game := Game; 1815 end; 1816 1817 procedure TPlayer.SetClient(AValue: TClient); 1818 begin 1819 if FClient=AValue then Exit; 1820 if Assigned(FClient) then FClient.FControlPlayer := nil; 1821 FClient := AValue; 1822 if Assigned(FClient) then FClient.FControlPlayer := Self; 1743 1823 end; 1744 1824 … … 2146 2226 end; 2147 2227 2148 procedure TPlayer.Paint(Canvas: TCanvas );2228 procedure TPlayer.Paint(Canvas: TCanvas; View: TView); 2149 2229 begin 2150 2230 PlayerMap.Paint(Canvas, View); … … 2153 2233 constructor TPlayer.Create; 2154 2234 begin 2155 View := TView.Create;2156 2235 StartUnits := DefaultPlayerStartUnits; 2157 2236 StartCell := nil; … … 2163 2242 begin 2164 2243 FreeAndNil(PlayerMap); 2165 FreeAndNil(View);2166 2244 inherited Destroy; 2167 2245 end; … … 2180 2258 Agressivity := Source.Agressivity; 2181 2259 Defensive := Source.Defensive; 2182 View.Assign(Source.View);2183 2260 end; 2184 2261 … … 2432 2509 end else begin 2433 2510 FRunning := AValue; 2434 for I := 0 to Players.Count - 1 do2435 with T Player(Players[I]) do begin2511 for I := 0 to Clients.Count - 1 do 2512 with TClient(Clients[I]) do begin 2436 2513 View.Clear; 2437 2514 end; … … 2811 2888 PrevPlayer: TPlayer; 2812 2889 begin 2813 CurrentPlayer.View.SelectedCell := nil;2890 //TODO CurrentPlayer.View.SelectedCell := nil; 2814 2891 MoveAll(CurrentPlayer); 2815 2892 Map.Grow(CurrentPlayer); … … 2820 2897 repeat 2821 2898 CurrentPlayer := TPlayer(Players[(Players.IndexOf(CurrentPlayer) + 1) mod Players.Count]); 2899 if Assigned(FOnPlayerChange) then 2900 FOnPlayerChange(Self); 2822 2901 until CurrentPlayer.TotalCells > 0; 2823 2902 if Players.IndexOf(CurrentPlayer) < Players.IndexOf(PrevPlayer) then begin … … 2870 2949 Players := TPlayers.Create; 2871 2950 Players.Game := Self; 2951 Clients := TClients.Create; 2952 Clients.Game := Self; 2872 2953 2873 2954 MapImageFileName := 'Images/Maps/WorldMap.png'; … … 2887 2968 destructor TGame.Destroy; 2888 2969 begin 2970 FreeAndNil(Clients); 2889 2971 FreeAndNil(Moves); 2890 2972 FreeAndNil(Players); … … 2918 3000 end; 2919 3001 2920 2921 3002 if SymetricMap then begin 2922 3003 for C := 0 to (Map.Cells.Count div 2) - 1 do begin … … 2931 3012 with TPlayer(Players[I]) do begin 2932 3013 PlayerMap.Update; 2933 View.Clear;2934 3014 if (Map.Size.X > 0) and (Map.Size.Y > 0) then begin 2935 3015 // Try to obtain start cell for each player … … 2950 3030 StartCell.Power := TPlayer(Players[I]).StartUnits; 2951 3031 end; 3032 PlayerMap.CheckVisibility; 3033 end; 3034 if Players.Count > 0 then CurrentPlayer := TPlayer(Players[0]) 3035 else CurrentPlayer := nil; 3036 3037 Clients.Clear; 3038 Clients.New('Spectator'); 3039 for I := 0 to Players.Count - 1 do 3040 with TPlayer(Players[I]) do 3041 if Mode = pmHuman then begin 3042 Clients.New(TPlayer(Players[I]).Name); 3043 TPlayer(Players[I]).Client := TClient(Clients.Last); 3044 end; 3045 3046 for I := 0 to Clients.Count - 1 do 3047 with TClient(Clients[I]) do begin 3048 View.Clear; 2952 3049 View.Zoom := 1; 2953 3050 View.CenterMap; 2954 PlayerMap.CheckVisibility; 2955 end; 2956 if Players.Count > 0 then CurrentPlayer := TPlayer(Players[0]) 2957 else CurrentPlayer := nil; 3051 end; 2958 3052 end; 2959 3053 … … 2985 3079 with TCellLink(CellLinks[C]) do begin 2986 3080 if Length(Points) >= 2 then begin 2987 MoveTo( Points[0]);3081 MoveTo(View.CellToCanvasPos(Points[0])); 2988 3082 for I := 1 to Length(Points) - 1 do 2989 LineTo( Points[I]);3083 LineTo(View.CellToCanvasPos(Points[I])); 2990 3084 end; 2991 3085 end;
Note:
See TracChangeset
for help on using the changeset viewer.