Changeset 36 for trunk/UCore.pas
- Timestamp:
- Jan 1, 2018, 8:57:03 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UCore.pas
r34 r36 8 8 Dialogs, Classes, SysUtils, Graphics, SpecializedMatrix, SpecializedList, 9 9 IntfGraphics, FPImage, LCLType, SpecializedBitmap, GraphType, Math, URectangle, 10 Syncobjs, UThreading, Forms, DateUtils, UAudioSystem, UAudioSystemMPlayer; 10 Syncobjs, UThreading, Forms, DateUtils, UAudioSystem, UAudioSystemMPlayer, 11 XMLConf, DOM; 11 12 12 13 const … … 63 64 Image: TMatrixByte; 64 65 Mask: TMatrixByte; 66 procedure Assign(Source: TTank); 65 67 constructor Create; 66 68 destructor Destroy; override; 69 end; 70 71 { TTanks } 72 73 TTanks = class(TListObject) 74 procedure Assign(Source: TTanks); 67 75 end; 68 76 … … 109 117 Name: string; 110 118 Keys: TPlayerKeys; 111 Tanks: T ListObject; // TListObject<TTank>119 Tanks: TTanks; 112 120 Bullets: TListObject; // TListObject<TBullet> 113 121 LastShootTime: TDateTime; … … 133 141 destructor Destroy; override; 134 142 procedure Assign(Source: TPlayer); 143 procedure LoadConfig(Config: TXMLConfig; Path: string); 144 procedure SaveConfig(Config: TXMLConfig; Path: string); 135 145 property Exploded: Boolean read FExploded write SetExploded; 136 146 end; … … 139 149 140 150 TPlayers = class(TListObject) 151 Engine: TEngine; 141 152 procedure Assign(Players: TPlayers); 153 procedure LoadConfig(Config: TXMLConfig; Path: string); 154 procedure SaveConfig(Config: TXMLConfig; Path: string); 142 155 end; 143 156 … … 212 225 procedure DoDrawToBitmap; 213 226 procedure InitPlayerPool; 227 procedure InitPlayers; 214 228 public 215 229 Keyboard: TKeyboard; … … 232 246 procedure NewGame; 233 247 procedure NewRound; 248 procedure LoadConfig(Config: TXMLConfig; Path: string); 249 procedure SaveConfig(Config: TXMLConfig; Path: string); 234 250 property Bitmap: TBitmap read FBitmap write SetBitmap; 235 251 property Active: Boolean read FActive write SetActive; … … 267 283 end; 268 284 285 { TTanks } 286 287 procedure TTanks.Assign(Source: TTanks); 288 var 289 I: Integer; 290 begin 291 Clear; 292 Count := Source.Count; 293 for I := 0 to Count - 1 do begin 294 Items[I] := TTank.Create; 295 TTank(Items[I]).Assign(TTank(Source.Items[I])); 296 end; 297 end; 298 269 299 { TPlayers } 270 300 … … 279 309 end; 280 310 311 procedure TPlayers.SaveConfig(Config: TXMLConfig; Path: string); 312 var 313 I: Integer; 314 begin 315 Config.SetValue(DOMString(Path + '/Count'), Count); 316 for I := 0 to Count - 1 do 317 TPlayer(Items[I]).SaveConfig(Config, Path + '/Player' + IntToStr(I)); 318 end; 319 320 procedure TPlayers.LoadConfig(Config: TXMLConfig; Path: string); 321 var 322 I: Integer; 323 begin 324 Clear; 325 Count := Config.GetValue(DOMString(Path + '/Count'), 0); 326 for I := 0 to Count - 1 do begin 327 Items[I] := TPlayer.Create; 328 TPlayer(Items[I]).Engine := Engine; 329 TPlayer(Items[I]).Id := I; 330 TPlayer(Items[I]).LoadConfig(Config, Path + '/Player' + IntToStr(I)); 331 end; 332 end; 333 281 334 { TSystemThread } 282 335 … … 319 372 { TTank } 320 373 374 procedure TTank.Assign(Source: TTank); 375 begin 376 Image.Assign(Source.Image); 377 Mask.Assign(Source.Mask); 378 end; 379 321 380 constructor TTank.Create; 322 381 begin … … 327 386 destructor TTank.Destroy; 328 387 begin 329 Mask.Free;330 Image.Free;388 FreeAndNil(Mask); 389 FreeAndNil(Image); 331 390 inherited Destroy; 332 391 end; … … 694 753 destructor TWorld.Destroy; 695 754 begin 696 Surface.Free;697 Matter.Free;755 FreeAndNil(Surface); 756 FreeAndNil(Matter); 698 757 inherited Destroy; 699 758 end; … … 1186 1245 constructor TPlayer.Create; 1187 1246 begin 1188 Tanks := T ListObject.Create;1247 Tanks := TTanks.Create; 1189 1248 Bullets := TListObject.Create; 1190 1249 House := TRectangle.Create; … … 1194 1253 destructor TPlayer.Destroy; 1195 1254 begin 1196 ScreenFrame.Free;1197 House.Free;1198 Bullets.Free;1199 Tanks.Free;1255 FreeAndNil(ScreenFrame); 1256 FreeAndNil(House); 1257 FreeAndNil(Bullets); 1258 FreeAndNil(Tanks); 1200 1259 inherited Destroy; 1201 1260 end; … … 1203 1262 procedure TPlayer.Assign(Source: TPlayer); 1204 1263 begin 1264 Engine := Source.Engine; 1265 Id := Source.Id; 1205 1266 Keys := Source.Keys; 1206 1267 Color := Source.Color; … … 1211 1272 Position := Source.Position; 1212 1273 Score := Source.Score; 1274 Tanks.Assign(Source.Tanks); 1275 end; 1276 1277 procedure TPlayer.LoadConfig(Config: TXMLConfig; Path: string); 1278 begin 1279 with Config do begin 1280 Self.Name := GetValue(DOMString(Path + '/Name'), ''); 1281 Color := GetValue(DOMString(Path + '/Color'), 0); 1282 Enabled := GetValue(DOMString(Path + '/Enabled'), False); 1283 Keys.Left := GetValue(DOMString(Path + '/Keys/Left'), 0); 1284 Keys.Right := GetValue(DOMString(Path + '/Keys/Right'), 0); 1285 Keys.Down := GetValue(DOMString(Path + '/Keys/Down'), 0); 1286 Keys.Up := GetValue(DOMString(Path + '/Keys/Up'), 0); 1287 Keys.Shoot := GetValue(DOMString(Path + '/Keys/Shoot'), 0); 1288 end; 1289 InitTanks; 1290 end; 1291 1292 procedure TPlayer.SaveConfig(Config: TXMLConfig; Path: string); 1293 begin 1294 with Config do begin 1295 SetValue(DOMString(Path + '/Name'), Self.Name); 1296 SetValue(DOMString(Path + '/Color'), Color); 1297 SetValue(DOMString(Path + '/Enabled'), Enabled); 1298 SetValue(DOMString(Path + '/Keys/Left'), Keys.Left); 1299 SetValue(DOMString(Path + '/Keys/Right'), Keys.Right); 1300 SetValue(DOMString(Path + '/Keys/Down'), Keys.Down); 1301 SetValue(DOMString(Path + '/Keys/Up'), Keys.Up); 1302 SetValue(DOMString(Path + '/Keys/Shoot'), Keys.Shoot); 1303 end; 1213 1304 end; 1214 1305 … … 1517 1608 end; 1518 1609 1610 procedure TEngine.InitPlayers; 1611 var 1612 I: Integer; 1613 NewPlayer: TPlayer; 1614 begin 1615 Players.Clear; 1616 for I := 0 to PlayerPool.Count - 1 do 1617 with TPlayer(PlayerPool[I]) do 1618 if Enabled then begin 1619 NewPlayer := TPlayer.Create; 1620 NewPlayer.Assign(TPlayer(PlayerPool[I])); 1621 Players.Add(NewPlayer); 1622 Score := 0; 1623 end; 1624 end; 1625 1519 1626 procedure TEngine.CheckGameEnd; 1520 1627 var … … 1573 1680 IntfImage := TLazIntfImage.Create(1, 1); 1574 1681 PlayerPool := TPlayers.Create; 1682 PlayerPool.Engine := Self; 1575 1683 Players := TPlayers.Create; 1576 Players. OwnsObjects := False;1684 Players.Engine := Self; 1577 1685 Keyboard := TKeyboard.Create; 1578 1686 World := TWorld.Create; … … 1651 1759 begin 1652 1760 Active := False; 1653 Players.Clear; 1654 for I := 0 to PlayerPool.Count - 1 do 1655 with TPlayer(PlayerPool[I]) do 1656 if Enabled then begin 1657 Players.Add(PlayerPool[I]); 1658 Score := 0; 1659 end; 1761 InitPlayers; 1660 1762 ResizePlayerFrames; 1661 1763 CurrentRound := 0; … … 1681 1783 end; 1682 1784 1785 procedure TEngine.LoadConfig(Config: TXMLConfig; Path: string); 1786 begin 1787 PlayerPool.LoadConfig(Config, Path + '/Players'); 1788 end; 1789 1790 procedure TEngine.SaveConfig(Config: TXMLConfig; Path: string); 1791 begin 1792 PlayerPool.SaveConfig(Config, Path + '/Players'); 1793 end; 1794 1683 1795 end. 1684 1796
Note:
See TracChangeset
for help on using the changeset viewer.