Yahoo Clever wird am 4. Mai 2021 (Eastern Time, Zeitzone US-Ostküste) eingestellt. Ab dem 20. April 2021 (Eastern Time) ist die Website von Yahoo Clever nur noch im reinen Lesemodus verfügbar. Andere Yahoo Produkte oder Dienste oder Ihr Yahoo Account sind von diesen Änderungen nicht betroffen. Auf dieser Hilfeseite finden Sie weitere Informationen zur Einstellung von Yahoo Clever und dazu, wie Sie Ihre Daten herunterladen.
How do I best isolate game state from UI (C#)?
I'm writing a game and have prototyped a simple version of it using a single class, but now I want to expand (create more unit types, more complex UI, etc.), but I'm having trouble isolating UI code from game state code. I don't want my UI classes to have to be aware or dependent on how the game state is structured, nor do I want my game state to be dependent on how I decide to structure my UI. However, I find myself writing stuff like (pseudocode):
if( button3.Contains(mouseClickPosition) ) player0.attack(player1);
So now if I change the way attack() works (e.g. to something like game.attack(player0,player1) ), I have to update my UI code. What's the best way to isolate the two? I'm pretty new to C# (my background is C++) and game design in general, so any references would be appreciated as well.
1 Antwort
- vor 1 JahrzehntBeste Antwort
Hi,
First, try reading about Design Patterns. In order for you to isolate UI from business logic, you need to follow patterns, don't reconstruct the wheel. For sure other programmers like you have figured it out before. If you could design your class to be independent (loosely coupled), then your UI will follow. Read up Design Patterns on wikipedia. A best sample for your current scenario would be the Strategy Pattern.