Changeset 16
- Timestamp:
- Mar 27, 2015, 10:26:05 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UEngine.pas
r15 r16 144 144 LastNewWeekTime: TDateTime; 145 145 LastNewShapeTime: TDateTime; 146 LastTickTime: TDateTime; 146 147 ImagePassenger: TImage; 147 148 ImageLocomotive: TImage; 149 FTime: TDateTime; 148 150 function GetExistStationShapes: TStationShapeSet; 149 151 function GetStationOnPos(Pos: TPoint): TMetroStation; … … 157 159 procedure ComputeShapeDistanceStation(Station: TMetroStation; 158 160 UpdatedShape: TStationShape; Distance: Integer); 159 function GetTime: TDateTime;160 161 procedure TrainMovement; 161 162 public … … 171 172 ServedPassengerCount: Integer; 172 173 State: TGameState; 173 StartTime: TDateTime;174 174 procedure Tick; 175 175 procedure MouseMove(Position: TPoint); … … 180 180 destructor Destroy; override; 181 181 procedure Paint(Canvas: TCanvas); 182 property Time: TDateTime read GetTime;182 property Time: TDateTime read FTime; 183 183 end; 184 184 … … 199 199 MaxWaitingPassengers = 10; 200 200 MetroLineThickness = 13; 201 TrackClickDistance = 20; 201 202 202 203 implementation … … 604 605 T: Integer; 605 606 D: Integer; 607 MinD: Integer; 606 608 const 607 609 Distance = 30; … … 609 611 Result := nil; 610 612 I := 0; 613 MinD := High(Integer); 611 614 while (I < Lines.Count) do 612 615 with TMetroLine(Lines[I]) do begin 613 616 for T := 1 to TrackPoints.Count - 1 do begin 614 617 D := PointToLineDistance(Pos, TTrackPoint(TrackPoints[T - 1]).Point, TTrackPoint(TrackPoints[T]).Point); 615 if D < Distance then begin 618 if (D < MinD) and (D < TrackClickDistance) then begin 619 MinD := D; 616 620 Result := TMetroLine(Lines[I]); 617 Break;618 621 end; 619 622 end; 620 if Assigned(Result) then Break;621 623 Inc(I); 622 624 end; … … 789 791 end; 790 792 791 function TEngine.GetTime: TDateTime;792 begin793 Result := (Now - StartTime) / OneSecond * (60 * OneMinute);794 end;795 796 793 procedure TEngine.TrainMovement; 797 794 var … … 976 973 begin 977 974 if State = gsRunning then begin 975 FTime := FTime + (Now - LastTickTime) / OneSecond * (60 * OneMinute); 978 976 979 977 // Add new trains … … 1021 1019 1022 1020 end; 1021 LastTickTime := Now; 1023 1022 end; 1024 1023 … … 1105 1104 procedure TEngine.Reset; 1106 1105 var 1107 NewLine: TMetroLine;1108 1106 NewTrain: TMetroTrain; 1109 1107 I: Integer; 1110 1108 NewStation: TMetroStation; 1109 InitialStationCount: Integer; 1111 1110 begin 1112 1111 Passengers.Clear; … … 1118 1117 1119 1118 // Start with 3 stations with each different shape 1120 NewStation := Stations.AddNew; 1121 NewStation.Shape := ssSquare; 1122 NewStation := Stations.AddNew; 1123 NewStation.Shape := ssCircle; 1124 NewStation := Stations.AddNew; 1125 NewStation.Shape := ssTriangle; 1119 InitialStationCount := 30; 1120 for I := 0 to InitialStationCount - 1 do begin 1121 NewStation := Stations.AddNew; 1122 if I = 0 then NewStation.Shape := ssSquare 1123 else if I = 1 then NewStation.Shape := ssCircle 1124 else if I = 2 then NewStation.Shape := ssTriangle; 1125 end; 1126 1126 1127 1127 for I := 0 to 2 do begin 1128 NewLine :=Lines.AddNew;1128 Lines.AddNew; 1129 1129 NewTrain := TMetroTrain.Create; 1130 1130 Trains.Add(NewTrain); … … 1136 1136 LastNewWeekTime := Now; 1137 1137 LastNewShapeTime := Now; 1138 LastTickTime := Now; 1139 FTime := 0; 1138 1140 State := gsRunning; 1139 StartTime := Now;1140 1141 end; 1141 1142 -
trunk/UFormMain.lfm
r2 r16 9 9 OnCreate = FormCreate 10 10 OnDestroy = FormDestroy 11 OnKeyPress = FormKeyPress 11 12 OnShow = FormShow 12 13 LCLVersion = '1.5' -
trunk/UFormMain.pas
r3 r16 18 18 procedure FormCreate(Sender: TObject); 19 19 procedure FormDestroy(Sender: TObject); 20 procedure FormKeyPress(Sender: TObject; var Key: char); 20 21 procedure FormShow(Sender: TObject); 21 22 procedure PaintBox1Click(Sender: TObject); … … 52 53 begin 53 54 Engine.Free; 55 end; 56 57 procedure TFormMain.FormKeyPress(Sender: TObject; var Key: char); 58 begin 59 if (Key = #32) then begin 60 if Engine.State = gsRunning then Engine.State := gsPaused 61 else if Engine.State = gsPaused then Engine.State := gsRunning; 62 end; 54 63 end; 55 64
Note:
See TracChangeset
for help on using the changeset viewer.