Jump to content

  • Log In with Google      Sign In   
  • Create Account

Game Loop Implementation on Windows Forms C#


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 stoneyrich   Members   -  Reputation: 143

Like
0Likes
Like

Posted 13 June 2013 - 11:52 AM

Hi guys,

 

I need help. 

 

I am designing a two player card game in C#, but i have a problem figuring out the following:

  1. The Main Game Loop (UI thread or a sperate thread) 
  2. Human Player and AI player should they be on different threads?

I am going to run experiments with different pairings at the end of the game development.

 

my thoughts are below: 

 

MainGameLoop() 
//player A or B ()
//display card played ()
//check the scores ()
}
 
AI_Player()
{
//Constant thread runing to identify if its AI's turn to play.
}
 
HumanPlayer()
{
   //A click event from the UI form.
}

 



Sponsor:

#2 Mario Fraiss   Members   -  Reputation: 100

Like
0Likes
Like

Posted 13 June 2013 - 01:57 PM

Hi,

 

As you mentioned, you try to figure out the right way. In your case, I would definitely suggest you, to implement the following model:

 

1) Main-Loop which is responsible for the main execution

b) Updates Game UI, Updates Game Graphics, Updates Game States

 

2) The question about the seperation of threads concerning your players is not that easy to answer...

 

Is it necessary, that they act and react at the same time, simultaneously or every of the player turn by turn? If they act turn by turn, one thread should enough.. this  thread can handle manual (human actions) and automatic (AI actions).

 

Does this help you?


Greetings, The Proof

 

____

 

more than innovation.


#3 stoneyrich   Members   -  Reputation: 143

Like
0Likes
Like

Posted 13 June 2013 - 06:47 PM

Thanks Mario, 

 

Well it does answer and gives me a different look at my problem. 

 

  • But does that mean the main execution loop will be the UI thread, 

          because as i said ealier i will take picture box click event responses from the UI.

 

  • My players will act turn by turn (where will this player turn switch be in the main executioin loop ? ) 


#4 Mario Fraiss   Members   -  Reputation: 100

Like
0Likes
Like

Posted 14 June 2013 - 02:47 PM

Hi,

 

I'm glad, that I was able to bring you to another view of your problem.

 

In Windows-Forms you primary have one Thread, which is the UI Thread. This thread normally is redrawing the forms and controls and every action concerning that should be implemented within the OnPaint-Methods of your components. Therefore, all your actions, which are not about the UI should be seperated into an extra thread, e.g. this could be a thread you instantiate manually for the human player, and e.g. a Background-Worker thread which you could use for the AI-player.

 

In fact, It's up to you, how you get these things done. I think an easy and efficient way to solve your problem could be this one:

 

1) Subclass a Windows-Form or your Picture-Box, you probably need for implementing the custom drawing

2) Implement Event-Handlers for the Picture-Box and Event-Receivers for your class which handles a Player

3) Subclass the Player to be a human player

4) Subclass the Player to be an AI-player (and if you like, include Thread-Handling in the way of a background worker there)

 

I hope this brings you a little further :)


Greetings, The Proof

 

____

 

more than innovation.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS