Rev 25 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 25 | Rev 26 | ||
---|---|---|---|
Line 74... | Line 74... | ||
74 | procedure DoJump(SourceTag, DestTag: integer); |
74 | procedure DoJump(SourceTag, DestTag: integer); |
75 | function MayJump(SourceTag, DestTag: integer): boolean; overload; |
75 | function MayJump(SourceTag, DestTag: integer): boolean; overload; |
76 | procedure StoneDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); |
76 | procedure StoneDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); |
77 | procedure StoneDragDrop(Sender, Source: TObject; X, Y: Integer); |
77 | procedure StoneDragDrop(Sender, Source: TObject; X, Y: Integer); |
78 | procedure DrawField(x, y: integer; var f: TField); |
78 | procedure DrawField(x, y: integer; var f: TField); |
79 | function DrawStone(fieldtype: TFieldType; panel: TPanel): TImage; |
79 | function DrawStone(f: TField): TImage; |
80 | function DrawStoneBox(x, y, tag, halftabs: integer; isGoal: boolean): TPanel; |
80 | function DrawStoneBox(x, y, tag: integer; f: TField): TPanel; |
81 | procedure LoadPictureForType(FieldType: TFieldType; Picture: TPicture); |
81 | procedure LoadPictureForType(FieldType: TFieldType; Picture: TPicture); |
82 | function GoalStatus: TGoalStatus; |
82 | function GoalStatus: TGoalStatus; |
83 | end; |
83 | end; |
84 | 84 | ||
85 | var |
85 | var |
Line 90... | Line 90... | ||
90 | uses |
90 | uses |
91 | About, Finish, Choice, Functions, History, HighScore, Help, Constants, Math; |
91 | About, Finish, Choice, Functions, History, HighScore, Help, Constants, Math; |
92 | 92 | ||
93 | {$R *.dfm} |
93 | {$R *.dfm} |
94 | 94 | ||
- | 95 | type |
|
- | 96 | TFieldVclData = class(TObject) |
|
- | 97 | public |
|
- | 98 | Panel: TPanel; |
|
- | 99 | Stone: TImage; |
|
- | 100 | destructor Destroy; override; |
|
- | 101 | end; |
|
- | 102 | ||
95 | { TMainForm } |
103 | { TMainForm } |
96 | 104 | ||
97 | procedure TMainForm.RedrawStonesFromMatrix(Matrix: TPlayGroundMatrix); |
105 | procedure TMainForm.RedrawStonesFromMatrix(Matrix: TPlayGroundMatrix); |
98 | var |
106 | var |
99 | x, y: integer; |
107 | x, y: integer; |
100 | begin |
108 | begin |
101 | for x := Low(Matrix.Fields) to High(Matrix.Fields) do |
109 | for x := Low(Matrix.Fields) to High(Matrix.Fields) do |
102 | begin |
110 | begin |
103 | for y := Low(Matrix.Fields[x]) to High(Matrix.Fields[x]) do |
111 | for y := Low(Matrix.Fields[x]) to High(Matrix.Fields[x]) do |
104 | begin |
112 | begin |
105 | if Assigned(Matrix.Fields[x,y].Stone) then |
113 | if Assigned(Matrix.Fields[x,y].Data) and |
- | 114 | Assigned(TFieldVclData(Matrix.Fields[x,y].Data).Stone) then |
|
106 | begin |
115 | begin |
107 | LoadPictureForType(Matrix.Fields[x,y].FieldType, Matrix.Fields[x,y].Stone.Picture); |
116 | LoadPictureForType(Matrix.Fields[x,y].FieldType, |
- | 117 | TFieldVclData(Matrix.Fields[x,y].Data).Stone.Picture); |
|
108 | StoneDraggingAllow(Matrix.Fields[x,y].Stone, Matrix.FieldState(Matrix.Fields[x,y].FieldType) <> fsAvailable); |
118 | StoneDraggingAllow(TFieldVclData(Matrix.Fields[x,y].Data).Stone, |
- | 119 | Matrix.Fields[x,y].FieldState <> fsAvailable); |
|
109 | end; |
120 | end; |
110 | end; |
121 | end; |
111 | end; |
122 | end; |
112 | end; |
123 | end; |
113 | 124 | ||
Line 152... | Line 163... | ||
152 | ftYellow: Picture.Bitmap.LoadFromResourceName(HInstance, RES_YELLOW); |
163 | ftYellow: Picture.Bitmap.LoadFromResourceName(HInstance, RES_YELLOW); |
153 | ftRed: Picture.Bitmap.LoadFromResourceName(HInstance, RES_RED); |
164 | ftRed: Picture.Bitmap.LoadFromResourceName(HInstance, RES_RED); |
154 | end; |
165 | end; |
155 | end; |
166 | end; |
156 | 167 | ||
157 | function TMainForm.DrawStone(fieldtype: TFieldType; panel: TPanel): TImage; |
168 | function TMainForm.DrawStone(f: TField): TImage; |
- | 169 | var |
|
- | 170 | panel: TPanel; |
|
158 | begin |
171 | begin |
- | 172 | panel := TFieldVclData(f.Data).Panel; |
|
- | 173 | ||
159 | result := TImage.Create(panel); |
174 | result := TImage.Create(panel); |
160 | result.Parent := panel; |
175 | result.Parent := panel; |
161 | LoadPictureForType(fieldtype, result.Picture); |
176 | LoadPictureForType(f.FieldType, result.Picture); |
162 | result.Width := panel.Width - 2*MET_SHAPE_MARGIN; |
177 | result.Width := panel.Width - 2*MET_SHAPE_MARGIN; |
163 | result.Height := panel.Height - 2*MET_SHAPE_MARGIN; |
178 | result.Height := panel.Height - 2*MET_SHAPE_MARGIN; |
164 | result.Left := MET_SHAPE_MARGIN; |
179 | result.Left := MET_SHAPE_MARGIN; |
165 | result.Top := MET_SHAPE_MARGIN; |
180 | result.Top := MET_SHAPE_MARGIN; |
166 | result.Center := true; |
181 | result.Center := true; |
Line 168... | Line 183... | ||
168 | 183 | ||
169 | result.Tag := panel.Tag; |
184 | result.Tag := panel.Tag; |
170 | result.OnDragOver := panel.OnDragOver; |
185 | result.OnDragOver := panel.OnDragOver; |
171 | result.OnDragDrop := panel.OnDragDrop; |
186 | result.OnDragDrop := panel.OnDragDrop; |
172 | 187 | ||
173 | StoneDraggingAllow(result, PlayGroundMatrix.FieldState(fieldtype) <> fsAvailable); |
188 | StoneDraggingAllow(result, f.FieldState <> fsAvailable); |
174 | end; |
189 | end; |
175 | 190 | ||
176 | procedure TMainForm.StoneDraggingAllow(Stone: TImage; Allow: boolean); |
191 | procedure TMainForm.StoneDraggingAllow(Stone: TImage; Allow: boolean); |
177 | begin |
192 | begin |
178 | if Allow then |
193 | if Allow then |
Line 185... | Line 200... | ||
185 | Stone.DragMode := dmManual; |
200 | Stone.DragMode := dmManual; |
186 | (Stone.Parent as TPanel).DragMode := dmManual; |
201 | (Stone.Parent as TPanel).DragMode := dmManual; |
187 | end; |
202 | end; |
188 | end; |
203 | end; |
189 | 204 | ||
190 | function TMainForm.DrawStoneBox(x, y, tag, halftabs: integer; isGoal: boolean): TPanel; |
205 | function TMainForm.DrawStoneBox(x, y, tag: integer; f: TField): TPanel; |
191 | begin |
206 | begin |
192 | result := TPanel.Create(Playground); |
207 | result := TPanel.Create(Playground); |
193 | result.Parent := Playground; |
208 | result.Parent := Playground; |
194 | if isGoal then |
209 | if f.Goal then |
195 | begin |
210 | begin |
196 | result.BevelInner := bvLowered; |
211 | result.BevelInner := bvLowered; |
197 | end; |
212 | end; |
198 | result.Color := Playground.Color; |
213 | result.Color := Playground.Color; |
199 | result.BevelOuter := bvLowered; |
214 | result.BevelOuter := bvLowered; |
200 | result.Width := MET_FIELD_SIZE; |
215 | result.Width := MET_FIELD_SIZE; |
201 | result.Height := MET_FIELD_SIZE; |
216 | result.Height := MET_FIELD_SIZE; |
202 | result.Left := x * (MET_FIELD_SIZE+MET_FIELD_SPACE) + MET_FIELD_SPACE + (halftabs*MET_HALFTAB_SIZE); |
217 | result.Left := x * (MET_FIELD_SIZE+MET_FIELD_SPACE) + MET_FIELD_SPACE + (f.Indent*MET_HALFTAB_SIZE); |
203 | result.Top := y * (MET_FIELD_SIZE+MET_FIELD_SPACE) + MET_FIELD_SPACE; |
218 | result.Top := y * (MET_FIELD_SIZE+MET_FIELD_SPACE) + MET_FIELD_SPACE; |
204 | 219 | ||
205 | result.Tag := tag; |
220 | result.Tag := tag; |
206 | result.OnDragOver := StoneDragOver; |
221 | result.OnDragOver := StoneDragOver; |
207 | result.OnDragDrop := StoneDragDrop; |
222 | result.OnDragDrop := StoneDragDrop; |
Line 239... | Line 254... | ||
239 | Inc(LevelRemovedStones); |
254 | Inc(LevelRemovedStones); |
240 | RefreshStonesRemoved; |
255 | RefreshStonesRemoved; |
241 | end; |
256 | end; |
242 | 257 | ||
243 | PlayGroundMatrix.Fields[x,y].FieldType := ftEmpty; |
258 | PlayGroundMatrix.Fields[x,y].FieldType := ftEmpty; |
244 | LoadPictureForType(PlayGroundMatrix.Fields[x,y].FieldType, PlayGroundMatrix.Fields[x,y].Stone.Picture); |
259 | LoadPictureForType(PlayGroundMatrix.Fields[x,y].FieldType, |
- | 260 | TFieldVclData(PlayGroundMatrix.Fields[x,y].Data).Stone.Picture); |
|
245 | StoneDraggingAllow(PlayGroundMatrix.Fields[x,y].Stone, false); |
261 | StoneDraggingAllow(TFieldVclData(PlayGroundMatrix.Fields[x,y].Data).Stone, false); |
246 | end; |
262 | end; |
247 | 263 | ||
248 | procedure TMainForm.Aboutthislevel1Click(Sender: TObject); |
264 | procedure TMainForm.Aboutthislevel1Click(Sender: TObject); |
249 | var |
265 | var |
250 | mode: string; |
266 | mode: string; |
Line 315... | Line 331... | ||
315 | 331 | ||
316 | {$REGION 'Nun den Stein springen lassen'} |
332 | {$REGION 'Nun den Stein springen lassen'} |
317 | old_fieldtype := PlayGroundMatrix.Fields[s.X, s.Y].FieldType; // Steinfarbe merken |
333 | old_fieldtype := PlayGroundMatrix.Fields[s.X, s.Y].FieldType; // Steinfarbe merken |
318 | RemoveStone(s.X, s.Y, false); // Eigenen Stein entfernen. Keine Punkte zählen, da das unser eigener Stein ist, der springt |
334 | RemoveStone(s.X, s.Y, false); // Eigenen Stein entfernen. Keine Punkte zählen, da das unser eigener Stein ist, der springt |
319 | PlayGroundMatrix.Fields[d.X, d.Y].FieldType := old_fieldtype; // Farbe wiederherstellen |
335 | PlayGroundMatrix.Fields[d.X, d.Y].FieldType := old_fieldtype; // Farbe wiederherstellen |
- | 336 | LoadPictureForType(PlayGroundMatrix.Fields[d.X, d.Y].FieldType, |
|
320 | LoadPictureForType(PlayGroundMatrix.Fields[d.X, d.Y].FieldType, PlayGroundMatrix.Fields[d.X, d.Y].Stone.Picture); // Stein an neue Position malen |
337 | TFieldVclData(PlayGroundMatrix.Fields[d.X, d.Y].Data).Stone.Picture); // Stein an neue Position malen |
321 | StoneDraggingAllow(PlayGroundMatrix.Fields[d.X, d.Y].Stone, true); // Und die Drag-Eigenschaft erneuern |
338 | StoneDraggingAllow(TFieldVclData(PlayGroundMatrix.Fields[d.X, d.Y].Data).Stone, true); // Und die Drag-Eigenschaft erneuern |
322 | {$ENDREGION} |
339 | {$ENDREGION} |
323 | 340 | ||
324 | {$REGION 'Sind weitere Sprünge möglich oder ist das Spiel vorbei?'} |
341 | {$REGION 'Sind weitere Sprünge möglich oder ist das Spiel vorbei?'} |
325 | if not PlayGroundMatrix.CanJump(Level.GameMode = gmDiagonal) then |
342 | if not PlayGroundMatrix.CanJump(Level.GameMode = gmDiagonal) then |
326 | begin |
343 | begin |
Line 377... | Line 394... | ||
377 | begin |
394 | begin |
378 | if f.FieldType = ftFullSpace then exit; |
395 | if f.FieldType = ftFullSpace then exit; |
379 | 396 | ||
380 | index := PlaygroundMatrix.CoordToIndex(x, y); |
397 | index := PlaygroundMatrix.CoordToIndex(x, y); |
381 | 398 | ||
- | 399 | if not Assigned(f.Data) then f.Data := TFieldVclData.Create; |
|
382 | f.Panel := DrawStoneBox(x, y, index, f.indent, f.Goal); |
400 | TFieldVclData(f.Data).Panel := DrawStoneBox(x, y, index, f); |
383 | f.Stone := DrawStone(f.FieldType, f.Panel); |
401 | TFieldVclData(f.Data).Stone := DrawStone(f); |
384 | end; |
402 | end; |
385 | 403 | ||
386 | procedure TMainForm.TimerTimer(Sender: TObject); |
404 | procedure TMainForm.TimerTimer(Sender: TObject); |
387 | begin |
405 | begin |
388 | if MPauseTime.Checked then exit; |
406 | if MPauseTime.Checked then exit; |
Line 422... | Line 440... | ||
422 | max_y := 0; |
440 | max_y := 0; |
423 | for x := Low(PlaygroundMatrix.Fields) to High(PlaygroundMatrix.Fields) do |
441 | for x := Low(PlaygroundMatrix.Fields) to High(PlaygroundMatrix.Fields) do |
424 | begin |
442 | begin |
425 | for y := Low(PlaygroundMatrix.Fields[x]) to High(PlaygroundMatrix.Fields[x]) do |
443 | for y := Low(PlaygroundMatrix.Fields[x]) to High(PlaygroundMatrix.Fields[x]) do |
426 | begin |
444 | begin |
427 | if TPlayGroundMatrix.FieldState(PlaygroundMatrix.Fields[x,y].FieldType) = fsOccupied then |
445 | if PlaygroundMatrix.Fields[x,y].FieldState = fsOccupied then |
428 | Inc(LevelTotalStones); |
446 | Inc(LevelTotalStones); |
429 | DrawField(x, y, PlaygroundMatrix.Fields[x,y]); |
447 | DrawField(x, y, PlaygroundMatrix.Fields[x,y]); |
430 | p := PlaygroundMatrix.Fields[x,y].Panel; |
448 | p := TFieldVclData(PlaygroundMatrix.Fields[x,y].Data).Panel; |
431 | if Assigned(p) then |
449 | if Assigned(p) then |
432 | begin |
450 | begin |
433 | max_x := Max(max_x, p.Left + p.Width); |
451 | max_x := Max(max_x, p.Left + p.Width); |
434 | max_y := Max(max_y, p.Top + p.Height); |
452 | max_y := Max(max_y, p.Top + p.Height); |
435 | end; |
453 | end; |
Line 660... | Line 678... | ||
660 | procedure TMainForm.MHelpClick(Sender: TObject); |
678 | procedure TMainForm.MHelpClick(Sender: TObject); |
661 | begin |
679 | begin |
662 | HelpForm.ShowModal; |
680 | HelpForm.ShowModal; |
663 | end; |
681 | end; |
664 | 682 | ||
- | 683 | { TFieldVclData } |
|
- | 684 | ||
- | 685 | destructor TFieldVclData.Destroy; |
|
- | 686 | begin |
|
- | 687 | if Assigned(Stone) then Stone.Free; |
|
- | 688 | if Assigned(Panel) then Panel.Free; |
|
- | 689 | inherited; |
|
- | 690 | end; |
|
- | 691 | ||
665 | end. |
692 | end. |