Question tic tac toe game timer usage !

zeybekli

New member
Joined
Jan 10, 2012
Messages
1
Programming Experience
Beginner
i am new on c# looking all code from internet ,looking program's code to learn...

there a game tic tac toe.i understand all line of codes but not timer only.
also i am writing same code again and its giving me 12 errors about usage timer method..

how can i know and how can i fix them.
this is code..

C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

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

        int fon;

        Random r = new Random();
        private void Form1_Load(object sender, EventArgs e)
        {
            fon = r.Next(1, 4);

            timer1.Start(); 
            timer2.Start();
            button5.Text = "O"; 
            button5.Enabled = false; 
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (fon == 1)
            {
                button1.Text = "X";
                button1.Enabled = false;
                button4.Text = "0";
                button4.Enabled = false;

            }
            else if (fon == 2)
            {
                button1.Text = "X";
                button1.Enabled = false;
                button3.Text = "0";
                button3.Enabled = false;
            }
            else if (fon == 3)
            {
                button1.Text = "X";
                button1.Enabled = false;
                button6.Text = "0";
                button6.Enabled = false;
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (fon == 1)
            {
                button2.Text = "X";
                button2.Enabled = false;
                button6.Text = "0";
                button6.Enabled = false;

            }
            else if (fon == 2)
            {
                button2.Text = "X";
                button2.Enabled = false;
                button4.Text = "0";
                button4.Enabled = false;
            }
            else if (fon == 3)
            {
                button2.Text = "X";
                button2.Enabled = false;
                button7.Text = "0";
                button7.Enabled = false;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (fon == 1)
            {
                button3.Text = "X";
                button3.Enabled = false;
                button8.Text = "0";
                button8.Enabled = false;

            }
            else if (fon == 2)
            {
                button3.Text = "X";
                button3.Enabled = false;
                button1.Text = "0";
                button1.Enabled = false;
            }
            else if (fon == 3)
            {
                button3.Text = "X";
                button3.Enabled = false;
                button9.Text = "0";
                button9.Enabled = false;

            }


        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (fon == 1)
            {
                button4.Text = "X";
                button4.Enabled = false;
                button1.Text = "0";
                button1.Enabled = false;

            }
            else if (fon == 2)
            {
                button4.Text = "X";
                button4.Enabled = false;
                button2.Text = "0";
                button2.Enabled = false;
            }
            else if (fon == 3)
            {
                button4.Text = "X";
                button4.Enabled = false;
                button8.Text = "0";
                button8.Enabled = false;
            }

        }

        private void button5_Click(object sender, EventArgs e)
        {
        }
        private void button6_Click(object sender, EventArgs e)
        {
            if (fon == 1)
            {
                button6.Text = "X";
                button6.Enabled = false;
                button2.Text = "0";
                button2.Enabled = false;

            }
            else if (fon == 2)
            {
                button6.Text = "X";
                button6.Enabled = false;
                button9.Text = "0";
                button9.Enabled = false;
            }
            else if (fon == 3)
            {
                button6.Text = "X";
                button6.Enabled = false;
                button1.Text = "0";
                button1.Enabled = false;
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (fon == 1)
            {
                button7.Text = "X";
                button7.Enabled = false;
                button9.Text = "0";
                button9.Enabled = false;

            }
            else if (fon == 2)
            {
                button7.Text = "X";
                button7.Enabled = false;
                button8.Text = "0";
                button8.Enabled = false;
            }
            else if (fon == 3)
            {
                button7.Text = "X";
                button7.Enabled = false;
                button2.Text = "0";
                button2.Enabled = false;
            }

        }

        private void button8_Click(object sender, EventArgs e)
        {
            if (fon == 1)
            {
                button8.Text = "X";
                button8.Enabled = false;
                button3.Text = "0";
                button3.Enabled = false;

            }
            else if (fon == 2)
            {
                button8.Text = "X";
                button8.Enabled = false;
                button7.Text = "0";
                button7.Enabled = false;
            }
            else if (fon == 3)
            {
                button8.Text = "X";
                button8.Enabled = false;
                button4.Text = "0";
                button4.Enabled = false;
            }
        }

        private void button9_Click(object sender, EventArgs e)
        {
            if (fon == 1)
            {
                button9.Text = "X";
                button9.Enabled = false;
                button7.Text = "0";
                button7.Enabled = false;

            }
            else if (fon == 2)
            {
                button9.Text = "X";
                button9.Enabled = false;
                button6.Text = "0";
                button6.Enabled = false;
            }
            else if (fon == 3)
            {
                button9.Text = "X";
                button9.Enabled = false;
                button3.Text = "0";
                button3.Enabled = false;
            }
        }

        bool kazan = false;
        bool kazan2 = false;
        private void timer1_Tick(object sender, EventArgs e)
        {
            

            if (button1.Text == "X" && button2.Text == "X" && button3.Text == "X")
            {
                kazan = true;
            }

            else if (button1.Text == "X" && button5.Text == "X" && button9.Text == "X")
            {
                kazan = true;
            }

            else if (button1.Text == "X" && button4.Text == "X" && button7.Text == "X")
            {
                kazan = true;
            }

            else if (button4.Text == "X" && button5.Text == "X" && button6.Text == "X")
            {
                kazan = true;
            }

            else if (button3.Text == "X" && button6.Text == "X" && button9.Text == "X")
            {
                kazan = true;

            else if (button2.Text == "X" && button5.Text == "X" && button8.Text == "X")
            {
                kazan = true;
            }

            else if (button7.Text == "X" && button8.Text == "X" && button9.Text == "X")
            {
                kazan = true;
            }

            else if (button3.Text == "X" && button5.Text == "X" && button7.Text == "X")
            {
                kazan = true;
            }




            else if (button1.Text == "O" && button2.Text == "O" && button3.Text == "O")
            {
                kazan2 = true;
            }

            else if (button1.Text == "O" && button5.Text == "O" && button9.Text == "O")
            {
                kazan2 = true;
            }

            else if (button1.Text == "O" && button4.Text == "O" && button7.Text == "O")
            {
                kazan2 = true;
            }

            else if (button4.Text == "O" && button5.Text == "O" && button6.Text == "O")
            {
                kazan2 = true;
            }

            else if (button3.Text == "O" && button6.Text == "O" && button9.Text == "O")
            {
                kazan2 = true;
            }

            else if (button2.Text == "O" && button5.Text == "O" && button8.Text == "O")
            {
                kazan2 = true;
            }

            else if (button7.Text == "O" && button8.Text == "O" && button9.Text == "O")
            {
                kazan2 = true;
            }

            else if (button3.Text == "O" && button5.Text == "O" && button7.Text == "O")
            {
                kazan2 = true;
            }

        }}



        private void timer2_Tick(object sender, EventArgs e)
        {
            

            if (kazan == true)
            {
                timer2.Stop();
                MessageBox.Show(" you win");
                
                timer2.Start();
                fon = r.Next(1, 4); ;
                button1.Enabled = true;
                button1.Text = " ";
                button2.Enabled = true;
                button2.Text = " ";
                button3.Enabled = true;
                button3.Text = " ";
                button4.Enabled = true;
                button4.Text = " ";
                button5.Enabled = false;
                button5.Text = "O";
                button6.Enabled = true;
                button6.Text = " ";
                button7.Enabled = true;
                button7.Text = " ";
                button8.Enabled = true;
                button8.Text = " ";
                button9.Enabled = true;
                button9.Text = " ";
                kazan = false;
                kazan2 = false;
            }

            else if (kazan2 == true)
            {
                timer2.Stop();
                MessageBox.Show(" pc won");
                
                timer2.Start();
                fon = r.Next(1, 4);
                button1.Enabled = true;
                button1.Text = " ";
                button2.Enabled = true;
                button2.Text = " ";
                button3.Enabled = true;
                button3.Text = " ";
                button4.Enabled = true;
                button4.Text = " ";
                button5.Enabled = false;
                button5.Text = "O";
                button6.Enabled = true;
                button6.Text = " ";
                button7.Enabled = true;
                button7.Text = " ";
                button8.Enabled = true;
                button8.Text = " ";
                button9.Enabled = true;
                button9.Text = " ";
                kazan = false;
                kazan2 = false;
            }

            else if (button1.Enabled == false && button2.Enabled == false && button3.Enabled == false && button4.Enabled == false && button5.Enabled == false && button6.Enabled == false && button7.Enabled == false && button8.Enabled == false && button9.Enabled == false && kazan == false && kazan2 == false)
            {
                

                timer2.Stop();
                MessageBox.Show("no winner");
                button1.Enabled = true;
                button1.Text = " ";
                button2.Enabled = true;
                button2.Text = " ";
                button3.Enabled = true;
                button3.Text = " ";
                button4.Enabled = true;
                button4.Text = " ";
                button5.Enabled = false;
                button5.Text = "O";
                button6.Enabled = true;
                button6.Text = " ";
                button7.Enabled = true;
                button7.Text = " ";
                button8.Enabled = true;
                button8.Text = " ";
                button9.Enabled = true;
                button9.Text = " ";
                kazan = false;
                kazan2 = false;
                timer2.Start();
                fon = r.Next(1, 4);
            }

        }

    }


}

this is program
http://www.tamamsin.com/xox.rar
 
Back
Top Bottom