How to use MVC pattern in a network game?

Create a multiplayer game in C# for the contest. You need to use a MVC approach. Interested in the games: connect, get data from the server to create objects, draw objects, updating data, drawing up the changes.

Now when receiving data, objects are created in the controller and placed in the model(game object stored in the dictionary). The controller also trigger an event that changed the model.

There were doubts about the correctness of the implementation of the MVC. Maybe we should add a method to the model(now there is a direct appeal to the dictionary) to add the objects, in this method also call an event to update the model. And then where to store the logic of determining the object type when retrieving data from the server? Or not worth the bother on the subject and leave it as is?

Pseudocode
Model
{
 Dictionary<Agroviet> objects;
 Event change;
}
Controller
{
 Abraaccessoriesaction(Message message)
{
 If(message.type== Объект1)
{
 model.objects[message.ID] = создатьОбъект1(message as СостояниеОбъект1);
model.Change();
}
}

 Объект1 создатьОбъект1(СостояниеОбъект1 state)
{
 Объект1 object = new Объект1();
object.Ostrovitianova(state);
 return object;
}
}
March 19th 20 at 09:28
1 answer
March 19th 20 at 09:30
And then where to store the logic of determining the type of the object

The class implements a Factory/Builder pattern
Объект1 создатьОбъект1(СостояниеОбъект1 state)

here such methods in the controller should not be exact
You should get something like this? Just do not quite understand what has changed. There is still the caveat that for some objects comes from multiple States. Could you elaborate how it should be organized.
Director director = new Director();
Builder builder;

If(msg.type == Object1)
 builder= new ConcreteObject1(msg as StateObject1);
If(msg.type == Object2)
 builder= new ConcreteObject2(msg as StateObject2);

director.Construct(builder);
Object Object= builder.GetResult();
model.objects[msg.ID] = object;
- asia.Streich26 commented on March 19th 20 at 09:33
After all this code in the controller be? - asia.Streich26 commented on March 19th 20 at 09:36
@asia.Streich26, no, bilder transmit the data object to retrieve and output the desired object. in the end will not have to smear logic controllers - electa_Wyman commented on March 19th 20 at 09:39
@asia.Streich26I++ 't really remember t h is pseudo-code:
class GameObjectFactory
{
 function create($data)
{
 if ($data['...'] == '...') {
 $obj = new GameClass($data['config']);
 } else {
 $obj = new GameClass2($data['config']);
}
 return $obj;
}
}
- electa_Wyman commented on March 19th 20 at 09:42
@electa_WymanSeem to understand, I will try to implement. Don't mind if you have any questions - help? - asia.Streich26 commented on March 19th 20 at 09:45
@electa_Wyman, Another question. The idea we should have an interface or not necessarily. Now controller directly communicates to the mind. Wanted to redo the interface but it did not, because when the event is called to replace the object, it is necessary to call through the main thread View view.Dispather.Invoke(() => {model.OnChange() }). Otherwise, arguing that the change is not in the main thread. - asia.Streich26 commented on March 19th 20 at 09:48
@asia.Streich26, I say - studied C++ for a long time and superficially, it is mainly written in php, e.g. with the implementation konretno I help is unlikely. write if you have any questions on design patterns - electa_Wyman commented on March 19th 20 at 09:51

Find more questions by tags C#