- Perfectly Written Flawless Code in .Net Framework C# 5 language using WinForms.
- Programmer level only Beginner required. NOT Intermediate. NOT Expert.
- The code is explained immediately before being written.
- The game's basic functionality is that it has two players put their letters, the X and O in 9 available grid boxes one by one and the player to make a straight line with 3 letters wins.
- The Game Counts scores of the individual players and a Reset of the scores is also possible.
- Players may reset the current game and start a new game whenever needed.
- Please recommend and comment if it worked for you. Thank You for Visiting :)
The Function below helps to start a new game. It enables all the buttons to be pressed again and sets their Text values to blank meaning they are available to use.
This below for loop sets the 2D Array Values to 0. Grid values with 0 mean they are not clicked, unused, and available(waiting) for use by any player.
There are two diagonals in this square grid. The function below checks the two diagonals for a potential Win from any player.The two variables countforP1 and countforP2 counts the number of (particular) player visits in each diagonal. The two for loops allow us to check each cell in the 2D Grid Array.
When the button is clicked, the button is first disabled to register the visit. Then, we check if it is the first or second player to visit. The 2D Array is set then the Text on the button is set appropriately. After each visit, the rows, columns and diagonals are checked for a potential win. After a win, a new game starts automatically.