mercredi 17 avril 2019

Design problem: Coordinate system with multiple dimensions and shapes

Background:

Boards for games typically contain squares, hexes, octagons, or some other type of location. The games are not limited to 2-D boards, e.g. 3-D chess.

Every type of Coordinate should be able to provide the following information:

  • distance to another coordinate
  • direction to another coordinate
  • the set of neighboring coordinates

I am trying, for a homework question, to design a Coordinate class that is able to be used in any type of board game. In order to do so, I need to support any number of dimensions and different shaped locations.

Given this information, how might I design the Coordinates so that they will support all variations, even those not currently envisioned? I'm having trouble getting my feet off the ground with this - namely, I'm unsure which design pattern sounds best. Adapter? Factory? Creation?

Would love a nudge in the right direction! Looking to make a UML diagram representing this design.

Aucun commentaire:

Enregistrer un commentaire