Recent

Author Topic: TOWERS of Hanoi: Drop and Snap Help Needed  (Read 950 times)

Boleeman

  • Sr. Member
  • ****
  • Posts: 459
TOWERS of Hanoi: Drop and Snap Help Needed
« on: March 11, 2024, 03:25:47 am »
Hi All.

I found a CSharp Towers of Hanoi Game on Github and converted parts of it to Lazarus, but I was unable to get the drop and snap to position part of the Drag and Drop to work. Got the snap to bottom of peg to work, but the disk keeps on going to the top left form position on mouse up event.

Got the disks to size and place in the first spot.
Got the timer to work to time.

Wonder if anyone knowledgeable on Drag and Drop and Snap to position can help out?
Can't seem to sort it out and seem to be in a never ending loop at the moment.

« Last Edit: March 11, 2024, 03:29:35 am by Boleeman »

Seenkao

  • Hero Member
  • *****
  • Posts: 551
    • New ZenGL.
Re: TOWERS of Hanoi: Drop and Snap Help Needed
« Reply #1 on: March 11, 2024, 11:54:13 am »
Проверьте свою процедуру GetTargetPole, проблема либо в ней, либо в данных попадающих в неё. Вам необходимо научится пользоваться отладкой, тогда многие вопросы будут отпадать.

В вашей игре можно поднять несколько фишек не опустив ни одной. Сделайте проверку, чтоб этого невозможно было снять несколько фишек.

------------------------------
Google translate:
Check your procedure GetTargetPole, the problem is either in it or in the data falling into it. You need to learn how to use debugging, then many questions will disappear.

In your game, you can raise several chips without dropping any. Make a check so that it is impossible to remove several chips.
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

Zvoni

  • Hero Member
  • *****
  • Posts: 2362
Re: TOWERS of Hanoi: Drop and Snap Help Needed
« Reply #2 on: March 11, 2024, 12:23:48 pm »
Maybe for some ideas: https://forum.lazarus.freepascal.org/index.php/topic,66541.msg510240.html#msg510240
(nothing really to do with your problem)
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

rvk

  • Hero Member
  • *****
  • Posts: 6190
Re: TOWERS of Hanoi: Drop and Snap Help Needed
« Reply #3 on: March 11, 2024, 01:03:20 pm »
First... on Windows you don't see the discs. You forgot this line:
Code: Pascal  [Select][+][-]
  1.     pieceLabel[j].Transparent := false;

Second...
In PiecesMouseMove you correctly locate the targetpole (you see this because the disc snaps in place).
But when you release in PiecesMouseUp, you have wrong coordinates for X,Y.
You can also see this because you calculate the X,Y differently for TargetPole.

Make both the same and the disc will snap in place correctly.

Boleeman

  • Sr. Member
  • ****
  • Posts: 459
Re: TOWERS of Hanoi: Drop and Snap Help Needed
« Reply #4 on: March 13, 2024, 08:20:11 am »
Sorry about not replying earlier, but where I live we had a heat wave stretching over quite a number of days.


I will try out the advice given. Thank you to all who replied.

 

TinyPortal © 2005-2018