Jump to content


Check out our Community Blogs

aazamsajid

Member Since 01 Apr 2012
Offline Last Active Apr 13 2012 10:08 AM
-----

Topics I've Started

Shorter code for tic-tac-toe game code

08 April 2012 - 11:50 AM

i am working on a tic tac toe game this is loop code ....how can write this in short way like in algorthm or arrays etc

void check()
	    {
		    if (b[0].Text == b[1].Text && b[1].Text == b[2].Text && b[0].Text != "")//
		    {
			    MessageBox.Show(b[0].Text + " wins");
			    reset();
		    }
		    if (b[3].Text == b[4].Text && b[4].Text == b[5].Text && b[3].Text != "")//
		    {
			    MessageBox.Show(b[0].Text + " wins");
			    reset();
		    }
		    if (b[6].Text == b[7].Text && b[7].Text == b[8].Text && b[6].Text != "")//
		    {
			    MessageBox.Show(b[0].Text + " wins");
			    reset();
		    }
		    if (b[0].Text == b[3].Text && b[3].Text == b[6].Text && b[0].Text != "")//
		    {
			    MessageBox.Show(b[0].Text + " wins");
			    reset();
		    }
		    if (b[1].Text == b[4].Text && b[4].Text == b[7].Text && b[1].Text != "")//
		    {
			    MessageBox.Show(b[0].Text + " wins");
			    reset();
		    }
		    if (b[2].Text == b[5].Text && b[5].Text == b[8].Text && b[2].Text != "")//6
		    {
			    MessageBox.Show(b[0].Text + " wins");
			    reset();
		    }
		    if (b[0].Text == b[4].Text && b[4].Text == b[8].Text && b[0].Text != "")//7
		    {
			    MessageBox.Show(b[0].Text + " wins");
			    reset();
		    }
		    if (b[2].Text == b[4].Text && b[4].Text == b[6].Text && b[2].Text != "")//8
		    {
			    MessageBox.Show(b[0].Text + " wins");
			    reset();
		    }
		  
	   
	   
	    }

Change text size of a dynamic button

08 April 2012 - 08:46 AM

i am working on tic tac toe game and im creating dynamic buttions now i want change text's size of a dynamic buttion'text
how can i change ...?

void Form1_Click(object sender, EventArgs e)
	    {
		    Button bt = (Button)sender;
		    if (flag == 0)
		    {
			    bt.Text = "x";
			    bt.Text.Size = new System.Drawing.Size(30, 20);//this line i am using please correct it with a correct one.
			    flag = 1;
		    }
		    else
		    {
			    bt.Text = "0";
			    flag = 0;
		    }
		   
		    bt.Enabled = false;
		    t++;
		    check();
		    if (t == 9)
		    {
			    MessageBox.Show("Draw");
			    reset();
		    }
	    }

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download