Tower of Hanoi in c#
|
. |
(Console application) |
Version: 180626Tu |
. |
Long time ago, for the first time, I came to know about 'Tower of Hanoi' puzzle
game through a book on 'C/Turbo C' and another book on 'Data structure'. Both
these books were in our course and both books were very good. |
. |
|
. |
Turbo C's
that book was and still is
|
. |
The Waite Group's
|
Turbo C
|
Programming for the PC
|
By
|
(Robert Lafore)
|
|
|
. |
|
. |
Data Structure's
that book was and still is
|
. |
Schaum's Outline of
|
THEORY AND PROBLEMS
|
of
|
DATA
|
STRUCTURES
|
Seymour Lipschutz, Ph.D
|
McGRAW-Hill BOOK COMPANY
|
|
|
. |
|
. |
In 'C/Turbo C'
book there was an example program for playing 'Tower of Hanoi' puzzle game
(Chapter #: 16, Chapter name: C++ and Object-Oriented Programming,
Section: Towers of Hanoi) and in
'Data structure' book there
were 2 example algorithms for solving 'Tower of
Hanoi' puzzle game (Chapter #: 6, Chapter name: STACKS, QUEUES,
RECURSION, Section: 6.7 - TOWERS OF HANOI). |
As far as i remember now, then I wrote both examples in 'Turbo C' and enjoyed
playing with game as well as with code. That code was simple but good for
'C/Turbo C' learning level. Then time fast forwarded for around a decade
and this time I made 'Tower of Hanoi' puzzle game in 'HTML / JScript' using beautiful and solid FrontPage. This time Game environment was much advance
then before and more colorful also. |
Again time fast forwarded for around a decade and this time in
memory of my last efforts for 'Tower of Hanoi' I decided to re-make that puzzle game in c#.
Because I was making this version in memory of last 2 efforts plus more so this time I
made it as (a) 'Console application' and (b) 'Windows Forms application'. |
Here in this post, in the following paragraphs, I am sharing 'Console
application' version of 'Tower of Hanoi' puzzle game made by me in c#. |
.. |
Salient features of application:
|
This puzzle game is one player console based game. This puzzle game is controlled
/ played by keyboard keys. What keys are required when, is always displayed on
screen. Mostly alphabets and arrow keys are required. |
. |
Screen shots of 'TowerOfHanoi_07' with description: |
Following are screen shots of
'TowerOfHanoi_07' at different stages with their
description. |
. |
Application on Load: |
'TowerOfHanoi_07'
console application looks like in the following image when it loads. Author
information is displayed on top row. Under that in green rectangle are displayed
(a)_Game objective and (b)_Rules. Under that a prompt is displayed asking
user how many disks he/she wants to play with. At the bottom of the screen is
status line which displays (a)_Application mode 'Input' meaning application is
expecting an input from user and (b)_Status message (Message tells what User needs to do or what Application is doing at
any stage). |
. |
|
. |
|
. |
Game started: (Move disk from) |
When none '0' (on '0' game quits) number of disks is entered in first screen
game starts and following screen is displayed. Second line from top line tells
what is expected / required from player. 3rd line form top tells (a) min.
numbers of moves required for solving current puzzle and (b) current move
number. Under 3rd line 3 towers in red (with selected number of disks on it in
yellow colors), blue and green color are displayed. On line under towers game asks for and gets tower name for moving disk from. On status line useful
information is displayed. Pressing 'X' here will end this game and take to
first screen. |
. |
|
. |
|
. |
Game started: (Move disk to) |
In this screen every thing is same as in 'Game started: (Move disk from)' screen
except this time game is asking for and getting tower name for moving disk to.
On status line useful information is displayed. Pressing 'X' here will end this
game and take to first screen. |
. |
|
. |
|
. |
Game after some moves:
|
'TowerOfHanoi_07' will look like in the following image after some moves. |
. |
|
. |
|
. |
Game completed:
|
'TowerOfHanoi_07'
looks like in the following image when it is completed. In 3rd line after Move #
it is announced that game is completed. On line under tower a message is
displayed to congratulate player and also tells in how many moves game is
completed and in how much time. Under this line a message is displayed to tell
player what to do now. In status line 'Message' field also 'Game completed!' is
displayed. |
. |
|
. |
|
. |
Game aborted:
|
'TowerOfHano_07' looks like in the following image when
game is aborted by pressing 'X' when it asks for From or To tower. In 3rd line
after Move # Aborted is displayed. On line under tower a message is displayed
telling that current game is aborted after so many moves and in so much time. On
line under this a message is displayed telling user what to do now. In status
line in 'Message' field also 'Game aborted.' is displayed. |
. |
|
. |
|
. |
Exiting TowerOfHanoi_07:
|
'TowerOfHanoi_07' looks like in the following image when
'0' is pressed in 'get number of towers screen'. In this screen 1st row from top
displays author information. Under that in a green rectangle (a)_departing
message is displayed (b)_Time spent on game is displayed (c)_A message is
displayed telling user what to do now. In status line on bottom of screen after
'Message' field 'Exiting from application . . .' is displayed.
|
. |
|
. |
|
. |
[Note] During making screen shots of 'TowerOfHanoi_07' and adding water
marks in those images I came across a small problem. That problem was that my
water marks were in color and they were not looking good to me on black
background. So to solve that problem I made a "Windows Forms
application"/"WinForms" in c# for changing any/all colors in water
mark image to white color. Water marks in images in this post are result of that
application.
|
. |
|
. |
Enjoy
Complete
Source code of application written and compiled in visual studio 2010 Ultimate by me.
Download it. Extract it. Read 'ReadMeFirst.txt' file and do as is explained in
it. |
|
No comments:
Post a Comment