0
\$\begingroup\$

I am trying to implement a simple game "Bulls and cows" in c#. It is a final project of my university course about design patterns. The target of the game is simple - try to guess the opponent number.

http://github.com/snoward/BullsAndCows

I try to follow the MVC and dependency injection patterns. My problem is that I don't know what part of my program should be responsible for network connection. Is this a part of controller work?

I think that the best way is to create a new instance of network controller as server for my game. And then user choose UI to use (console or window). So, network controller must observe user's UI to update game model state.

\$\endgroup\$
  • \$\begingroup\$ The title of your question is broad from the matter you are asking about. Network support is not about who is in charge of networking in a software system. \$\endgroup\$ – liggiorgio Jun 8 '16 at 14:19
2
\$\begingroup\$

In a classic MVC world, the networking is split into a controller and a view component.

Network input is a controller, because it processes commands which then result in changes to the model.

The network output is a view, because it translates the model changes which are happening in your game into a network protocol. This is not much different from translating the model changes into pixels or console text.

Both the network controller and the network view depend on the same network connection, which is a dependency you should inject when you instantiate them.

When you follow these patterns, then it becomes very easy to implement different kinds of multiplayer, because the controllers and views used by a remote player, a local player or an AI player can all interact with the game through the same interfaces.

\$\endgroup\$
  • \$\begingroup\$ Sounds very nice. But can you support your answer with some examples? I think that network should be a model, which can be add to system if user wants this. \$\endgroup\$ – snoward Jun 8 '16 at 14:51
  • \$\begingroup\$ @MikhailPliskovsky What kind of example do you expect? \$\endgroup\$ – Philipp Jun 8 '16 at 14:58
  • \$\begingroup\$ I wish you can see the structure of my project and suggest some improvements. Link me the place, where network part can be added. \$\endgroup\$ – snoward Jun 8 '16 at 15:08
  • \$\begingroup\$ @MikhailPliskovsky Remember that software development is no exact science. There are countless solutions for every problem, and which solution is the best depends on many different factors, with many of them based on personal preference. \$\endgroup\$ – Philipp Jun 8 '16 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.