Answer the question
In order to leave comments, you need to log in
How to properly use the MVC pattern in a multiplayer game?
I am creating a network game in C# for a competition. You need to use the MVC approach. The game process of interest: we connect, we receive data from the server to create objects, we draw objects, we update data, we draw changes.
Now, when data is received, objects are created in the controller and placed in the model (I store game objects in a dictionary). In the controller, I also call an event that the model has changed.
There were doubts about the correctness of the implementation of MVC. It may be worth adding a method for the model (now there is a direct access to the dictionary) for adding objects, in this method also call an event to update the model. And where then to store the logic with the definition of the type of the object when receiving data from the server? Or should you not bother with this topic at all and leave it as it is?
Pseudocode
Модель
{
Словарь<ИгровойОбъект> объекты;
Событие изменение;
}
Контроллер
{
ОбработчикСообщенийотСервера(Сообщение сообщение)
{
Если(сообщение.тип== Объект1)
{
модель.объекты[сообщение.ID] = создатьОбъект1(сообщение как СостояниеОбъект1);
модель.Изменение();
}
}
Объект1 создатьОбъект1(СостояниеОбъект1 состояние)
{
Объект1 объект = new Объект1();
объект.УстановитьСостояние(состояние);
вернуть объект;
}
}
Answer the question
In order to leave comments, you need to log in
And where then to store the logic with the definition of the object type
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question