Forum > Games

TOWERS of Hanoi: Drop and Snap Help Needed


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.

Проверьте свою процедуру 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.

Maybe for some ideas:,66541.msg510240.html#msg510240
(nothing really to do with your problem)

First... on Windows you don't see the discs. You forgot this line:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---    pieceLabel[j].Transparent := false;
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.

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.


[0] Message Index

Go to full version