Click here to Skip to main content
15,891,513 members

Need help! Linking a Windows Form to a Game class.

Landstar_01 asked:

Open original thread
Hi everyone.

I'm fairly new to coding and have had very little tuition to get to where I am, but I am very stuck with this problem on my latest University assignment.

First of all, I was given the framework to start working with from the University and as such, the project type is a Class Library, but it runs as a game. The game itself is a simple side-scrolling shooter similar to the classic R-Type game series. The project itself doesn't have to display that many techniques, so it's only a 2D game using mostly graphics I've been given.

As a way to show extra credit, I'm trying to implement a series of menu screens using Windows Forms. I have one that is created when the application is launched to be the opening menu. It has 2 buttons. One which launches the game (by closing the form and playing the scene using a this.PlayScene(Scene) method. The second button is supposed to exit the game, but I don't know how to get this one to work.

So far, I have tried methods such as:

C#
public void button2_Click(object sender, EventArgs e)
{
    this.Close();
    mKernel.Exit();
}


C#
In Form1:
int _counter = 0;

public int setCounter(int counter)
{
    counter = _counter;
    return counter;
}

public void button2_Click(object sender, EventArgs e)
{
    _counter++;
    this.Close();
}

In Kernel:
int counter = 0;

form1.ShowDialog();
form1.Focus();

counter = form1.setCounter(counter);

if (counter != 0)
{
    this.Exit();
}


In both cases, the Kernel class is the main XNAGame class. In every attempt I've tried, clicking the button simply closes the form and runs the scene as normal. Is there any way I could possibly get the Kernel class to exit the game after the form is closed and this button was clicked in order to close it?
Tags: C#, XNA4.0

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900