简体   繁体   中英

How to share an object between two Models in MVC?

I have two Models in my card game.

  1. HandModel - contains the list of instances of CardModel.
  2. BoardModel - contains instances of CardModel placed on the board with specific coordinates.

I want to pop a card instance from the HandModel list and place it in the BoardModel coordinates. I would like to send a Card between those two models, but I don't want to directly call BoardModel inside HandModel just for this reason. Not sure how should I do it.

You might want to design your model in a way in which the card model itself has some kind of location which can be updated by a controller which handles the cards. That way no model has to know any other model.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM