B4J Code Snippet Tower of Hanoi (with solution)

Tower of Hanoi (with solution)

Eliminated modal form and replaced by Callback; Erel suggestion.
This eliminated the unwanted effect on form.
Thank Erel.
 

Attachments

  • TowerOfHanoi-3.zip
    355.6 KB · Views: 339
  • THanoi.jpg
    THanoi.jpg
    106.4 KB · Views: 382
Last edited:

Beja

Expert
Licensed User
Longtime User
Great, thanks for sharing.. a couple of comments

1- The animation is a little slow.. make it faster
2- Allow deselect.. now the app forces you to continue with the disk to another destination and bring it back when you make a mistake.
 

BeneBarros

Active Member
Licensed User
Longtime User
Nice. I see that you are using a transparent modal form to stop the code execution until the animation ends. The downside of this is that it causes the main form to lose focus and it is noticeable.

I would have used a callback sub instead that will run when the animation completes.
Thanks for the tip ... I will change
Great, thanks for sharing.. a couple of comments

1- The animation is a little slow.. make it faster
2- Allow deselect.. now the app forces you to continue with the disk to another destination and bring it back when you make a mistake.
1 - You can change the speed before starting the solution
2 - The rule is that the larger disks does not overlap the lower ... and the application blocks this possibility.
Thanks for the comments
 

Beja

Expert
Licensed User
Longtime User
2 - The rule is that the larger disks does not overlap the lower ... and the application blocks this possibility.
Thanks for the comments

Understand.. but the large disk is taken from above one that's larger than it.. so my suggestion is to allow the player to cancel the movement if she clicked again on the disk at the same original location. Just like computer chess.. one click on the piece selects it, another resets the selection.
I wrote this game in 1997 using QuickBasic 4.5 compiler.. when clicked on a disk it hovered above the column then you can either put it on another (bigger) disk or put it back on the same place.. I don't see here this function. (to put it back in case of a mistake)

Yet another point:
You put the first disk in column 2
You put the second disk in column 3
Then the application does not allow you to pick up the third disk from column 1.. I understand you can't put it in either columns because it's bigger than both, but you give the player the right to make a mistake.. let him pick it up but not put it down over any of the smaller two and play some error sounds until he put it back and try another solution. Now you are shielding the player from making a mistake.. in some way game is helping the player in the solution (partly)
 
Last edited:

BeneBarros

Active Member
Licensed User
Longtime User
Understand.. but the large disk is taken from above one that's larger than it.. so my suggestion is to allow the player to cancel the movement if she clicked again on the disk at the same original location. Just like computer chess.. one click on the piece selects it, another resets the selection.
I wrote this game in 1997 using QuickBasic 4.5 compiler.. when clicked on a disk it hovered above the column then you can either put it on another (bigger) disk or put it back on the same place.. I don't see here this function. (to put it back in case of a mistake)

Yet another point:
You put the first disk in column 2
You put the second disk in column 3
Then the application does not allow you to pick up the third disk from column 1.. I understand you can't put it in either columns because it's bigger than both, but you give the player the right to make a mistake.. let him pick it up but not put it down over any of the smaller two and play some error sounds until he put it back and try another solution. Now you are shielding the player from making a mistake.. in some way game is helping the player in the solution (partly)
Understand.. but the large disk is taken from above one that's larger than it.. so my suggestion is to allow the player to cancel the movement if she clicked again on the disk at the same original location. Just like computer chess.. one click on the piece selects it, another resets the selection.
I wrote this game in 1997 using QuickBasic 4.5 compiler.. when clicked on a disk it hovered above the column then you can either put it on another (bigger) disk or put it back on the same place.. I don't see here this function. (to put it back in case of a mistake)

Yet another point:
You put the first disk in column 2
You put the second disk in column 3
Then the application does not allow you to pick up the third disk from column 1.. I understand you can't put it in either columns because it's bigger than both, but you give the player the right to make a mistake.. let him pick it up but not put it down over any of the smaller two and play some error sounds until he put it back and try another solution. Now you are shielding the player from making a mistake.. in some way game is helping the player in the solution (partly)
I understood what you meant ... and considers this as a wrong move?
I will give a rethought the algorithm
Thanks for the sugestion.

I also add a checkbox "No animation" list only in tableview
 

Beja

Expert
Licensed User
Longtime User
Yes now we are on the same page.. if the player picked a big disk but didn't find a place to put it, then he will put it back and try another disk from another column.. this way he will lose time and his final duration until he solves it will be longer.. he will know this bad result is because he wasted time in wrong movement and will play again :)
 

BeneBarros

Active Member
Licensed User
Longtime User
Yes now we are on the same page.. if the player picked a big disk but didn't find a place to put it, then he will put it back and try another disk from another column.. this way he will lose time and his final duration until he solves it will be longer.. he will know this bad result is because he wasted time in wrong movement and will play again :)
Yes now we are on the same page.. if the player picked a big disk but didn't find a place to put it, then he will put it back and try another disk from another column.. this way he will lose time and his final duration until he solves it will be longer.. he will know this bad result is because he wasted time in wrong movement and will play again :)
ok ... I understand ... I will start to make changes and add a chronometer.
 
Top