Game class diagram

一世执手 提交于 2019-11-28 02:07:04

You actually have a pretty good start at an analysis model. An analysis model should represent the domain, which in this case is the world of your game. If you convert the nouns into classes and the verbs you already have into association-end properties, a first version of your analysis model will fall out. (But, make sure the classes are singular, not plural.) One way to do this conversion is to make a bullet list of natural-language sentences, in both directions, such as:

  • Game represented by [one or more] Fields
  • Field represents [one] Game
  • Field identified by [one] Coordinate
  • Coordinate identifies [one] Field
  • Settlement contained in [zero or one] Field
  • Field contains [zero or one] Settlement
  • . . .

(I think it may be premature for you to take on superclasses, abstract classes, and interfaces since you're asking about the basics here. Please ask another more specific question after you have more experience under your belt.)

You can then convert the association-end-property names into participial phrases to look more normal in your target OO language, while still retaining semantics. These participial phrases tell the reader of your code the purpose of the association, as well as disambiguate multiple associations between two classes for different purposes. Here are some examples of what I mean by participial phrases (i.e., verb phrases used as adjectives), used as role names:

  • |Game| -representedGame-----representingField- |Field|
  • |Field| -identifiedField-----identifyingCoordinate- |Coordinate|
  • |Settlement| -containedSettlement----containingField- |Field|
  • . . .

At this point, make a list of verbs, representing the things you want your classes to accomplish. These are your operations. Sometimes it is obvious which class should be responsible for an operation; other times you have to anthropomorphize.

Now, code methods for those operations using graphical and I/O libraries, and you have yourself a game!

For more information, I highly recommend you read Leon Starr's How to Build Articulate UML Models article or H. S. Lahman's book, Model-Based Development: Applications.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!