Writing Hangman during India’s January chills and of course an Indian wedding has been a hell of an experience. Up until Breakout game, which is assignment #4 of Stanford’s Introduction to Computer Science course, it felt like walking with crutches. A lot of structure and program snippets were provided indirectly by iconic professor Mehran Sahami in his lectures. Not so much in Hangman.
Hangman taught me several aspects of programming. I have had particular troubles with managing the size of window in the
acm library backed course. There are two type of Java programs I have encountered. Although I am technically unaware of their subtleties but Application always opened in a 200px square window whereas Applet had parameters to define size of the window.
canvas which is an object of class
HangmanCanvas() created a dual pane for console and graphical aspect of the program.
Due to weariness of the great Indian wedding I didn’t decompose my implementation from beginning. It was a mistake. After certain point of time it became impossibly hard for me. I understand how primitive types are passed by value and objects are passed by reference but my dash object kept behaving like a primitive type which prevented me from applying more objected oriented programming to my program.
Intuitively, I think it would be much more simpler to ask for input at one single point. It is always tricky to trigger something without asking any input before hand. Consequently, I had to ask for user-guessed-letter at several instances checking for illegal guesses. Although it requires more reading of other people’s code to learn how things are done in wild for both what is simpler and appropriate object-orientedness of a program.
Most of the run method and rest of the program was pretty straight forward. It comprised of following all the instructions of the Hangman Game.
I could also have better implemented HangmanCanvas class but I opted for mere copy pasting coordinating the lines to make it run perfectly well. I could have added a little more invars to make my program more readable. Oh! well. I had to finish the program as soon as possible so that I can get to Android programming which is my primary goal.
Overall being able to solve problems is a very self-affirming experience. I particularly enjoyed solving how to make letter’s show in right order and using null pointer.
In the end, I have a strong urge to say what Woody Allen said in Annie Hall,”..there goes another novel..”
Code can be found in my Github repo.