Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
60 lines (45 sloc) 2.05 KB


JavaScript code to create Tower of Hanoi game.

Version: 0.1

This code itself is not a jQuery plugin, but this code needs jQuery and jQuery UI to run. Make sure jQuery and jQuery UI are loaded first before create the Game instance.


First, you need block container for your game instance in your html document. jQuery and jQuery UI must be loaded before this script. The following example is the simple way to put it altogether:

  <div id="game-container"></div>
  <script src="js/jquery-1.7.1.min.js"></script>
  <script src="js/jquery-ui.min.js"></script>
  <script src="js/TowerOfHanoi.min.js?v=0.1"></script>

Create Tower of Hanoi game instance by calling Game constructor:

jQuery(function() {
  game = new Game();

Creating Game object without any options passed to constructor will create pegs with droppable behavior and discs with draggable behavior. You need to declare your own rule for the game, example_02.html gives you the basic overview for the rule of the game.


There are three working examples, with commented code as guide, to give you a brief view on how this code can be used in several ways. All examples are provided in root directory of this repository.


Live demo of this example:


Live demo of this example:


Live demo of this example:

jQuery and jQuery UI versions

This code has been tested with jQuery 1.7.1 and jQuery UI 1.8.16 (both versions included in js directory). You may help me by testing the code with other jQuery and jQuery UI versions.

Supported Browsers

Chrome 16, Firefox 4. You may help me by testing the code with other browsers.


Copyright (c) 2012 Akeda Bagus Licensed under MIT ( license.