Rev 25 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 25 | Rev 26 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | unit LevelFunctions; |
1 | unit LevelFunctions; |
2 | 2 | ||
3 | interface |
3 | interface |
4 | 4 | ||
5 | uses |
5 | uses |
6 | SysUtils, Dialogs, Functions, ExtCtrls, Classes, Math; |
6 | SysUtils, Dialogs, Functions, Classes; |
7 | 7 | ||
8 | type |
8 | type |
9 | TFieldType = (ftUndefined, ftFullSpace, ftEmpty, ftRed, ftYellow, ftGreen); |
9 | TFieldType = (ftUndefined, ftFullSpace, ftEmpty, ftRed, ftYellow, ftGreen); |
10 | 10 | ||
11 | TFieldState = (fsUndefined, fsLocked, fsAvailable, fsOccupied); |
11 | TFieldState = (fsUndefined, fsLocked, fsAvailable, fsOccupied); |
Line 18... | Line 18... | ||
18 | TGoalStatus = (gsUndefined, gsNoGoal, gsMultipleStonesRemaining, |
18 | TGoalStatus = (gsUndefined, gsNoGoal, gsMultipleStonesRemaining, |
19 | gsLastStoneInGoalRed, gsLastStoneInGoalYellow, |
19 | gsLastStoneInGoalRed, gsLastStoneInGoalYellow, |
20 | gsLastStoneInGoalGreen, gsLastStoneOutsideGoal); |
20 | gsLastStoneInGoalGreen, gsLastStoneOutsideGoal); |
21 | 21 | ||
22 | TCoord = record |
22 | TCoord = record |
23 | X: integer; |
23 | X: integer; // fields. not pixels |
24 | Y: integer; |
24 | Y: integer; // fields. not pixels |
25 | end; |
25 | end; |
26 | 26 | ||
27 | TField = record |
27 | TField = record |
28 | Indent: integer; |
28 | Indent: integer; // half steps |
29 | FieldType: TFieldType; |
29 | FieldType: TFieldType; |
30 | Goal: Boolean; |
30 | Goal: Boolean; |
31 | Panel: TPanel; |
31 | Data: TObject; // can be used to hold VCL references. Is not cloned when calling CloneMatrix! |
32 | Stone: TImage; |
32 | function FieldState: TFieldState; |
33 | end; |
33 | end; |
34 | 34 | ||
35 | TPlayGroundMatrix = record |
35 | TPlayGroundMatrix = record |
36 | Fields: array of array of TField; |
36 | Fields: array of array of TField; |
37 | public |
37 | public |
Line 40... | Line 40... | ||
40 | function GoalStatus(StonesRemaining: integer): TGoalStatus; |
40 | function GoalStatus(StonesRemaining: integer): TGoalStatus; |
41 | function GoalFieldType: TFieldType; |
41 | function GoalFieldType: TFieldType; |
42 | function MatrixWorth: integer; |
42 | function MatrixWorth: integer; |
43 | procedure ClearMatrix(FreeVCL: boolean); |
43 | procedure ClearMatrix(FreeVCL: boolean); |
44 | function CloneMatrix: TPlayGroundMatrix; |
44 | function CloneMatrix: TPlayGroundMatrix; |
45 | class function FieldState(t: TFieldType): TFieldState; overload; static; |
- | |
46 | function FieldState(f: TField): TFieldState; overload; |
- | |
47 | function FieldState(x, y: integer): TFieldState; overload; |
45 | function FieldState(x, y: integer): TFieldState; overload; |
48 | function FieldState(c: TCoord): TFieldState; overload; |
46 | function FieldState(c: TCoord): TFieldState; overload; |
49 | function CanJump(SourceX, SourceY, DestX, DestY: integer; DiagonalOK: boolean): boolean; overload; |
47 | function CanJump(SourceX, SourceY, DestX, DestY: integer; DiagonalOK: boolean): boolean; overload; |
50 | function CanJump(Source, Dest: TCoord; DiagonalOK: boolean): boolean; overload; |
48 | function CanJump(Source, Dest: TCoord; DiagonalOK: boolean): boolean; overload; |
51 | function CanJump(SourceX, SourceY: integer; DiagonalOK: boolean): boolean; overload; |
49 | function CanJump(SourceX, SourceY: integer; DiagonalOK: boolean): boolean; overload; |
Line 206... | Line 204... | ||
206 | begin |
204 | begin |
207 | for x := Low(Fields) to High(Fields) do |
205 | for x := Low(Fields) to High(Fields) do |
208 | begin |
206 | begin |
209 | for y := Low(Fields[x]) to High(Fields[x]) do |
207 | for y := Low(Fields[x]) to High(Fields[x]) do |
210 | begin |
208 | begin |
211 | if Assigned(Fields[x,y].Stone) then Fields[x,y].Stone.Free; |
- | |
212 | if Assigned(Fields[x,y].Panel) then Fields[x,y].Panel.Free; |
209 | if Assigned(Fields[x,y].Data) then Fields[x,y].Data.Free; |
213 | end; |
210 | end; |
214 | end; |
211 | end; |
215 | end; |
212 | end; |
216 | SetLength(Fields, 0, 0); |
213 | SetLength(Fields, 0, 0); |
217 | end; |
214 | end; |
Line 226... | Line 223... | ||
226 | SetLength(result.Fields[x], Length(Fields[x])); |
223 | SetLength(result.Fields[x], Length(Fields[x])); |
227 | for y := Low(Fields[x]) to High(Fields[x]) do |
224 | for y := Low(Fields[x]) to High(Fields[x]) do |
228 | begin |
225 | begin |
229 | result.Fields[x,y].FieldType := Fields[x,y].FieldType; |
226 | result.Fields[x,y].FieldType := Fields[x,y].FieldType; |
230 | result.Fields[x,y].Goal := Fields[x,y].Goal; |
227 | result.Fields[x,y].Goal := Fields[x,y].Goal; |
231 | result.Fields[x,y].Panel := Fields[x,y].Panel; |
228 | result.Fields[x,y].Data := Fields[x,y].Data; |
232 | result.Fields[x,y].Stone := Fields[x,y].Stone; |
- | |
233 | end; |
229 | end; |
234 | end; |
230 | end; |
235 | end; |
231 | end; |
236 | 232 | ||
237 | function TPlayGroundMatrix.CoordToIndex(x, y: integer): integer; |
233 | function TPlayGroundMatrix.CoordToIndex(x, y: integer): integer; |
Line 247... | Line 243... | ||
247 | function TPlayGroundMatrix.CoordToIndex(coord: TCoord): integer; |
243 | function TPlayGroundMatrix.CoordToIndex(coord: TCoord): integer; |
248 | begin |
244 | begin |
249 | result := CoordToIndex(coord.X, coord.Y); |
245 | result := CoordToIndex(coord.X, coord.Y); |
250 | end; |
246 | end; |
251 | 247 | ||
252 | class function TPlayGroundMatrix.FieldState(t: TFieldType): TFieldState; |
- | |
253 | begin |
- | |
254 | result := fsUndefined; |
- | |
255 | case t of |
- | |
256 | ftFullSpace: result := fsLocked; |
- | |
257 | ftEmpty: result := fsAvailable; |
- | |
258 | ftGreen: result := fsOccupied; |
- | |
259 | ftYellow: result := fsOccupied; |
- | |
260 | ftRed: result := fsOccupied; |
- | |
261 | end; |
- | |
262 | end; |
- | |
263 | - | ||
264 | function TPlayGroundMatrix.FieldState(f: TField): TFieldState; |
- | |
265 | begin |
- | |
266 | result := FieldState(f.FieldType); |
- | |
267 | end; |
- | |
268 | - | ||
269 | function TPlayGroundMatrix.FieldState(x, y: integer): TFieldState; |
248 | function TPlayGroundMatrix.FieldState(x, y: integer): TFieldState; |
270 | begin |
249 | begin |
271 | result := fsUndefined; |
250 | result := fsUndefined; |
272 | if (x < Low(Fields)) or (x > High(Fields)) then exit; |
251 | if (x < Low(Fields)) or (x > High(Fields)) then exit; |
273 | if (y < Low(Fields[x])) or (y > High(Fields[x])) then exit; |
252 | if (y < Low(Fields[x])) or (y > High(Fields[x])) then exit; |
274 | 253 | ||
275 | result := FieldState(Fields[x,y]); |
254 | result := Fields[x,y].FieldState; |
276 | end; |
255 | end; |
277 | 256 | ||
278 | function TPlayGroundMatrix.CanJump(SourceX, SourceY, DestX, DestY: integer; DiagonalOK: boolean): boolean; |
257 | function TPlayGroundMatrix.CanJump(SourceX, SourceY, DestX, DestY: integer; DiagonalOK: boolean): boolean; |
279 | begin |
258 | begin |
280 | result := false; |
259 | result := false; |
Line 542... | Line 521... | ||
542 | 521 | ||
543 | { Wird hier nicht abgeprüft, da dafür zuerst der PlayGround gebaut sein muss. |
522 | { Wird hier nicht abgeprüft, da dafür zuerst der PlayGround gebaut sein muss. |
544 | Es ist außerdem eher ein logischer Fehler, kein Fehler in der Levelstruktur! } |
523 | Es ist außerdem eher ein logischer Fehler, kein Fehler in der Levelstruktur! } |
545 | end; |
524 | end; |
546 | 525 | ||
- | 526 | { TField } |
|
- | 527 | ||
- | 528 | function TField.FieldState: TFieldState; |
|
- | 529 | begin |
|
- | 530 | result := fsUndefined; |
|
- | 531 | case FieldType of |
|
- | 532 | ftFullSpace: result := fsLocked; |
|
- | 533 | ftEmpty: result := fsAvailable; |
|
- | 534 | ftGreen: result := fsOccupied; |
|
- | 535 | ftYellow: result := fsOccupied; |
|
- | 536 | ftRed: result := fsOccupied; |
|
- | 537 | end; |
|
- | 538 | end; |
|
- | 539 | ||
547 | end. |
540 | end. |