Note: This homework should be done in the groups established in class (not necessarily your project groups). It is a learning exercise and will not be graded, however, students should take it seriously and try to reflect on the process, especially on any difficulties they faced when trying to integrate the pieces together!
P.S. I have decided to make the final (integration) stage an individual homework. Please upload your solutions to Moodle as indicated below.
In the game of Hangman the player must find a word chosen secretly by the program. The player can try one letter at a time and the program says how many times and where the letter appears in the secret word. If the player tries more than a certain number of incorrect letters (i.e. letters which do not appear in the secret word), they lose the game and the program tells them the secret word, otherwise they continue until they uncover the complete word.
Usually, players are able to see the partially formed word made by the letters so far correctly guessed, any unknown letters being left blank. They may also be able to see the set of all letters that might be in the word (with those already used possibly being removed), as well as the number of incorrect tries made so far (this is often shown graphically, by the number of visible body parts of a cartoon character which is hung when complete -hence the name of the game!)
set all letters to English alphabet, set max allowed incorrect tries to 6, number of incorrect tries to 0, used letters to empty set, secret word to result of calling choose secret word method, knownSoFar to StringBuffer of same length as secret word, but all characters are stars ('*').
returns number of times the letter occurs in the secret word. Adds letter to used letters. Updates known so far to show the letter at each position it exists in secret word. If the letter is not in secret word then increment number of incorrect tries. Method should return error values to indicate if the letter is not valid (-1), if the letter was already used (-2), and indicate if game over (-3).
returns a word chosen at random from a fixed array of words (defined in program code.) Also write another version of the method that reads the set of words from a text file and selects one from that.
play the game, by creating an instance of Hangman class and allowing the user to interact with it (in text mode using the keyboard only.) The program must repeatedly get letters from the user and try them...
The following division of work has been decided upon and allocated to specific groups during class:
Please email your Java code as an attachment to
david@cs.bilkent.edu.tr
with subject line "CS102 - Hangman - SecSS - pieceNoX"
(e.g. "CS102 - Hangman - Sec01 - pieceNo2 " for the Section 01 group doing the
constructor)
Be sure your code includes the names of all the people in the group.
Due dates (for individual pieces):
I will combine the pieces into a single zip file and publish them here as soon as I can after the deadline.
Revised procedure - I have decided to make this stage an individual homework
As soon as it is available, you should download the complete set of code pieces for your section and attempt to get the whole program working. Please keep a record of what you did, in particular, what went wrong and how you went about fixing it, but also, think about why the problems occurred in the first place and what might be done to avoid similar difficulties in the future. Include a text file containing these reflections together with your code when you upload your work to Moodle.
Note: Please do not look at the code from other sections, at least until after the exercise is completed!
Sec01_Hangman.zip (10/2/2012 - 21:30)
Sec02_Hangman.zip (13/2/2012 - 13:10)
Sec03_Hangman.zip (13/2/2012 - 21:00)
Please upload your completed solution to the Moodle activity for your section, SecSS_HW1 (as a zipped JCreator project, called SS_HW1_yourname.zip as for the lab assignments).
Please upload your work (code & reflections) before the lab session (even if it is incomplete), so the TAs can look at it too.
It will not be graded as such, however, you will get zero if you fail to upload the code and reflections!
Good luck!