اذهب إلى المحتوى
  • 0

لعبة Tic Tac toa ويندوز C#

AM0

السؤال

Recommended Posts

  • 0
بتاريخ 4 ساعات قال AM0:

اكوادي هذي كنت ابغا احط قائمه فيها العب من جديد او مو شرط قائمه بس ابغا اضغط ويخلي الللعبه تنعاد يعني ابغا شيفره تعيد لي اللعبه 

مرحبًا @AM0,

الشيفرة لديك تعمل جيداً و لعمل ميزة إعادة اللعبة :

  • أولاً داخل الدلة winner() نقوم بتوقيف السطر :
  • Application.Exit();

    حتى لا يتوقف البرنامج عند إنتهاء اللعبة .

  • بعد ذلك نقوم بعمل زر جديد و عند الضعط عليه نُعيد اللعبة من جديد بهذه الشيفرة:

  • count = 0;
    
    button1.Text = "";
    button1.Enabled = true;
    
    button2.Text = "";
    button2.Enabled = true;
    
    button3.Text = "";
    button3.Enabled = true;
    
    button4.Text = "";
    button4.Enabled = true;
    
    button5.Text = "";
    button5.Enabled = true;
    
    button6.Text = "";
    button6.Enabled = true;
    
    button7.Text = "";
    button7.Enabled = true;
    
    button8.Text = "";
    button8.Enabled = true;
    
    button9.Text = "";
    button9.Enabled = true;

    المنطق هو اننا نقوم بإعادة قيمة المتغير count الى الصفر و نص كل الأزرار إلى الوضع الإفتراضي مع عمل ذلك يصبح وكأننا قمنا بإعادة تشغيل البرنامج و يُمكننا اللعب من جديد .

رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • 0

اكوادي هذي كنت ابغا احط قائمه فيها العب من جديد او مو شرط قائمه بس ابغا اضغط ويخلي الللعبه تنعاد يعني ابغا شيفره تعيد لي اللعبه 

هذي الاكواد 

 public partial class Form1 : Form
    {
        int count = 0;
        public Form1()
        {
            InitializeComponent();
        }
 
        private void winner()
        {

            if ((button1.Text == button2.Text) && (button1.Text == button3.Text) && button1.Text!="")
            {
                if (count % 2 == 0)
                {
                    MessageBox.Show("Player 1 is the winner");
                    Application.Exit();
                }
                else
                {
                    MessageBox.Show("Player 2 is the winner");
                    Application.Exit();
                }

            }
            if ((button4.Text == button5.Text) && (button4.Text == button6.Text) && button4.Text != "")
            {
                if (count % 2 == 0)
                {
                    MessageBox.Show("Player 1 is the winner");
                    Application.Exit();
                }
                else
                {
                    MessageBox.Show("Player 2 is the winner");
                    Application.Exit();
                }

            }
            if ((button7.Text == button8.Text) && (button8.Text == button9.Text) && button7.Text != "")
            {
                if (count % 2 == 0)
                {
                    MessageBox.Show("Player 1 is the winner");
                    Application.Exit();
                }
                else
                {
                    MessageBox.Show("Player 2 is the winner");
                    Application.Exit();
                }

            }
            if ((button1.Text == button4.Text) && (button4.Text == button7.Text) && button1.Text != "")
            {
                if (count % 2 == 0)
                {
                    MessageBox.Show("Player 1 is the winner");
                    Application.Exit();
                }
                else
                {
                    MessageBox.Show("Player 2 is the winner");
                    Application.Exit();
                }

            }
            if ((button2.Text == button5.Text) && (button2.Text == button8.Text) && button2.Text != "")
            {
                if (count % 2 == 0)
                {
                    MessageBox.Show("Player 1 is the winner");
                    Application.Exit();
                }
                else
                {
                    MessageBox.Show("Player 2 is the winner");
                    Application.Exit();
                }

            }
            if ((button3.Text == button6.Text) && (button3.Text == button9.Text) && button3.Text != "")
            {
                if (count % 2 == 0)
                {
                    MessageBox.Show("Player 1 is the winner");
                    Application.Exit();
                }
                else
                {
                    MessageBox.Show("Player 2 is the winner");
                    Application.Exit();
                }

            }
            if ((button1.Text == button5.Text) && (button1.Text == button9.Text) && button1.Text != "")
            {
                if (count % 2 == 0)
                {
                    MessageBox.Show("Player 1 is the winner");
                    Application.Exit();
                }
                else
                {
                    MessageBox.Show("Player 2 is the winner");
                    Application.Exit();
                }

            }
            if ((button3.Text == button5.Text) && (button3.Text == button7.Text) && button3.Text != "")
            {
                if (count % 2 == 0)
                {
                    MessageBox.Show("Player 1 is the winner");
                    Application.Exit();
                }
                else
                {
                    MessageBox.Show("Player 2 is the winner");
                    Application.Exit();
                }

            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (count % 2==0)
            {
                button1.Text = "O";
                button1.Enabled = false;
                winner();
                count++;
            }
            else
            {

                button1.Text = "X";
                button1.Enabled = false;
                winner();
                count++;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {

            if (count % 2 == 0)
            {
                button2.Text = "O";
                button2.Enabled = false;
                winner();
                count++;
            }
            else
            {

                button2.Text = "X";
                button2.Enabled = false;
                winner();
                count++;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {

            if (count % 2 == 0)
            {
                button3.Text = "O";
                button3.Enabled = false;
                winner();
                count++;
            }
            else
            {

                button3.Text = "X";
                button3.Enabled = false;
                winner();
                count++;
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {

            if (count % 2 == 0)
            {
                button4.Text = "O";
                button4.Enabled = false;
                winner();
                count++;
            }
            else
            {

                button4.Text = "X";
                button4.Enabled = false;
                winner();
                count++;
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {

            if (count % 2 == 0)
            {
                button5.Text = "O";
                button5.Enabled = false;
                winner();
                count++;
            }
            else
            {

                button5.Text = "X";
                button5.Enabled = false;
                winner();
                count++;
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {

            if (count % 2 == 0)
            {
                button6.Text = "O";
                button6.Enabled = false;
                winner();
                count++;
            }
            else
            {

                button6.Text = "X";
                button6.Enabled = false;
                winner();
                count++;
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {

            if (count % 2 == 0)
            {
                button7.Text = "O";
                button7.Enabled = false;
                winner();
                count++;
            }
            else
            {

                button7.Text = "X";
                button7.Enabled = false;
                winner();
                count++;
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {

            if (count % 2 == 0)
            {
                button8.Text = "O";
                button8.Enabled = false;
                winner();
                count++;
            }
            else
            {

                button8.Text = "X";
                button8.Enabled = false;
                winner();
                count++;
            }
        }

        private void button9_Click(object sender, EventArgs e)
        {

            if (count % 2 == 0)
            {
                button9.Text = "O";
                button9.Enabled = false;
                winner();
                count++;
            }
            else
            {

                button9.Text = "X";
                button9.Enabled = false;
                winner();
                count++;
            }
        }
    }

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...