How to Make a Game in C++ Visual Studio: Tic Tac Toe

Hey folks! I hope your life is programming well. As you know, your life is like a game, and you are the expert player of that game. But have you ever wondered about the games you play on your phones, PCs, and laptops? How these games are developed? Have you ever wondered about the development of a game in a Visual Studio?

You can also use game engines available for C++ developers to develop a game but, this one is a simple tic tac toe game that doesn’t require any game engine.

Well, I will inform you how to develop your own game in C++ Visual Studio. There is no rocket science behind creating any game. Just glide through the article completely and you will feel yourself a master of the thing.

But before getting the knowledge of making any game, let’s conquer a bit about the Visual Studio.

How to Make a Game in C Visual Studio - How to Make a Game in C++ Visual Studio: Tic Tac Toe

What is a Visual Studio?

The visual studio is an IDE (Integrated Development Environment) mainly used to create various applications and chiefly gaming applications. This software provides its user with a comfortable environment to produce any game or application. 

It supports some built-in high-level programming languages like C, C++, C#. Moreover, it also sustains other languages like python and java. Its free version, containing all the features, is also available on its website https://www.visualstudio.com/downloads for programmers.

Requirements to Develop a Game

There are certain requirements to develop a game in C++.

Software
There are two packages needed to develop a game:

Windows Vista/7/8/8.1:

These windows can be used to create any game in C#.Net using Visual Studio.

Visual Studio:

It is also packaged software. You can read all the information about it in the paragraph written above.

Skills

There is only one skill needed if you want to develop a game in Visual Studio:

Requirement of basic and root knowledge of C, C++, and C#.

Starting with the Game Development

The game development on C++ visual studio is a piece of cake if you understand this article properly. To make it easy for you, I will be giving you an example of a tic tac toe game, so the difficulty level decreases to some extent. So my impatient readers, let’s start with our mission.

  • First, you have to open the Visual Studio app, which you installed in the Windows 7 or 8 or 8.1 version of your PC.
  • After opening the application, you need to click on the FILE option in the menu bar. Some options will appear when you click on the file. It would be best if you opted for the NEW PROJECT option.
Open new game Project in Visual Studio
  • Then give your project a good attractive name like if I want to develop a tic tac toe game, I will name my project Mind Boosting Tic Tac Toe Game.
  • In the middle of the screen, you will see a basic dialogue box with “FORM 1”.
  • A dialogue box of properties will appear on the right side of the screen. There you can see a property named “Show Icon”. If you do not want to show your icon, you can remove it by switching it from “True to False”. And your icon will disappear.
  • You can also change the form name by clicking on the “Text” option.
  • Drag the tool named “Tool Strip” to the form from the toolbox dialogue.
  • You need to create “File” and “Help” (two menus). There will be an empty box that will ask you to “Type Here”. You can type the menus over there by writing in it these words. “The menus are not functional after we had changed the names. We need to have further proceedings”. 
Update the form properties and hide icon, disable maximize
  • Add “New Game” and “Quit” as sub-menus by clicking on the “File” in the form. You can also add the “About” submenu to the help menu. 
image 40 - How to Make a Game in C++ Visual Studio: Tic Tac Toe

Addition of the Gaming Arena

  1. Drag the “Button” named tool to the form from the toolbox dialogue. As I am making a Tic Tac Toe Game, there will be nine buttons in the game. It would help if you dragged the button tool nine times 
  2. Click on one of the button tools after you are done adjusting the workspace’s size (buttons).
Add button and resize it
  1. Then, a “Property Dialogue” is added to regulate the game’s font. As I am developing the tic tac toe game, I will use the font of “X” and “O” to appear big enough on the screens. The font of each button should be the same, so the game gives a synchronized look.
  2. In this game, there will be a need to rename each button. There are nine buttons in my game, so I will name them in a Matrix form like: (Button1 as A1, Button 2 as A2, Button 3 as A3, Button 4 as B1, Button 5 as B2, Button 6 as B3, Button7 as C1, Button 8 as C2 and Button 9 as C3).Here A, B, and C are rows 1, 2, and 3. It will be helpful for us to further develop our game. 

Menus are Allotted with Tasks

  • You need to click on the “Help” menu in the form and further choose the “About “submenu” by double-clicking on it.
  • At this point, you will come across a basic C# program.
  • Now, you need to type a message in “private void aboutToolStripMenu…….”. The message will be as follows:

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

  • After typing MessageBox.Show a set of 21 string options that will appear. You will click on the third string.
  • A task for the “//Exit//menu” is added. Here you will type “‘private void exitToolStripMenu…… ‘.

Application.Exit();

  • You need to do the same with the “Exit” and “About” menus. With the “New Game” menu, you need to double-click it. Now type this function in “ private newGameTool……….”
turn = ture;
turn_count = 0;
 
 
foreach(Control c in Controls){
  Button b = (Button)c;
  b.Enabled = true;
  b.Text = "";
}
catch { }

Working on the Game

  • After you have entered the programming section, under “Public Partial Class” write this code:
bool turn = true;
int turn_count = 0;
  • Now, tap on any one of the buttons in the form. Then, click on the “Thunder Bolt” Icon present in the properties.
  • “Click Button” should be typed under the “Click” property. Apply it to all nine buttons.
  • The code written below should be typed in the “Public Partial Class”.
gray out box on click
private void button_click(object sender , EventArgs e){
  Button b = (Button)sender;
  if(turn)
    b.Text = "X";
  else
    b.Text = "O";
  turn = !turn;
  b.Enabled = false;
  turn_count++;
  check();
}

Declaring the Winner

  • Checking and declaring the winner is our main achievement. 
  • Here we will develop a new class.
  • So, ultimately the renaming of the button is proved handy over here.
  • Type this piece of code under “public partial class”.
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("Its a Draw !"); 
  } 
}//End of class
Tik Tac Toe game in C#.net winner
  • As soon as the winner is declared and announced, the buttons should be disabled.
  • We have to create a new class under “public partial class”. And type this:
private void disableButtons() {
  try{
    foreach(Control c in Controls){
      Button b = (Button)c;
      b.Enabled = false;
    }
  }
  catch { }
}

Enjoy the Game

Now your game is developed and is fully functional to play. You can enjoy it. But before playing, you need to know that tic tac toe is a multi-player game.

Player 1 will be you, and player two will be a computer. And it would help if you were very clever to play with the computer as it is an expert in this game. Let’s see who will win this game, the computer or you, because the computer will never lose the game and I think so is you.

You can also use this video link to develop your own tic tac toe game in the visual studio.

Concluding Thoughts

 I hope you can now easily develop any game, especially a tic tac toe game. You just need to follow the steps accordingly, as reported in the article, and the basic thing is that you need to have a strong grip on C, C++, and C# computer languages so you can type the codes in your program without any error and mistake. 

Now, enjoy and develop your games in C++ Visual studio and give the world a chance to play the games developed by you.

Scroll to Top