Develop Tic Tac Toe game bigger version (9X9) using basic Windows Form and C# Dotnet codes



Hello friend, here let’s see how we can develop a Tic Tac Toe puzzle game (9X9) by doing minor modifications in the code base which formed from the blog Tic Tac Toe 3X3 puzzle using C#.



Prerequisites
  • Basic c# programming knowledge
  • Basic windows form application development knowledge 
  • Visual studio 2010+ 
  • This is poorly the continuation of the blog Tic Tac Toe 3X3 puzzle using C#. If you have not visited the same yet, please do visit the blog first.


Blog Url :-



Step 1.
First we will modify the changes to the codes which is to generate the buttons dynamically. As we can see in the below screenshot all the numbers which made it a 3X3 puzzle will be changed to make it a 9x9 puzzle.

Develop Tic Tac Toe puzzle bigger version using C# 

As you can see in the code the 3x3 matrix (button array) is changed into 9x9 here, the button size and location values are changed and font size is reduced. All these changes will make the new 9x9 puzzle fit in the existing panel
Let’s run the code now to see if the 9x9 puzzle loads and the buttons clicks works correctly

Develop Tic Tac Toe puzzle bigger version using C# 

As you can see in the above screenshot it is loaded perfect and the button clicks, toggling and marking are working properly.


Step 2.

Next we will modify the codes which to check if any player wins the game. Let’s start with the vertical check first.

Develop Tic Tac Toe puzzle bigger version using C#

As you can see in the new code, we made the code changes to check if there are five consecutive blocks in any vertical lines (in 3x3 it was checking if there are 3 consecutive blocks).
Now let’s run the application to see if the horizontal check really works.

Develop Tic Tac Toe puzzle bigger version using C#


Step 3.

Now let’s do some code refactoring here. As we are using similar codes to check game win in all the direction let’s move those codes into a private method which will help to reduce the code length and complexity.

Develop Tic Tac Toe puzzle bigger version using C#

Now let’s do the code modification in the horizontal check.

Develop Tic Tac Toe puzzle bigger version using C#


Step 4.

Now let’s do the code changes for diagonal check.

Develop Tic Tac Toe puzzle bigger version using C#

As you can see there are additional modifications (loop logics) in the diagonal check. The reason for this is the diagonal check in the 9x9 is bit different from 3x3 puzzle. The following screens will give some idea how the difference comes in.

Develop Tic Tac Toe puzzle bigger version using C#



Step 5.

We don’t’ need to modify the code which checks the game draw scenario, and so we are done with code changes and following is the outlook of the final code base.

Develop Tic Tac Toe puzzle bigger version using C#

Let’s run the application and see if it works fine in all the scenarios. The following screens shows samples of player winning with horizontal blocks, player winning with vertical blocks and game becomes draw.

Develop Tic Tac Toe puzzle bigger version using C#
Player wins with horizontal blocks


Develop Tic Tac Toe puzzle bigger version using C#
Player wins with horizontal blocks



Develop Tic Tac Toe puzzle bigger version using C#
Game becomes draw






Enjoy Coding…!!!



Comments

  1. Hi Dear Freinds!
    I am here to tell you about a lovely game site about Tic Tac Toe Game.The Game is about tick and cross.Click Here to play the game and to have fun.

    ReplyDelete

Post a Comment