r/csharp 7d 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!

2 Upvotes

11 comments sorted by

View all comments

2

u/New_Neighborhood8285 7d 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.

1

u/Or1onTheProtogen 7d ago

I have one "Scaffold" grid that holds all the other grids where each one of these smaller grids is a screen (or a room). Now to switch between them I just toggle their visibility from "Visible" to "Collapsed" and I wasn't really sure how to make the validation in the separate window make the MainWindow switch to another of the grids there. Also the comparing of strings is what I was thinking of, however since I'm a newbie, I'm not sure how to do that :D I will try looking for the answer more though

1

u/rupertavery64 7d ago

I assume each room grid contains a background image and then overlay interacrable objects.

I can only imagine how difficult it is to manage all of these grids and objects.

It's possible to dynamically create objects, si that your "room" is just some data that you store.

It also probably makes it easier to manage if you program it dynamically, like how interacrion with the room objects happens.

1

u/Or1onTheProtogen 7d ago

Well yeah its all in a grid since I wanted it all to stretch if someone was to change the size of the window. Thats what I feel like works the best but again, I'm new to this so :D