Changeset 32 for trunk/UGame.pas
- Timestamp:
- Oct 12, 2019, 11:01:10 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGame.pas
r31 r32 124 124 procedure Render(Canvas: TCanvas; CanvasSize: TPoint); 125 125 procedure MoveAll(Direction: TMoveDirection); 126 procedure MoveAllAnimate(Direction: TMoveDirection); 126 127 procedure MoveAllAndUpdate(Direction: TMoveDirection); 127 128 procedure MoveTile(SourceTile, TargetTile: TTile); … … 505 506 begin 506 507 case Direction of 507 drLeft: begin 508 Result := TArea.Create(1, 0, Board.Size.X - 1, Board.Size.Y - 1); 509 end; 510 drUp: begin 511 Result := TArea.Create(0, 1, Board.Size.X - 1, Board.Size.Y - 1); 512 end; 513 drRight: begin 514 Result := TArea.Create(Board.Size.X - 2, 0, 0, Board.Size.Y - 1); 515 end; 516 drDown: begin 517 Result := TArea.Create(0, Board.Size.Y - 2, Board.Size.X - 1, 0); 518 end; 508 drNone: Result := TArea.Create(0, 0, 0, 0); 509 drLeft: Result := TArea.Create(1, 0, Board.Size.X - 1, Board.Size.Y - 1); 510 drUp: Result := TArea.Create(0, 1, Board.Size.X - 1, Board.Size.Y - 1); 511 drRight: Result := TArea.Create(Board.Size.X - 2, 0, 0, Board.Size.Y - 1); 512 drDown: Result := TArea.Create(0, Board.Size.Y - 2, Board.Size.X - 1, 0); 519 513 end; 520 514 end; … … 629 623 RenderTile(Canvas, Board.Tiles[Y, X], TileRect); 630 624 end; 625 end; 626 627 procedure TGame.MoveAll(Direction: TMoveDirection); 628 var 629 P: TPoint; 630 PNew: TPoint; 631 I: Integer; 632 Area: TArea; 633 begin 634 if Direction = drNone then Exit; 635 if not CanMoveDirection(Direction) then Exit; 636 FMoving := True; 637 FBoardUndo.Assign(Board); 638 FCanUndo := True; 639 Area := GetMoveArea(Direction); 640 Board.ClearMerged; 641 for I := 0 to Max(Board.Size.X, Board.Size.Y) - 1 do begin 642 P := Area.P1; 643 while P.Y <> Area.P2.Y + Area.Increment.Y do begin 644 P.X := Area.P1.X; 645 while P.X <> Area.P2.X + Area.Increment.X do begin 646 PNew := P + DirectionDiff[Direction]; 647 if IsValidPos(PNew) then begin 648 if (Board.Tiles[P.Y, P.X].Value <> 0) then begin 649 if (Board.Tiles[PNew.Y, PNew.X].Value = 0) then begin 650 Board.Tiles[P.Y, P.X].Moving := True; 651 Board.Tiles[PNew.Y, PNew.X].Value := Board.Tiles[P.Y, P.X].Value; 652 Board.Tiles[PNew.Y, PNew.X].Merged := Board.Tiles[P.Y, P.X].Merged; 653 Board.Tiles[P.Y, P.X].Value := 0; 654 Board.Tiles[P.Y, P.X].Merged := False; 655 end else 656 if (not Board.Tiles[P.Y, P.X].Merged) and (not Board.Tiles[PNew.Y, PNew.X].Merged) and 657 (Board.Tiles[PNew.Y, PNew.X].Value = Board.Tiles[P.Y, P.X].Value) then begin 658 Board.Tiles[P.Y, P.X].Moving := True; 659 Board.Tiles[PNew.Y, PNew.X].Value := Board.Tiles[PNew.Y, PNew.X].Value + Board.Tiles[P.Y, P.X].Value; 660 Board.Tiles[PNew.Y, PNew.X].Merged := True; 661 Board.Tiles[P.Y, P.X].Value := 0; 662 Board.Tiles[P.Y, P.X].Merged := False; 663 Score := Score + Board.Tiles[PNew.Y, PNew.X].Value; 664 end; 665 end; 666 end; 667 Inc(P.X, Area.Increment.X); 668 end; 669 Inc(P.Y, Area.Increment.Y); 670 end; 671 DoChange; 672 end; 673 FMoving := False; 631 674 end; 632 675 … … 707 750 begin 708 751 Result := False; 752 if Direction = drNone then Exit; 709 753 Area := GetMoveArea(Direction); 710 754 P := Area.P1; … … 729 773 end; 730 774 731 procedure TGame.MoveAll (Direction: TMoveDirection);775 procedure TGame.MoveAllAnimate(Direction: TMoveDirection); 732 776 var 733 777 P: TPoint; … … 823 867 begin 824 868 HighestValue := Board.GetHighestTileValue; 825 MoveAll (Direction);869 MoveAllAnimate(Direction); 826 870 827 871 NewTile := FillRandomTile;
Note:
See TracChangeset
for help on using the changeset viewer.