I have a problem. I am doing a Pong game in c# Win Forms. I created Form1 which is actual game, Form2 which is Menu and Form3 which is Options Window. My problem is how to get access to panel(my background in game) properties from Form3 which is Options.
1 Answers
The first question that pops into my mind is- Why do you need 3 different forms (windows or Dialog Boxes). Wouldn't it be better to just have a single form, and switch it's content depending on where you are in the game?
You could, for example, just add 3 different Panels with the Game, Menu and Options, and set only the currently active to being visible. Or use the Menu as an overlay over the actual game (in case you want to access it during the game). Then you have only a single Form, and could put all the game logic into it.
But if you really want to use 3 different forms, then I'd recommend to use one form (or any other class) as the main program logic class that has access to all the other forms, windows, game-data. So you hold the references to the different forms in one place, and you can easily access them.
In order to get the back links to this main program logic class, just give it to the other forms, either in the constructor, or as a property which you set after creation. You could also use the singleton pattern, and create a single static instance of this main class, with a public static access, so all other classes can simply access it through the static getter.
You see, there are countless options. All depends on your personal preferences, and what you specifically need.
-
I have another problem now. I set "C" key to open ingame menu and ofc I set timer1.Enabled = false. In menu I have button Resume, then timer1.Enabled goes true. My problem is that when I press C once and get back to play, I can't use keys I set before ( Esc for Exit and Space for Restart). Any ideas? Im a begginer so i don't know such an easy things ;d – Szymon Apr 19 '15 at 13:21
-
Yes, I see that you are a beginner. I'd recommend to follow some basic tutorials so that you get accustomed to the programming concept. If you have specific questions, please open another question. – azt Apr 19 '15 at 16:55