Game class diagram

2019-01-15 20:49发布

I have a problem with taking a class diagram for a game. The world in which the game takes place, can be represented by fields. Each field is identified by the coordinates x and y. The field may be convenient to establish a settlement or not. If there is a settlement on the field, the only one. Each field is linked to a landscape as a bitmap. In some fields, there may be resources (eg coal, ore), or other artifacts which are not proprietary. Each player is the ruler of a principality. May belong to the Duchy of many settlements. The Principality of nationality and citizenship designates settlements truck. The settlers are citizens of the duchy through belonging to one of the settlements of the principality. The settlement may, however, live in different nations, whose nationality does not coincide with citizenship. Individual nations living in village characterized by loyalty to the principality, which owns the village. For the settlers imposed a head tax, which every week has to be diverted to the principality. Taxes feed the treasury of the duchy. Too high taxes lowers the morale of the settlers. Collected funds for in importance to the maintenance of buildings and armies. In the villages you can put different types of buildings. Some of them can be built only a single copy of each settlement (eg, ditch), others in larger quantities (eg, plant furrier). To the sediment was in the building, part of the settlers must work as a builder of a specified number of hours and must be available appropriate products and raw materials for their construction. ¬ precipitate diameter of each day may work in other occupations (such as armorer, scouts). To the settlers could carry out their jobs, usually the appropriate buildings are required (such as a forge, sawmill). Most workers provide artifacts - manufactures products (eg, a blacksmith, a farmer) or producing natural resources (eg, a miner, a lumberjack). Manufacture of the product may be needed for some artifacts. Then, post workers, who by the requisite number of hours will work in production. The artifact, which was created as a result of the settlers, is a product. For the most backwards area of ​​the product to be Armor (eg, sword, chain mail) and food (eg bread, meat). The most important type of artifact that is not a product is a natural resource. To the pellet could be stored in the artifact more, you must build a warehouse.

I'm not even asking about all the task - i know it is large and time spending. I just would like to hear some suggestions, what to put as abstract class, what to put as interface here. What class should have operations to build a building? Thanks in advance for any your idea, event single sentence!

1条回答
趁早两清
2楼-- · 2019-01-15 21:31

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.

查看更多
登录 后发表回答