Rev 21 | Rev 23 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 21 | Rev 22 | ||
---|---|---|---|
Line 62... | Line 62... | ||
62 | procedure SaveSettings; |
62 | procedure SaveSettings; |
63 | procedure RestartLevel; |
63 | procedure RestartLevel; |
64 | procedure SetNewPlayGroundMatrix(Matrix: TPlayGroundMatrix); |
64 | procedure SetNewPlayGroundMatrix(Matrix: TPlayGroundMatrix); |
65 | procedure RedrawStonesFromMatrix(Matrix: TPlayGroundMatrix); |
65 | procedure RedrawStonesFromMatrix(Matrix: TPlayGroundMatrix); |
66 | function AskForLevel: String; |
66 | function AskForLevel: String; |
67 | function AreJumpsPossible: boolean; |
- | |
68 | procedure StoneDraggingAllow(Stone: TImage; Allow: boolean); |
67 | procedure StoneDraggingAllow(Stone: TImage; Allow: boolean); |
69 | procedure NewGame(Filename: string); |
68 | procedure NewGame(Filename: string); |
70 | function LevelTime: String; |
69 | function LevelTime: String; |
71 | procedure DestroyLevel; |
70 | procedure DestroyLevel; |
72 | procedure RefreshTime; |
71 | procedure RefreshTime; |
73 | procedure RefreshPoints; |
72 | procedure RefreshPoints; |
74 | procedure RefreshStonesRemoved; |
73 | procedure RefreshStonesRemoved; |
75 | procedure CountPoints(t: TFieldType); |
- | |
76 | procedure RemoveStone(x, y: integer; count_points: boolean); |
74 | procedure RemoveStone(x, y: integer; count_points: boolean); |
77 | procedure DoJump(SourceTag, DestTag: integer); |
75 | procedure DoJump(SourceTag, DestTag: integer); |
78 | function CanJump(x, y: integer): boolean; |
- | |
79 | function MayJump(SourceX, SourceY, DestX, DestY: integer): boolean; overload; |
- | |
80 | function MayJump(SourceTag, DestTag: integer): boolean; overload; |
76 | function MayJump(SourceTag, DestTag: integer): boolean; overload; |
81 | procedure StoneDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); |
77 | procedure StoneDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); |
82 | procedure StoneDragDrop(Sender, Source: TObject; X, Y: Integer); |
78 | procedure StoneDragDrop(Sender, Source: TObject; X, Y: Integer); |
83 | function DrawField(x, y: integer; t: TFieldProperties; indent: integer): TField; |
79 | function DrawField(x, y: integer; t: TFieldProperties; indent: integer): TField; |
84 | function DrawStone(fieldtype: TFieldType; panel: TPanel): TImage; |
80 | function DrawStone(fieldtype: TFieldType; panel: TPanel): TImage; |
Line 235... | Line 231... | ||
235 | procedure TMainForm.RefreshPoints; |
231 | procedure TMainForm.RefreshPoints; |
236 | begin |
232 | begin |
237 | Statistics.Panels.Items[2].Text := Format(LNG_POINTS, [Points]); |
233 | Statistics.Panels.Items[2].Text := Format(LNG_POINTS, [Points]); |
238 | end; |
234 | end; |
239 | 235 | ||
240 | procedure TMainForm.CountPoints(t: TFieldType); |
- | |
241 | begin |
- | |
242 | inc(Points, FieldTypeWorth(t)); |
- | |
243 | RefreshPoints; |
- | |
244 | end; |
- | |
245 | - | ||
246 | procedure TMainForm.RemoveStone(x, y: integer; count_points: boolean); |
236 | procedure TMainForm.RemoveStone(x, y: integer; count_points: boolean); |
247 | begin |
237 | begin |
248 | if count_points then |
238 | if count_points then |
249 | begin |
239 | begin |
250 | CountPoints(PlayGroundMatrix.Fields[x, y].FieldType); |
240 | Inc(Points, FieldTypeWorth(PlayGroundMatrix.Fields[x, y].FieldType)); |
- | 241 | RefreshPoints; |
|
- | 242 | ||
251 | Inc(LevelRemovedStones); |
243 | Inc(LevelRemovedStones); |
252 | RefreshStonesRemoved; |
244 | RefreshStonesRemoved; |
253 | end; |
245 | end; |
254 | PlayGroundMatrix.Fields[x, y].FieldType := ftEmpty; |
246 | PlayGroundMatrix.Fields[x, y].FieldType := ftEmpty; |
255 | LoadPictureForType(PlayGroundMatrix.Fields[x, y].FieldType, PlayGroundMatrix.Fields[x, y].Stone.Picture); |
247 | LoadPictureForType(PlayGroundMatrix.Fields[x, y].FieldType, PlayGroundMatrix.Fields[x, y].Stone.Picture); |
256 | StoneDraggingAllow(PlayGroundMatrix.Fields[x, y].Stone, false); |
248 | StoneDraggingAllow(PlayGroundMatrix.Fields[x, y].Stone, false); |
257 | end; |
249 | end; |
258 | 250 | ||
259 | function TMainForm.CanJump(x, y: integer): boolean; |
- | |
260 | begin |
- | |
261 | if PlayGroundMatrix.FieldState(x, y) <> fsStone then |
- | |
262 | begin |
- | |
263 | result := false; |
- | |
264 | exit; |
- | |
265 | end; |
- | |
266 | - | ||
267 | result := true; |
- | |
268 | - | ||
269 | if MayJump(x, y, x+2, y) then exit; |
- | |
270 | if MayJump(x, y, x-2, y) then exit; |
- | |
271 | if MayJump(x, y, x, y+2) then exit; |
- | |
272 | if MayJump(x, y, x, y-2) then exit; |
- | |
273 | - | ||
274 | if Level.GetGameMode = gmDiagonal then |
- | |
275 | begin |
- | |
276 | if MayJump(x, y, x-2, y-2) then exit; |
- | |
277 | if MayJump(x, y, x+2, y-2) then exit; |
- | |
278 | if MayJump(x, y, x-2, y+2) then exit; |
- | |
279 | if MayJump(x, y, x+2, y+2) then exit; |
- | |
280 | end; |
- | |
281 | - | ||
282 | result := false; |
- | |
283 | end; |
- | |
284 | - | ||
285 | procedure TMainForm.Aboutthislevel1Click(Sender: TObject); |
251 | procedure TMainForm.Aboutthislevel1Click(Sender: TObject); |
286 | var |
252 | var |
287 | mode: string; |
253 | mode: string; |
288 | goalYeSNo: string; |
254 | goalYeSNo: string; |
289 | resourcestring |
255 | resourcestring |
Line 291... | Line 257... | ||
291 | LNG_MODE = 'Mode: %s'; |
257 | LNG_MODE = 'Mode: %s'; |
292 | LNG_STONES_TOTAL = 'Stones: %d'; |
258 | LNG_STONES_TOTAL = 'Stones: %d'; |
293 | LNG_GOAL_AVAILABLE = 'Target field defined'; |
259 | LNG_GOAL_AVAILABLE = 'Target field defined'; |
294 | LNG_NO_GOAL = 'No target field'; |
260 | LNG_NO_GOAL = 'No target field'; |
295 | begin |
261 | begin |
296 | if Level.GetGameMode = gmDiagonal then |
262 | case Level.GameMode of |
297 | mode := 'Diagonal' |
263 | gmNormal: mode := 'Diagonal'; |
298 | else if Level.GetGameMode = gmNormal then |
264 | gmDiagonal: mode := 'Normal'; |
299 | mode := 'Normal' |
265 | gmUndefined: mode := '?'; |
300 | else |
266 | end; |
301 | mode := '?'; |
- | |
302 | 267 | ||
303 | if GoalStatus = gsNoGoal then |
268 | if GoalStatus = gsNoGoal then |
304 | goalYeSNo := LNG_NO_GOAL |
269 | goalYeSNo := LNG_NO_GOAL |
305 | else |
270 | else |
306 | goalYeSNo := LNG_GOAL_AVAILABLE; |
271 | goalYeSNo := LNG_GOAL_AVAILABLE; |
Line 310... | Line 275... | ||
310 | Format(LNG_MODE, [mode]) + #13#10 + |
275 | Format(LNG_MODE, [mode]) + #13#10 + |
311 | Format(LNG_STONES_TOTAL, [LevelTotalStones]) + #13#10 + |
276 | Format(LNG_STONES_TOTAL, [LevelTotalStones]) + #13#10 + |
312 | goalYesNo); |
277 | goalYesNo); |
313 | end; |
278 | end; |
314 | 279 | ||
315 | function TMainForm.AreJumpsPossible: boolean; |
- | |
316 | var |
- | |
317 | i, j: integer; |
- | |
318 | begin |
- | |
319 | result := false; |
- | |
320 | for i := Low(PlayGroundMatrix.Fields) to High(PlayGroundMatrix.Fields) do |
- | |
321 | begin |
- | |
322 | for j := Low(PlayGroundMatrix.Fields[i]) to High(PlayGroundMatrix.Fields[i]) do |
- | |
323 | begin |
- | |
324 | if CanJump(i, j) then |
- | |
325 | begin |
- | |
326 | result := true; |
- | |
327 | break; |
- | |
328 | end; |
- | |
329 | if result then break; |
- | |
330 | end; |
- | |
331 | end; |
- | |
332 | end; |
- | |
333 | - | ||
334 | procedure TMainForm.DoJump(SourceTag, DestTag: integer); |
280 | procedure TMainForm.DoJump(SourceTag, DestTag: integer); |
335 | resourcestring |
281 | resourcestring |
336 | LNG_JUMP_LOG = '%d [%d, %d] -> %d [%d, %d];'; |
282 | LNG_JUMP_LOG = '%d [%d, %d] -> %d [%d, %d];'; |
337 | var |
283 | var |
338 | d, s: TPoint; |
284 | d, s: TPoint; |
Line 345... | Line 291... | ||
345 | s := LookupFieldCoordinateArray[SourceTag]; |
291 | s := LookupFieldCoordinateArray[SourceTag]; |
346 | 292 | ||
347 | JumpHistory.Add(Format(LNG_JUMP_LOG, [SourceTag+1, s.x+1, s.y+1, DestTag+1, d.x+1, d.y+1])); |
293 | JumpHistory.Add(Format(LNG_JUMP_LOG, [SourceTag+1, s.x+1, s.y+1, DestTag+1, d.x+1, d.y+1])); |
348 | 294 | ||
349 | {$REGION 'Stein entfernen und Punkte vergeben'} |
295 | {$REGION 'Stein entfernen und Punkte vergeben'} |
350 | if Level.GetGameMode = gmDiagonal then |
296 | if Level.GameMode = gmDiagonal then |
351 | begin |
297 | begin |
352 | if (s.X-2 = d.X) and (s.Y-2 = d.Y) and (PlayGroundMatrix.FieldState(s.X-1, s.Y-1) = fsStone) then RemoveStone(s.X-1, s.Y-1, true); |
298 | if (s.X-2 = d.X) and (s.Y-2 = d.Y) and (PlayGroundMatrix.FieldState(s.X-1, s.Y-1) = fsStone) then RemoveStone(s.X-1, s.Y-1, true); |
353 | if (s.X-2 = d.X) and (s.Y+2 = d.Y) and (PlayGroundMatrix.FieldState(s.X-1, s.Y+1) = fsStone) then RemoveStone(s.X-1, s.Y+1, true); |
299 | if (s.X-2 = d.X) and (s.Y+2 = d.Y) and (PlayGroundMatrix.FieldState(s.X-1, s.Y+1) = fsStone) then RemoveStone(s.X-1, s.Y+1, true); |
354 | if (s.X+2 = d.X) and (s.Y-2 = d.Y) and (PlayGroundMatrix.FieldState(s.X+1, s.Y-1) = fsStone) then RemoveStone(s.X+1, s.Y-1, true); |
300 | if (s.X+2 = d.X) and (s.Y-2 = d.Y) and (PlayGroundMatrix.FieldState(s.X+1, s.Y-1) = fsStone) then RemoveStone(s.X+1, s.Y-1, true); |
355 | if (s.X+2 = d.X) and (s.Y+2 = d.Y) and (PlayGroundMatrix.FieldState(s.X+1, s.Y+1) = fsStone) then RemoveStone(s.X+1, s.Y+1, true); |
301 | if (s.X+2 = d.X) and (s.Y+2 = d.Y) and (PlayGroundMatrix.FieldState(s.X+1, s.Y+1) = fsStone) then RemoveStone(s.X+1, s.Y+1, true); |
Line 377... | Line 323... | ||
377 | LoadPictureForType(PlayGroundMatrix.Fields[d.X, d.Y].FieldType, PlayGroundMatrix.Fields[d.X, d.Y].Stone.Picture); // Stein an neue Position malen |
323 | LoadPictureForType(PlayGroundMatrix.Fields[d.X, d.Y].FieldType, PlayGroundMatrix.Fields[d.X, d.Y].Stone.Picture); // Stein an neue Position malen |
378 | StoneDraggingAllow(PlayGroundMatrix.Fields[d.X, d.Y].Stone, true); // Und die Drag-Eigenschaft erneuern |
324 | StoneDraggingAllow(PlayGroundMatrix.Fields[d.X, d.Y].Stone, true); // Und die Drag-Eigenschaft erneuern |
379 | {$ENDREGION} |
325 | {$ENDREGION} |
380 | 326 | ||
381 | {$REGION 'Sind weitere Sprünge möglich oder ist das Spiel vorbei?'} |
327 | {$REGION 'Sind weitere Sprünge möglich oder ist das Spiel vorbei?'} |
382 | if not AreJumpsPossible then |
328 | if not PlayGroundMatrix.CanJump(Level.GameMode = gmDiagonal) then |
383 | begin |
329 | begin |
384 | MPauseTime.Checked := false; |
330 | MPauseTime.Checked := false; |
385 | MPauseTime.Enabled := false; |
331 | MPauseTime.Enabled := false; |
386 | Timer.Enabled := false; |
332 | Timer.Enabled := false; |
387 | RefreshTime; |
333 | RefreshTime; |
Line 405... | Line 351... | ||
405 | SetLength(PrevPlaygroundMatrixes, Length(PrevPlaygroundMatrixes)+1); |
351 | SetLength(PrevPlaygroundMatrixes, Length(PrevPlaygroundMatrixes)+1); |
406 | PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1] := PlaygroundMatrix.CloneMatrix; |
352 | PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1] := PlaygroundMatrix.CloneMatrix; |
407 | MUndo.Enabled := true; |
353 | MUndo.Enabled := true; |
408 | end; |
354 | end; |
409 | 355 | ||
410 | function TMainForm.MayJump(SourceX, SourceY, DestX, DestY: integer): boolean; |
- | |
411 | begin |
- | |
412 | result := false; |
- | |
413 | - | ||
414 | // Check 1: Ist das Zielfeld überhaupt leer? |
- | |
415 | if PlayGroundMatrix.FieldState(DestX, DestY) <> fsAvailable then exit; |
- | |
416 | - | ||
417 | // Check 2: Befindet sich ein Stein zwischen Source und Destination und ist der Abstand 2? |
- | |
418 | if Level.GetGameMode = gmDiagonal then |
- | |
419 | begin |
- | |
420 | if (SourceX-2 = DestX) and (SourceY-2 = DestY) and (PlayGroundMatrix.FieldState(SourceX-1, SourceY-1) = fsStone) then result := true; |
- | |
421 | if (SourceX-2 = DestX) and (SourceY+2 = DestY) and (PlayGroundMatrix.FieldState(SourceX-1, SourceY+1) = fsStone) then result := true; |
- | |
422 | if (SourceX+2 = DestX) and (SourceY-2 = DestY) and (PlayGroundMatrix.FieldState(SourceX+1, SourceY-1) = fsStone) then result := true; |
- | |
423 | if (SourceX+2 = DestX) and (SourceY+2 = DestY) and (PlayGroundMatrix.FieldState(SourceX+1, SourceY+1) = fsStone) then result := true; |
- | |
424 | end; |
- | |
425 | - | ||
426 | if (SourceX+2 = DestX) and (SourceY = DestY) and (PlayGroundMatrix.FieldState(SourceX+1, SourceY ) = fsStone) then result := true; |
- | |
427 | if (SourceX-2 = DestX) and (SourceY = DestY) and (PlayGroundMatrix.FieldState(SourceX-1, SourceY ) = fsStone) then result := true; |
- | |
428 | if (SourceX = DestX) and (SourceY+2 = DestY) and (PlayGroundMatrix.FieldState(SourceX , SourceY+1) = fsStone) then result := true; |
- | |
429 | if (SourceX = DestX) and (SourceY-2 = DestY) and (PlayGroundMatrix.FieldState(SourceX , SourceY-1) = fsStone) then result := true; |
- | |
430 | end; |
- | |
431 | - | ||
432 | function TMainForm.MayJump(SourceTag, DestTag: integer): boolean; |
356 | function TMainForm.MayJump(SourceTag, DestTag: integer): boolean; |
433 | var |
357 | var |
434 | s, d: TPoint; |
358 | s, d: TPoint; |
435 | begin |
359 | begin |
436 | d := LookupFieldCoordinateArray[DestTag]; |
360 | d := LookupFieldCoordinateArray[DestTag]; |
437 | s := LookupFieldCoordinateArray[SourceTag]; |
361 | s := LookupFieldCoordinateArray[SourceTag]; |
438 | 362 | ||
439 | result := MayJump(s.X, s.Y, d.X, d.Y); |
363 | result := PlaygroundMatrix.CanJump(s.X, s.Y, d.X, d.Y, Level.GameMode = gmDiagonal); |
440 | end; |
364 | end; |
441 | 365 | ||
442 | procedure TMainForm.StoneDragDrop(Sender, Source: TObject; X, Y: Integer); |
366 | procedure TMainForm.StoneDragDrop(Sender, Source: TObject; X, Y: Integer); |
443 | begin |
367 | begin |
444 | DoJump(TComponent(Source).Tag, TComponent(Sender).Tag); |
368 | DoJump(TComponent(Source).Tag, TComponent(Sender).Tag); |
Line 552... | Line 476... | ||
552 | LevelFile := Filename; |
476 | LevelFile := Filename; |
553 | Level := TLevel.Create(LevelFile); |
477 | Level := TLevel.Create(LevelFile); |
554 | LevelArray := Level.LevelStringToLevelArray(true); |
478 | LevelArray := Level.LevelStringToLevelArray(true); |
555 | if Length(LevelArray) = 0 then Exit; |
479 | if Length(LevelArray) = 0 then Exit; |
556 | BuildPlayground(LevelArray); |
480 | BuildPlayground(LevelArray); |
557 | if not AreJumpsPossible then |
481 | if not PlayGroundMatrix.CanJump(Level.GameMode = gmDiagonal) then |
558 | begin |
482 | begin |
559 | MessageDlg(LNG_LVL_INVALID_NO_JUMP, mtError, [mbOk], 0); |
483 | MessageDlg(LNG_LVL_INVALID_NO_JUMP, mtError, [mbOk], 0); |
560 | end; |
484 | end; |
561 | RefreshTime; |
485 | RefreshTime; |
562 | RefreshStonesRemoved; |
486 | RefreshStonesRemoved; |