Rev 24 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 24 | Rev 25 | ||
---|---|---|---|
Line 4... | Line 4... | ||
4 | 4 | ||
5 | uses |
5 | uses |
6 | SysUtils, Dialogs, Functions, ExtCtrls, Classes, Math; |
6 | SysUtils, Dialogs, Functions, ExtCtrls, Classes, Math; |
7 | 7 | ||
8 | type |
8 | type |
9 | TCoord = record |
- | |
10 | X: integer; |
- | |
11 | Y: integer; |
- | |
12 | end; |
- | |
13 | - | ||
14 | TFieldType = (ftUndefined, ftFullSpace, ftEmpty, ftRed, ftYellow, ftGreen); |
9 | TFieldType = (ftUndefined, ftFullSpace, ftEmpty, ftRed, ftYellow, ftGreen); |
15 | 10 | ||
- | 11 | TFieldState = (fsUndefined, fsLocked, fsAvailable, fsOccupied); |
|
- | 12 | ||
16 | TGameMode = (gmUndefined, gmNormal, gmDiagonal); |
13 | TGameMode = (gmUndefined, gmNormal, gmDiagonal); |
17 | 14 | ||
18 | TLevelError = (leUndefined, leNone, leInvalidElement, leEmptyBoard, leRowInvalidLength, |
15 | TLevelError = (leUndefined, leNone, leInvalidElement, leEmptyBoard, |
19 | leUnsupportedVersion, leUnsupportedMode); |
16 | leRowInvalidLength, leUnsupportedVersion, leUnsupportedMode); |
- | 17 | ||
- | 18 | TGoalStatus = (gsUndefined, gsNoGoal, gsMultipleStonesRemaining, |
|
- | 19 | gsLastStoneInGoalRed, gsLastStoneInGoalYellow, |
|
- | 20 | gsLastStoneInGoalGreen, gsLastStoneOutsideGoal); |
|
- | 21 | ||
- | 22 | TCoord = record |
|
- | 23 | X: integer; |
|
- | 24 | Y: integer; |
|
- | 25 | end; |
|
20 | 26 | ||
21 | TField = record |
27 | TField = record |
22 | Indent: integer; |
28 | Indent: integer; |
23 | FieldType: TFieldType; |
29 | FieldType: TFieldType; |
24 | Goal: Boolean; |
30 | Goal: Boolean; |
25 | Panel: TPanel; |
31 | Panel: TPanel; |
26 | Stone: TImage; |
32 | Stone: TImage; |
27 | end; |
33 | end; |
28 | 34 | ||
29 | TGoalStatus = (gsUndefined, gsNoGoal, gsMultipleStonesRemaining, gsLastStoneInGoalRed, gsLastStoneInGoalYellow, gsLastStoneInGoalGreen, gsLastStoneOutsideGoal); |
- | |
30 | - | ||
31 | TFieldState = (fsUndefined, fsLocked, fsAvailable, fsOccupied); |
- | |
32 | - | ||
33 | TPlayGroundMatrix = record |
35 | TPlayGroundMatrix = record |
34 | Fields: array of array of TField; |
36 | Fields: array of array of TField; |
35 | public |
37 | public |
36 | procedure InitFieldArray(width, height: integer); |
38 | procedure InitFieldArray(width, height: integer); |
37 | function MatrixHasGoal: boolean; |
39 | function MatrixHasGoal: boolean; |
- | 40 | function GoalStatus(StonesRemaining: integer): TGoalStatus; |
|
38 | function GoalFieldType: TFieldType; |
41 | function GoalFieldType: TFieldType; |
39 | function MatrixWorth: integer; |
42 | function MatrixWorth: integer; |
40 | procedure ClearMatrix(FreeVCL: boolean); |
43 | procedure ClearMatrix(FreeVCL: boolean); |
41 | function CloneMatrix: TPlayGroundMatrix; |
44 | function CloneMatrix: TPlayGroundMatrix; |
42 | class function FieldState(t: TFieldType): TFieldState; overload; static; |
45 | class function FieldState(t: TFieldType): TFieldState; overload; static; |
43 | function FieldState(f: TField): TFieldState; overload; |
46 | function FieldState(f: TField): TFieldState; overload; |
44 | function FieldState(x, y: integer): TFieldState; overload; |
47 | function FieldState(x, y: integer): TFieldState; overload; |
- | 48 | function FieldState(c: TCoord): TFieldState; overload; |
|
45 | function CanJump(SourceX, SourceY, DestX, DestY: integer; DiagonalOK: boolean): boolean; overload; |
49 | function CanJump(SourceX, SourceY, DestX, DestY: integer; DiagonalOK: boolean): boolean; overload; |
46 | function CanJump(Source, Dest: TCoord; DiagonalOK: boolean): boolean; overload; |
50 | function CanJump(Source, Dest: TCoord; DiagonalOK: boolean): boolean; overload; |
47 | function CanJump(SourceX, SourceY: integer; DiagonalOK: boolean): boolean; overload; |
51 | function CanJump(SourceX, SourceY: integer; DiagonalOK: boolean): boolean; overload; |
48 | function CanJump(Source: TCoord; DiagonalOK: boolean): boolean; overload; |
52 | function CanJump(Source: TCoord; DiagonalOK: boolean): boolean; overload; |
49 | function CanJump(DiagonalOK: boolean): boolean; overload; |
53 | function CanJump(DiagonalOK: boolean): boolean; overload; |
Line 70... | Line 74... | ||
70 | 74 | ||
71 | function FieldTypeWorth(t: TFieldType): integer; |
75 | function FieldTypeWorth(t: TFieldType): integer; |
72 | 76 | ||
73 | implementation |
77 | implementation |
74 | 78 | ||
- | 79 | uses |
|
- | 80 | Constants; |
|
- | 81 | ||
75 | function FieldTypeWorth(t: TFieldType): integer; |
82 | function FieldTypeWorth(t: TFieldType): integer; |
76 | begin |
83 | begin |
77 | if t = ftGreen then result := 10 |
84 | if t = ftGreen then result := WORTH_GREEN |
78 | else if t = ftYellow then result := 20 |
85 | else if t = ftYellow then result := WORTH_YELLOW |
79 | else if t = ftRed then result := 30 |
86 | else if t = ftRed then result := WORTH_RED |
80 | else result := 0; |
87 | else result := 0; |
81 | end; |
88 | end; |
82 | 89 | ||
83 | { TPlayGroundMatrix } |
90 | { TPlayGroundMatrix } |
84 | 91 | ||
Line 94... | Line 101... | ||
94 | result := result or Fields[x,y].Goal; |
101 | result := result or Fields[x,y].Goal; |
95 | end; |
102 | end; |
96 | end; |
103 | end; |
97 | end; |
104 | end; |
98 | 105 | ||
- | 106 | function TPlayGroundMatrix.GoalStatus(StonesRemaining: integer): TGoalStatus; |
|
- | 107 | var |
|
- | 108 | ft: TFieldType; |
|
- | 109 | begin |
|
- | 110 | if not MatrixHasGoal then |
|
- | 111 | result := gsNoGoal |
|
- | 112 | else if StonesRemaining > 1 then |
|
- | 113 | Result := gsMultipleStonesRemaining |
|
- | 114 | else |
|
- | 115 | begin |
|
- | 116 | ft := GoalFieldType; |
|
- | 117 | if ft = ftRed then |
|
- | 118 | result := gsLastStoneInGoalRed |
|
- | 119 | else if ft = ftYellow then |
|
- | 120 | result := gsLastStoneInGoalYellow |
|
- | 121 | else if ft = ftGreen then |
|
- | 122 | result := gsLastStoneInGoalGreen |
|
- | 123 | else |
|
- | 124 | result := gsUndefined; |
|
- | 125 | end; |
|
- | 126 | end; |
|
- | 127 | ||
99 | function TPlayGroundMatrix.GoalFieldType: TFieldType; |
128 | function TPlayGroundMatrix.GoalFieldType: TFieldType; |
100 | var |
129 | var |
101 | x, y: integer; |
130 | x, y: integer; |
102 | begin |
131 | begin |
103 | result := ftEmpty; // Damit der Compiler nicht meckert |
132 | result := ftEmpty; // Damit der Compiler nicht meckert |
Line 208... | Line 237... | ||
208 | function TPlayGroundMatrix.CoordToIndex(x, y: integer): integer; |
237 | function TPlayGroundMatrix.CoordToIndex(x, y: integer): integer; |
209 | begin |
238 | begin |
210 | result := x + y * Width; |
239 | result := x + y * Width; |
211 | end; |
240 | end; |
212 | 241 | ||
- | 242 | function TPlayGroundMatrix.FieldState(c: TCoord): TFieldState; |
|
- | 243 | begin |
|
- | 244 | result := FieldState(c.X, c.Y); |
|
- | 245 | end; |
|
- | 246 | ||
213 | function TPlayGroundMatrix.CoordToIndex(coord: TCoord): integer; |
247 | function TPlayGroundMatrix.CoordToIndex(coord: TCoord): integer; |
214 | begin |
248 | begin |
215 | result := CoordToIndex(coord.X, coord.Y); |
249 | result := CoordToIndex(coord.X, coord.Y); |
216 | end; |
250 | end; |
217 | 251 |