Guruji Point - Code You Want To Write

  • Home
  • Asp.Net
  • WCF
  • SQL
  • Type Script
  • AngularJS
  • Tech News
  • Blog
  • Earn Online

Friday, 9 October 2015

Tic Tac Toe Game In Windows Application Using C#.Net

 No comments   

Introduction

This Tic-Tac-Toe Window Game usually played with paper and pen by peoples.

How To Design

On New Form Window drag and drop 9 button controls from Toolbox and select all controls go to property window, choose Click Events Property and on Click Property give name it BtnAll .

                                       




and after doing this double click on Click Property  Now the BtnAll_Click Event Opens on Code Window. Then Write down the following code on Code Window.

namespace TicTokGameByJatin
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        int Count = 1;

        private void BtnAll(object sender, EventArgs e)
        {
            Button b = (Button)sender;
            b.Text = (Count % 2 == 0) ? "X" : "0";
            b.Enabled = false;
            check();
            Count++;
        }
       
//condition for 8 logic with row column diagonal.................

        void check()
        {
            if (button1.Text == button2.Text && button2.Text == button3.Text && button1.Text != "")
            {
                result(button1.Text);
            }
            else if (button4.Text == button5.Text && button5.Text == button6.Text && button4.Text != "")
            {
                result(button4.Text);
            }
            else if (button7.Text == button8.Text && button8.Text == button9.Text && button7.Text != "")
            {
                result(button7.Text);
            }
            else if (button1.Text == button4.Text && button4.Text == button7.Text && button1.Text != "")
            {
                result(button1.Text);
            }
            else if (button2.Text == button5.Text && button5.Text == button8.Text && button2.Text != "")
            {
                result(button2.Text);
            }
            else if (button3.Text == button6.Text && button6.Text == button9.Text && button3.Text != "")
            {
                result(button3.Text);
            }
            else if (button1.Text == button5.Text && button5.Text == button9.Text && button1.Text != "")
            {
                result(button1.Text);
            }
            else if (button3.Text == button5.Text && button5.Text == button7.Text && button3.Text != "")
            {
                result(button3.Text);
            }
            else if (Count == 10)
            {
              
                MessageBox.Show("Game Draw!!!!!");


            }
        }

//code for  result.....................

void result(string text)
{
if (text == "X")
{
MessageBox.Show("Second Player has won the GAME!!!!!!!!");
}
else if (text == "0")
{
MessageBox.Show("First Player has won the GAME!!!!!!!!");
}

else
{
    MessageBox.Show("");
}
if (MessageBox.Show("Are You Want To Play Again!", "Confirmation Message", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
reset();
}
else
{
this.Close();
}
}

//code for reset button.....................

void reset()
{
foreach (Button b in this.Controls)
{
b.Text = "";
b.Enabled = true;
}
Count = 1;
}
}
}

After Game finished 






  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to TwitterShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Facebook Updates

Guruji Point

Popular Posts

  • Base64 Encoding And Decoding In SQL Server
    Introduction In this article we will learn How to encode a string into Base64String and how to decode Base64String to string. How to crea...
  • Convert DataSet To List Or GenericList Using LINQ - C#
    Introduction In this article we will learn how to convert dataset to list or convert DataSet to List of collection o generic list in c#. ...
  • Trigger In SQL Server - Insert Update Delete In Single Trigger With Example
    Introduction In this article we will learn what is trigger . How to manage Insert, Update and Delete operation in trigger. Insert Update ...
  • Maintain The State Of Dynamic Added User Control On Each PostBack
    Introduction In this article we will learn how to maintain the state of dynamically created controls in asp.net using c#.  Retain the stat...
  • What Is Connection Pooling In Asp.Net Using C# With Example
    Introduction In this article we will learn what is connection pooling. Why connection pooling useful , what is the max limit and minimum ...

Categories

comma seperated string in sql Comman table Expression in SQL Dynamic Grid Row IQueryable in c# Learn AngularJS row_number() and dense_rank() salary table structure. Scope_Identity() Use of indexes while loop in sql why do we need cursor why tuple used

Best Deal Here

About Us

This blog is about the Programming ,Tech News and some intresting facts related Contents. Here you can find fundamental and expert level topic of programming languages very practically related to C# , Asp.Net ,Sql-Server, JavaScript, Jquery, WebServices And also Web-Api, WCF ,WPF, Angular Js.

Contact Us

Email Us - gurujipoints@gmail.com
Contact- 8077657477

Reach Us

Copyright © Guruji Point - Code You Want To Write