Answer the question
In order to leave comments, you need to log in
How to design a "spaceship"?
Hello, it 's me again . There is a spaceship. Ship class . It contains an array of ship compartments. Hardpoint class . Equipment can be installed in each compartment. There is such a scheme - IEquipment - a base abstract class that defines general parameters like mass, size, etc. Descendants of IEquipment - equipment types, Generator , Engine , etc. Well, their specimens lying in the compartments are specific models of this equipment.
The problem is in their operation. A simple example - the engine determines the speed of the ship (physics, sorry). Accordingly, in order for external scripts (movements in this case) to recognize the speed of the ship, we had to place the Speed property in the main class (Ship), which goes through all the engines on the ship and reads the resulting speed from them. The problem is that in the course of development a lot of new properties are added and all this hangs in the Ship. Is this normal or is it bad architecture and normal people do things differently? In general, I ask the gurus to analyze this and make a verdict.
Answer the question
In order to leave comments, you need to log in
Use the stat system. For example you have a class
enum StatType {
speed;
power;
mobility;
}
class StatManager {
// Выставляет начальное значение стата
void setStateBase(StatType type, float value);
// Добавляет новый модификатор для стата
void addStatModf(StatType type, StatModf modf);
// Удаляет модификатор стата
void removeStatModf(StatType type, StatModf modf);
// Возвращает значение стата со всеми повешенными на него StatModf
Float getStateValue(StatType type);
}
enum StatModfType {
set;
add;
mult;
}
class StatModf {
var StatModfType type; // как именно модификатор влияет
var Float value; // значение с которым он влияет
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question