[Browse] [Tag cloud]

Log on:
Powered by Elgg

Pip Turner :: Blog :: Pattern Matching Project - Hangman game - Project review

March 23, 2011


Project Review and Conclusions


The most significant thing that I have learnt from producing my hangman game in C++ is how classes can be used and how they can integrate with each other. I chose to use C++ because I was not as familiar with it as I was with C and I have learnt much about object orientation and the additional libraries available in C++ e.g. ‘string.h’. It is evident that I still have much to learn though. For example my original plan was to transfer strings between classes but for some reason C++ does not make this easy when strings are private. To overcome this problem I decided to use a limited array but this is something I hope to learn how to do in the future as this limits the length of movie titles (that are guessed by the user) in my file that can be accessed.


Another key thing learnt is how to access files. I had not done this before producing this program and by attempting it I have learnt much about where files need to be placed in order to open them easily and how to get certain lines of characters from files. This was a problem I had to overcome. I had to access a random line in a file. I found that I had to use the getline function and a temporary buffer to overcome it.


Something that might seem trivial that I have ascertained is when to use = and when to use ==. This produced a major error in my program and it took me a couple of hours staring at my program to work out why my ‘if statements’ and ‘while statements’ were not working. I have learnt from this and will be looking out for this syntactical mistake in the future.


I have also learnt more about how to compile a program in linux and the errors that may occur when moving from the windows environment to this operating system. For example, in linux my program could not access my file because it had capitals in it (as linux is case sensitive). I also discovered that I had to use g++ to compile my program rather than gcc as this only compiles C programs. In addition I realised not to void my constructors and destructors in linux.


I have also found out how to create a timer in C++ using time.h and the difftime function. In addition to discovering how to use the || syntax to effectively create an ‘or’ in an ‘if statement’. This I needed to be able to recognise both upper case ‘A’ and lower case ‘a’ at the same time. Moreover I have realised to be very careful about using a division in a calculation just in case the denominator becomes 0 and how to use a string and the string.length function to stop the user from entering more than one char. All of these aspects I believe will be useful as I continue to use C++.


If I was to begin this project again I would probably alter the class structure slightly and have more control of displays from the main function. At the moment one of my class’ functions does a lot of outputting to the display and I understand this is bad practice. I would also learn more about transferring unlimited arrays of chars (such as strings and char*) from one class to another so as to get rid of the limitation of 100 characters on the movie titles in the file accessed. I would also like to get rid of a small error to do with spaces in a string causing more than one error message to be displayed. To further update the project I would like to create an anagram game that runs alongside the hangman game and can be accessed from the main menu. I would also like to store the high scores in an external file so they are not lost after the game is completed. Finally I would like to use other databases of words and sentences to increase the ability of hangman (for example it could be used to learn words in a language other than English). 


Posted by Pip Turner | Share

You must be logged in to post a comment.

/