Reputation: 9
I have question connected with MVC in pure C#.
public int level;
public int money;
with button AddLevel, which triggers broadcast message
"PlayerView.LevelUP"
The controller receive message PlayerView.LevelUp and do something like this:
PlayerModel.level++;
PlayerView.Update();
List of available shop items
Displays List of items
When button buy is clicked for specific item the message is send:
"ShopView.BuyItem.{id}, price"
and the problem occurs here. I don't know how to substract the money from my PlayerModel. Should I use:
playerModel =- price;
or should I use reference to the PlayerController and do something like this:
playerController.SubstractMoney(price);
The problem might be more complex when we would like to add the Confirmation Window - are you sure to buy the item? With ConfirmationWindowView, ConfirmationController, ConfirmationModel?
Upvotes: 0
Views: 75
Reputation: 156
Each of your class should have a single responsibility according to SOLID principles. Shop controller is different than player controller, same as the models. Break your project into Presentation (View), Business(Controller) and Data (Model) layers. Your controllers will contain all business logic while the data layer will provide data.
Upvotes: 1
Reputation: 216
Your approach can completely depend upon the scenarios how you want to make a call. You can create a seperate viewmodel for combined shop + player.
Regarding your 3rd point - ShopController: You can either make an ajax call or call action method directly(playerController.SubstractMoney(price);) It depends on your calls.
For confirmation window: you can use jquery modal popups or any 3rd pop ups eg: foundation.js. Make a global popup(with a global id) and then you can call it from any view.
Upvotes: 0