loading

Hey Guys, its true. You can create your own game with basic knowledge of Visual Studio and C#. Before getting started I want to say that if you like this instructable then please VOTE ME for CODED-Creations Contest, by just clicking the VOTE option on the top right side of this instructable.

SOFTWARE Requirements :

1. Windows Vista/7/8/8.1

2. Visual Studio

SKILL Requirements :

1. Basic Knowledge of C/C++ and C#.

Here is a video if you want you can watch it.

WATCH HERE: [ PLAY VIDEO ]

Please Follow the steps carefully.


Step 1: Getting Started

1. Click FILE -> New Project.

2. Give project a name like "Tic Tac Toe " or of your choice.

3. You would see a basic dialog open with the title "Form 1".

4. In "Properties" dialog , there is a property called "Show Icon" .If you want you can remove the icon by toggling it from 'TRUE' to 'FALSE'.

And if you want to change the form name click on 'TEXT' option and change the form name as desired.

5. In 'ToolBox' dialog there is a tool named as "MenuStrip". Just drag it to the form.

6. For basics create two menus as 'Files' and 'Help'. Just type in the empty box that says "Type here". (Note :: we just named it and the menus are not functional, we need to proceed further for it ).

Click on 'File'(in the form) and add sub menus as "New game" and "Exit". And in Help add a sub-menu named " About"

Step 2: Adding a Game Area

1. In 'ToolBox' dialog, there is a tool named "Button" just drag it to the form. Since its "Tic Tac Toe" it will have nine buttons. Drag it nine times and re-size it and adjust it accordingly.

2. After completely adjusting the work-space. Click on anyone of the button(tool) . And in 'Property' dialog adjust the Font , Big enough such that 'X' and 'O' s will be clearly visible. Make sure each button have same font.

3. Renameeach button in Matrix form(like : Button1 will become A1, Button2 = A2 ,Button3 = A3, Button4 = B1, Button5 = B2,Button6 = B3,Button7 = C1 , Button8 = C2 and Button9 =C3 where A,B,C are rows and 1,2,3 are Columns. )

This renaming will help us a lot in further process.

Step 3: Giving Tasks to the Menus

1. Click -> 'Help'(in the form) and double click -> 'About'.

2. Now a basic C# program will appear.

3. In 'private void aboutToolStripMenu....... ' type

         MessageBox.Show("By //Your name//" , " Tic Tac Toe About ");

When you type MessageBox.Show( It will show a set of "21" string options. Make sure select the 3rd.(See the above image for more clarity) .

4. Similarly we would add a task for the //Exit// menu.

In 'private void exitToolStripMenu...... ' type

          Application.Exit(); 

( see the images for more clarity)

5. Now similarly like "About" and "Exit" double click "New Game". In " private newGameTool.......... " Tyep this code:

           turn = ture;<br>           turn_count = 0;<br>           try<br>           {<br>              foreach(Control c in Controls)<br>              {<br>                  Button b = (Button)c;<br>                  b.Enabled = true;<br>                  b.Text = "";<br>               }<br>            }<br>            catch { }<br>       

Step 4: Working on the

1. Go to the program and under " public partial class " Type ==>>

bool turn = true ;<br>int turn_count = 0;

(click on the image for ore clarity.)

2. In the form click on anyone of the button. In the "Properties" there is a "Thunder Bolt" Icon, click on it.

Under the "Click" property type this :: " button_click ".

Do this to all the 9 buttons. (Click on the second image for more clarity).

3. Write this code under " public partial class " ...Type this===>>

private void button_click(object sender , EventArgs e)<br>{<br>  Button b = (Button)sender;<br>  if(turn)<br>    b.Text = "X";<br>  else<br>    b.Text = "O";<br>  turn = !turn;<br>  b.Enabled = false;<br>  turn_count++;<br>  check();<br>}

(Click on the images for more clarity).

Step 5: Checking the Winner

Our

main aim in this step is to check the winner. So we need to create a new class here. So basically the renaming of the button will be useful here.

1. Under " public partial class " type this===>>

private void check()
{ bool winner = false; //Horizontal checking if((A1.Text==A2.Text)&&(A2.Text==A3.Text)&&(!A1.Enabled)) winner = true; else if((B1.Text==B2.Text)&&(B2.Text==B3.Text)&&(!B1.Enabled)) winner = true; else if((C1.Text==C2.Text)&&(C2.Text==C3.Text)&&(!C1.Enabled)) winner = true; //Vertical Checking else if((A1.Text==B1.Text)&&(B1.Text==C1.Text)&&(!A1.Enabled)) winner = true; else if((A2.Text==B2.Text)&&(B2.Text==C2.Text)&&(!A2.Enabled)) winner = true; else if((A3.Text==B3.Text)&&(B3.Text==C3.Text)&&(!A3.Enabled)) winner = true; //Oblique Checking else if((A1.Text==B2.Text)&&(B2.Text==C3.Text)&&(!A1.Enabled)) winner = true; else if((A3.Text==B2.Text)&&(B2.Text==C1.Text)&&(!A3.Enabled)) winner = true;

if(winner) { disableButtons(); String win = ""; if(turn) win = "O"; else win = "X"; MessageBox.Show(win + " Wins ! " , "Yay"); // Click Image for more clarity(string operation 2/21) } else { if(turn_count == 9) MessageBox.Show("Draw !","Bummer"); } }//End of class

2. Now we have to disable the buttons as soon as

someone wins

create a new class under " public partial class " Type this==>>

private void disableButtons()
{

try

{

foreach(Control c in Controls)

{

Button b = (Button)c;

b.Enabled = false;

}

}

catch { }

}

Step 6: Step 6 : Enjoy the Game

CONGRATULATIONS !

You have completed creating your own "Tic Tac Toe" game . Enjoy playing your game.

If you liked this instructable please do VOTE me for the Contest.

And there are some videos to do add-on s if want you can watch them.

THANK YOU VIEWING THIS INSTRUCTABLE

<p>i fany one dont have money that does not mean its require to upgrade in premium </p>
<p>you liers i dont need your pdf </p>
<p>Why :( </p>
Thanks
<p>I remember spending hours and hours with Visual Studio back in the day. Thanks for sharing! </p>
My Pleasure.

About This Instructable

31,656views

44favorites

License:

Bio: Ready to become a great genius the world have ever seen,, sorry not 'a genius' .... "the great genius" ...lol
More by pabdullah:Make a game using Visual Studio L293D/NE Motor Driver Pin Diagram  How To Remove Camera Lens From Old Phone 
Add instructable to: