Late answer but for those asking why the buttons are clickable again after a win. It is the same as when the New Game menu item didnt work, put the try/catch inside the foreach loop on your disableButtons method and it should work fine!
A better solution for the try/catch blocks will be to check if the controls are buttons or not with if(someButton is Button), and instead if using the buttons them self to indicate the turn for player X or O you can add a ToolTip control and assign it to the "mouse enter" with toolTip1.SetToolTip(b, "It´s player X turn"); For the rest of the example... is REALLY good!, thnx a lot for putting this up. Request: Any chance this whole game can be redone with an OOP approach?.
if your buttons are clickable again after adding the labels try to do the same step at "private void disableButtons" explained at 10:29 as what you did by new game. or replacing disablebuttons with this code: private void disableButtons() { foreach (Control c in Controls) { try { Button b = (Button)c; b.Enabled = false; } // end foreach catch { } } // end try }
nice video bro, learning really well on your tutorials keep up the good work!! Have one question, when someone wins how do you make it not able to continue i notice if someone wins you can keep going on same game, i guess i'm trying to say is how can you lock the game so it wont continue until you click on new game
Just something I thought about when doing the first tute. I selected all the buttons after I entered the first button_enter and pasted. it put it on all buttons. I did the same for button_leave. you don't have to paste one by one.
Hey chris, Thanks for sharing this, I was just wondering if their would be an easy way to Allow users to enter their name when the game gets opened, and to be shown on the scoreboard instead of X Win Count and O Win count etc?
Hello.The code is fine,but what when x or o wins the round?. It gives +1 to count,show message witch player is the winner and then what? :) It cannot count again,you need to press new game everytime. What if i want it to count until 10 wins? Thanks. Bane
Hey Bane, If you wanted the game to automatically start a new game, the easiest way would be to add: newGameToolStripMenuItem.PerformClick(); to each case when X or O wins (say right after the message box is shown) or after the message box for a draw is shown. That would be the simplest way. Of course there other ways to do that too. :)
hello, i was wondering, how do you change the color of the text if the button is disabled ? :( cuz i wanna mess around with the proprieties e.g. if the result is X then the font color will be red etc, but it doesnt do anything because the button is disabled, any way to disable only certain propreties like text instead of the entire button?
Hi. Thanx for your videos. Wanted to ask about an exception unhandled with string format. This is referring to the Int32 and the Parse method for restting the score. When the score resets, the text in the count labels change to 0 and the becomes the counters. How do I fix it.....don't understand enough from reading my C# books. Please help
hello, how can you make it swap the between X and O (the one that starts) like, i chose x and my budy o, but if i get to start i know how to win... so how can i make it to change one turn starts O next one starts X. even better, how can i make it so i can chose who is to start?
hello dude, im new to c# programming language. can i ask you a question? what if i set some winning patterns of buttons and deadlock buttons how do i do it?
I get an error right after we added the labels for the count, it says "An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll Additional information: Input string was not in a correct format." it of-coarse highlights the x_Win_Count line as that was the winner., did I need to add a using statement? Thanks in advance.
If you want to make a textbox to show whose turn, I have some ideas here : ) private void Turns_Checker() { if (turns_count % 2 == 0) { Whose_Turn_TextBox.Text = "O"; } else { Whose_Turn_TextBox.Text = "X"; } }
2:00 you can select multiple items with shift + click and then wirite it only once
Hi, the buttons are now clickable again after a win is set since we added the labels
Late answer but for those asking why the buttons are clickable again after a win. It is the same as when the New Game menu item didnt work, put the try/catch inside the foreach loop on your disableButtons method and it should work fine!
A better solution for the try/catch blocks will be to check if the controls are buttons or not with if(someButton is Button), and instead if using the buttons them self to indicate the turn for player X or O you can add a ToolTip control and assign it to the "mouse enter" with toolTip1.SetToolTip(b, "It´s player X turn");
For the rest of the example... is REALLY good!, thnx a lot for putting this up.
Request: Any chance this whole game can be redone with an OOP approach?.
if your buttons are clickable again after adding the labels try to do the same step at "private void disableButtons" explained at 10:29 as what you did by new game.
or replacing disablebuttons with this code:
private void disableButtons()
{
foreach (Control c in Controls)
{
try
{
Button b = (Button)c;
b.Enabled = false;
} // end foreach
catch { }
} // end try
}
It shows error, modifier private is not valid
disableButtons is declared but never used.
Solved the errors. I love you man.
It worked !! Thank you so much i was stuck in this for hours
nice video bro, learning really well on your tutorials keep up the good work!! Have one question, when someone wins how do you make it not able to continue i notice if someone wins you can keep going on same game, i guess i'm trying to say is how can you lock the game so it wont continue until you click on new game
you can simply disable all the buttons
Maybe You can add same code in C++?
brilliant!
Thanks a lot i created the same game using your help provided. Keep publishing games and more on csharp codes like these.
Thanks for sharing this tutorial. You helped me a lot and make me loveee c# :D :)
Chris, you are best my man! ty for that tutorial!!))
Thanks for sharing !!
thank u sir
Thank you!
Hey. What about empty catch?)
Just something I thought about when doing the first tute. I selected all the buttons after I entered the first button_enter and pasted. it put it on all buttons. I did the same for button_leave. you don't have to paste one by one.
How can we make it an option to vs the computer?
There are a couple follow up videos...the last one covers playing against the computer.
Thank you!!
thanks mr chiris
Hey chris, Thanks for sharing this, I was just wondering if their would be an easy way to Allow users to enter their name when the game gets opened, and to be shown on the scoreboard instead of X Win Count and O Win count etc?
Alex, Here ya go: (Part 3) Visual Studio Winform Tic Tac Toe Tutorial Example (C#) Hope this helps!
Chris Merritt Thanks a lot, your a top guy :)
+Chris Merritt Video 4 is not really clear (explicit) for people who not speak English
Hello.The code is fine,but what when x or o wins the round?. It gives +1 to count,show message witch player is the winner and then what? :) It cannot count again,you need to press new game everytime. What if i want it to count until 10 wins? Thanks. Bane
Hey Bane, If you wanted the game to automatically start a new game, the easiest way would be to add:
newGameToolStripMenuItem.PerformClick();
to each case when X or O wins (say right after the message box is shown) or after the message box for a draw is shown. That would be the simplest way. Of course there other ways to do that too. :)
Chris Merritt
Thank you :)
9:34
can u prevent the gray out of the disabled buttons bcoz it doesn't look nice
hello, i was wondering, how do you change the color of the text if the button is disabled ? :(
cuz i wanna mess around with the proprieties e.g. if the result is X then the font color will be red etc, but it doesnt do anything because the button is disabled, any way to disable only certain propreties like text instead of the entire button?
Hi. Thanx for your videos. Wanted to ask about an exception unhandled with string format. This is referring to the Int32 and the Parse method for restting the score. When the score resets, the text in the count labels change to 0 and the becomes the counters. How do I fix it.....don't understand enough from reading my C# books. Please help
thanks very much helpfull
hello, how can you make it swap the between X and O (the one that starts) like, i chose x and my budy o, but if i get to start i know how to win... so how can i make it to change one turn starts O next one starts X.
even better, how can i make it so i can chose who is to start?
hello dude, im new to c# programming language. can i ask you a question? what if i set some winning patterns of buttons and deadlock buttons how do i do it?
I'm not sure I follow what you're asking. You mean how to you preprogram moves by the computer player?
Nice
Wheres part 1?
HI. I need a command wich reset the game after someone wons. Can someone help me. Thank you!
I get an error right after we added the labels for the count, it says "An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
Additional information: Input string was not in a correct format." it of-coarse highlights the x_Win_Count line as that was the winner., did I need to add a using statement?
Thanks in advance.
Robert Carlson Disregard my last post, I put the letter o instead of a zero in the label text properties
svp lien de telechargement visual studio
minimax algorithm?????
Hey you should have more likes
Video 4 is not really clear (explicit) for people who not speak English
If you want to make a textbox to show whose turn, I have some ideas here : )
private void Turns_Checker()
{
if (turns_count % 2 == 0)
{ Whose_Turn_TextBox.Text = "O"; }
else
{ Whose_Turn_TextBox.Text = "X"; }
}
*deadlock patterns
Just a tip, an easy to rest form and scores
paste this in the rest score method
newGameToolStripMenuItem_Click(sender, e);