Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# XNA4.0
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:
 
public void button2_Click(object sender, EventArgs e)
{
    this.Close();
    mKernel.Exit();
}
 
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?
Posted 7-May-12 6:31am
Comments
BobJanova at 8-May-12 10:42am
   
What happens if you don't do 'this.Close()'?
mark merrens at 8-May-12 15:44pm
   
Reason for my vote of 2
We don't do homework though I see a few brave souls have tried to help you.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

there are lots of other ways...see Game State Management and if you want to continue with winforms.....try using "System.Diagnostic.Process.Start("C:\Windows\System32\taskkill.exe","/f /im [yourappname] /silent");" instead of "this.Exit();"
  Permalink  
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 6,769
1 Sergey Alexandrovich Kryukov 6,338
2 DamithSL 5,408
3 Manas Bhardwaj 4,816
4 Maciej Los 4,195


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 1 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100