25 May 2013

Hangman - Part 3

Welcome back, good to see all of you again. I hope your week was nice. We are developing our hangman game in an object oriented fashion therefore we need to identify some objects in our game. It's a good thing we have use cases because that's what we use to find those objects. Remember back in elementary school when you would have to identify the parts of a sentence? It's kind of like that. We also want to look for thinks that these objects know and things that it does.

Lets start with UC_001 and just go through them all listing objects as we come across them and putting what they know underneath as we find those as well. You'll have a better understanding by seeing it.
  • System/Game (Since our system is a game I'm going to start calling it game instead of system)
    • Type
    • Difficulty
That's it for UC_001, let's keep going
  • Game
    • Play Music
    • Draw Stand
    • Draw Lines
    • Display Letter
    • Move Letter
    • Display X
    • Progress Hangman
    • Animate Cursor
    • Time
    • Show Score
    • Show Hint
    • Show Error/Game over
  • Hangman Stand
    • Progression
  • Word
    • Letters
    • Category
  • High Score Table
    • Top 5
Alright, lets talk. The game is our main player here. From the looks of it the game is going to ask the other objects info about themselves so that it can display the state of the game properly. For example, the game will ask the word object if a letter is in the word and if not it'll ask the hangman stand what to draw next. The high score table object knows who's currently on the list so the game can act accordingly when the player is done with a game.

CRC Cards


Lets use all of this information to generate CRC cards or Class Responsibility Collaboration cards. It's a long name but they're not so bad. Check out the wiki link to get a better understanding of them. Their page is better than ones we've seen previously. The CRC card is usually written on a note card with the following fields.
Class Name - This should be a noun because objects are things. We picked out these already. Game, Word, Hangman Stand. These are our name for CRC cards.
ID - Give each card an ID for easy reference.
Description - Like the use cases give the class a short description.
Associated Use Cases - This is for easy reference to the stories this class is a part of.
Responsibilities - This includes what it does and what it knows, basically the things we listed under the objects in the list above. What it does will be methods that the class will have and what it knows will be data. Getters and setters are understood and don't need to be listed.
 Collaborators - This is the other classes that it works with. This can be just through association like between game and word or it can be another type of relationship like we talked about in a previous post.

Lets make our cards now...
...
...
Alright do you have your cards?

The reason we make these cards is so that we can role play! That's right grab your D&D group or your LARPing friends and hand out some CRC cards. Go through each step in a use case and play out as your class. Here's the trick though, it's what changes this from a typical Friday night into software engineering, you can only respond with your methods. I'll give an example to break the ice.
Game: "I need to display blank lines. Word how may letters do you have?"
Word: "I have 5 letters."
You see, game just called word's getNumLetters() method. It would be a data value that Word keeps in an int. As you role play each use case fill in any missing methods or data that a class should have but was forgotten.

Lets role play...
...
...
Ok that's enough of that. I hope your CRC cards are nice and full. The more fleshed out they are the easier things will be later. I still need to make my CRC cards but I may post a picture of them along with the class diagram next week. This brings us to our next topic.

Class diagrams


At this stage the things a class knows should be primitive data types. Lets talk about what those are. Integers, Booleans, Long, Float, Short, Char, Double, String. For this purpose strings can be considered primitive. We do this to see reduce complexity. If you need a complex data type it can come latter. As an example lets think about Java's Date object. If you need your object to store a Date what can you do? well internally Date stores its' data as a Long. You could simply make a variable of type long and call it date or you can list Date in the collaborators section.

My class diagrams will mostly conform to UML standards. Wikipedia has a great page on class diagrams that I suggest you look at. Using our CRC cards convert the info into class diagrams. Be sure to show relationships between the different classes. Since I'm on Linux I like to use Umbrello to make my diagrams. Wikipedia says it works on Unix like and Windows so give it a shot. Otherwise check out a list of tools here.

That's it for today. Next week I'll have my Class diagram made up. I'll share it with you and explain it a little more. Until then, keep coding.

No comments:

Post a Comment