Showing posts with label Console application. Show all posts
Showing posts with label Console application. Show all posts

Tuesday, June 26, 2018

Tower of Hanoi - 7 - c sharp - 180626Tu

  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.



Saturday, July 15, 2017

console barmenu -3- c sharp - 170714Fr

  Console BarMenu - 3  
.
(DOS era text-mode style Colorful Bar-Menu in c#)
Version: 170714Fr
.
During the era of DOS 3, creating a bar menu in text or graphic mode was a cutting-edge topic in programming. I vividly remember writing a ".prg" program in dBase III Plus on my institute's PC, which impressed my friends, lab assistants, and teachers. That program was my first attempt at creating a bar menu, and I'm proud to say it was a success. Although I'm not sure if the printout of that program still exists in my archives, I'm not eager to find out also. In memory of that bar menu, I've now recreated that bar menu as a Console project in C#.
.
Salient  features of above mentioned c# project are as follows:
(A) Display bar-menu.
(B) Provide menu-item selection mechanism through navigation keys like Up-arrow, Down-arrow, Home, End and Enter keys.
(C) Process menu-item selection and perform action accordingly.
(D) Return back to menu at end of action processed.
(E) Provide mechanism for exiting from 'bar-menu' and application.
.
Then I tried and made the above required project. Code for achieving above task is simple and is described as follows.
(1) First menu processing method is called. There must be one such method per menu.
(2) Then from menu processing method menu-driver method is called with information like menu-item-list etc.
(3) Then in menu-driver things happen in following sequence:
(3a) First menu is displayed.
(3b) Then user-input is taken.
(3c) Then user-input is processed based on input key as follows:
(3c1) Navigation key: Selected menuitem index is updated.
(3c2) Enter key: Current menuitem index is selected for returning.
(3c3) Escape key: Menu exit code is selected for returning.
(3c4) If user input is not Escape-Key or Enter-Key go back to step 3a.
(3c5) Menu-driver exits when user-input is Escape-Key or Enter-Key.
(4) Back in menu processing method returned value is processed as follows:
(4a) Respective methods are called according to returned value. On return control goes back to step 2.
(4b) Else menu exits when selection code is Escape-Key.
.
Keys used by menu are displayed in menu footer and are described in the following:
Navigation:
Down-arrow key for next menuitem.
Up-arrow key for previous menuitem.
Home key for First menuitem.
End key for last menuitem.
Selection:
Ente key for selecting current menuitem.
Exit:
Escape key for exiting menu.
.
Following is the C# code of the project I described above. It is not so simple or easy to understand. But it is full of helpful comments throughout it.
.

.
Code of "Console BarMenu - 3" in Visual C# 2010
.

.
Application Output
Following are some screen-shots of the application I took at different state of application to explain the application's look and feel.
.
Application is loaded
(When Application is loaded.)
.
.
Application Menu bar navigation
(When selection bar is on first menu-item)
.
(When selection bar is on last menu-item)
.
(When selection bar is on some other menu-item)
.
.
Application Menu item selected
When menu's any selection bar is selected by pressing ENTER key and application is moved to the respective section.
.
(When 'Grains and cereals' menu-item is selected and respective method is run)
.
(When 'Vegetables' menu-item is selected and respective method is run)
.
(When 'Bakery & Confectionery Products' menu-item is selected and respective method is run)
.

.
Method which displays message based on menu selection,  randomly selects background for console screen from a few dark ConsoleColors making display a little colorful.
.

.
A brief overview of Console application:
In the context of C#, a Console Application is a type of program that interacts with users through the command-line interface. This type of application reads input from the user through the standard input stream (STDIN), processes the input, and then displays output to the user through the standard output stream (STDOUT). Additionally, any error messages or exceptions are directed to the standard error stream (STDERR). Console Applications are commonly used for tasks that require user input, such as command-line tools, utilities, and interactive programs. They provide a simple and efficient way to interact with the user, making them a fundamental part of the C# programming landscape.
.

.
If there are any mistakes then I will surely remove them whenever found.
.

.
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.
.


Monday, July 3, 2017

ConsoleColor demo -2- C Sharp - 170703Mo

  ConsoleColor Demo - 2  
.
(Displays all foreground colors on all background colors in c#)
Version: 170703Mo
.
To check how text in any possible foreground ConsoleColor on any possible background ConsoleColor looks like I made a Console project in C Sharp. I also made basic requirement for the project as this:
(A) Display line of text in all ConsoleColors in its default sequence using one line for one color.
(B) Use navigation keys to change console background color in ConsoleColor default sequence, in any direction.
(C) Provide mechanism for exiting from application.
.
Then I tried and made the above required project. Code for achieving above task is simple and is described as follows.
(1) First all ConsoleColors are saved in an array in their default sequence.
(2) Then a do-while loop starts.
(3) In start of this loop console background color is set to first color in ConsoleColor array and console is cleared.
(*) Application also displays useful information near top and bottom of screen on black bars. At top current background color is also displayed. Both info-bars are displayd from inside of do-while loop at different places.
(4) Then in a for loop all alphabets in upper case then all digits then all alphabets in lower case are displayed  in all colors from ConsoleColor array, using one line for text in one color.
(5) Then user input is taken and according to input:
(5a) Console background color index is changed as follows:
(*) Up-arrow, Backspace, Left-arrow, Page-Up, E, S, NumPad8, NumPad4 and NumPad9 keys are used for selecting previous  color in ConsoleColor array. 
(*) Down-arrow, Spacebar, Right-arrow, Page-Down, D, F, NumPad2, NumPad6 and NumPad3 keys are used for selecting next color in ConsoleColor array.
(*) Home and NumPad7 key is used for selecting first color in ConsoleColor array
(*) End and NumPad1 key is used for selecting last color in ConsoleColor array.
(5b) In step 2 started do-while loop either continues or Exit. X and Escape keys are used for exiting loop.
(6) After loop exit application also ends after restoring defaults.
.
In the following table keys which can be used for performing different tasks are listed.
Navigation Keys
Action Keys
Exit
X Escape
Next Color
UpArrow PageUp LeftArrow Backspace E
NumPad8 NumPad9 NumPad4 S
Previous Color
DownArrow PageDown RightArrow Spacebar D
NumPad2 NumPad3 NumPad6 F
First Color
Home NumPad7
Last Color
End NumPad1
.
Exit is for exiting application. Remaining tasks are for selecting background console color. No matter 'Num Lok' key is on or off its buttons will work in same way for navigation.
Following is the C# code of the project I described above. It is simple and easy to understand. Plus it is full of helpful comments throughout it.
.

.
Visual C# 2010 Code
.

.
Application Output
Following are screenshots of the application I took at different stages of application.
.
(When Application is loaded.)
.
(When Background color is Black)
.
(When Background color is Blue)
.
(When Background color is Cyan)
.
(When Background color is DarkBlue)
.
(When Background color is DarkCyan)
.
(When Background color is DarkGray)
.
(When Background color is DarkGreen)
.
(When Background color is DarkMagenta)
.
(When Background color is DarkRed)
.
(When Background color is DarkYellow)
.
(When Background color is Gray)
.
(When Background color is Green)
.
(When Background color is Magenta)
.
(When Background color is Red)
.
(When Background color is White)
.
(When Background color is Yellow)
.

.
[2024 July 29 Thu] Note:- Previously I had shared three sample screen shots of the application and today I removed those images and shared 17 new screen-shots of application in it's all possible stages..
.

.
If there are any mistakes then I will surely remove them whenever found.
.

.
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.
.