|
- unit GameStore;
- interface
- type
- TGame = class
- private
- FName: string;
- FPrice: Double;
- public
- constructor Create(const AName: string; APrice: Double);
- property Name: string read FName;
- property Price: Double read FPrice;
- end;
- TGameStore = class
- private
- FGames: array of TGame;
- public
- constructor Create;
- procedure AddGame(const AName: string; APrice: Double);
- procedure DisplayGames;
- end;
- implementation
- constructor TGame.Create(const AName: string; APrice: Double);
- begin
- FName := AName;
- FPrice := APrice;
- end;
- constructor TGameStore.Create;
- begin
- SetLength(FGames, 0);
- end;
- procedure TGameStore.AddGame(const AName: string; APrice: Double);
- var
- Game: TGame;
- begin
- Game := TGame.Create(AName, APrice);
- SetLength(FGames, Length(FGames) + 1);
- FGames[Length(FGames) - 1] := Game;
- end;
- procedure TGameStore.DisplayGames;
- var
- Game: TGame;
- begin
- if Length(FGames) > 0 then
- begin
- for Game in FGames do
- begin
- Writeln('Game: ', Game.Name, ', Price: ', FloatToStr(Game.Price));
- end;
- end
- else
- Writeln('No games available.');
- end;
- end.
复制代码 在上述代码中,我们定义了 TGame 类来表示游戏,其中包括游戏名称和价格的属性。TGameStore 类用于管理游戏商城,包括添加游戏和展示游戏列表的功能。
- program GameShop;
- uses
- GameStore;
- var
- Store: TGameStore;
- begin
- Store := TGameStore.Create;
- Store.AddGame('Game 1', 49.99);
- Store.AddGame('Game 2', 29.99);
- Store.AddGame('Game 3', 39.99);
-
- Store.DisplayGames;
- Readln;
- end.
复制代码 在这个示例中,我们创建了一个 TGameStore 对象并添加了几个游戏。然后调用 DisplayGames 方法来展示游戏列表。你可以根据需要自定义和扩展这些类,以适应你的具体游戏商城需求。
|
上一篇:C#传奇源代码自动寻路源码下一篇:传奇自动寻路源码Delphi自动寻路源码
|