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 XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Facebook Updates

Guruji Point

Categories

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

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