managing different loops in different events

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kristu
    New Member
    • Jan 2010
    • 2

    managing different loops in different events

    i have this code:
    Code:
    private void mouseclicks(object sender, EventArgs e)
                {
                    int clicks = 0;
                    clicks++;
                        if (clicks % 2 == 0)
                        {
                            label5.Text = "Player One's Turn";
                           
                            
                        }
                        else label5.Text = "Player Two's Turn";
                }
    
            private void Form3_Load(object sender, EventArgs e)
            {
                
                
                for (int x = 0; x < 64; x++)
               {
                   
                   this.buttonarray[x].Click += new System.EventHandler(this.mouseclicks);
                   
                        
                    
                                
               }
            }
    basically i have this part of code where this will determine which player is next according to the number of clicks...in the form3_load event i made a loop for 64 (coz have 64 buttons) of array which will call the mouseclicks event

    in the mouseclicks event i have a varibel clicks to see home many clicks there is.. i am checking if the number is odd or even to determine the which player, if even than player one, if odd player two...

    the program only works for the first click becoz from the 64 loop it goes to the other event and never goes back to continue the other loop

    can some one help pls?
    Last edited by RedSon; Jan 14 '10, 04:42 PM. Reason: Added CODE tags
  • mzmishra
    Recognized Expert Contributor
    • Aug 2007
    • 390

    #2
    Everytime your onclick event is called you are trying to do
    int clicks = 0;
    clicks++;
    The problem is here.

    Comment

    • vishal1082
      New Member
      • Apr 2009
      • 92

      #3
      please write codes in [CODE] tags

      Comment

      • RedSon
        Recognized Expert Expert
        • Jan 2007
        • 4980

        #4
        What he ^ said...

        Comment

        Working...