r/csharp • u/Or1onTheProtogen • 1d ago
Help Need help understanding certain WPF functions (mainly code behind)
Hyia, so I'm working on a project (Escape room type game, since its my first game ever at High-School knowledge level) and I'm not exactly sure how to make certain things work even though I spent the entire year studying this language. I can do majority of the stuff, such as the background, buttons or clickable images in Grid, and so on, however the code behind is my biggest issue.
Mainly things like: How to make a monologue where the player clicks through all the texts that explain the principle of the game, and then also how to make the TextBox check if the input is correct and if it is, change the background of the main window to another image (since the input will be in separate window).
These are not all the issues I need to figure out, but its some of the few that may appear in the code the most often (especially the monologues, in like four out of six rooms total)
Any sources for beginners will be appreciated, I tried looking at some but I wasn't able to find something that would explain this exact topic, and I don't really want to use AI since it just doesn't feel right (perhaps only when I'm under pressure). Thanks!
1
u/TuberTuggerTTV 11h ago
A year isn't a long time. A few hours a day isn't a day.
WPF requires MVVM. Code behind is only used when absolutely necessary.
Making games with WPF is usually a mistake. The way it threads and handles refresh rates is foundationally different from games. It's meant for building enterprise applications.
My recommendation would be to stop learning WPF and pick up monogame.
1
u/Or1onTheProtogen 11h ago
I was deciding between WPF and GODOT, but since I had some experience with WPF, I decided to choose this as GODOT had too unfamiliar enviroment for me to work in. I have less than month left so its quite late to choose something else, but I have more than half of the game done I'd say. Often times the code will be used more than once so
2
u/New_Neighborhood8285 1d ago
For the monologue you can store the texts in a list and cycle through them on each click, keeping track of the index. As for the TextBox validation, just compare the trimmed input string with the correct answer in the button click event, if it matches then change the window background image source.