الانتقال إلى المحتوى

لغه سي شارب تصميم لعبه Tic Tac Toe


odai alhjahjah

Recommended Posts

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

 

 

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 tic_tak_toe__x_and_o__
{
    public partial class Form1 : Form
    {
        Button[,]bttn=new Button[3,3];
        enum gametype { x, o };
        gametype currengame = gametype.x;
        int count = 0;
 
        
        public Form1()
        {
            InitializeComponent();
 
            bttn[0, 0] = btn00; bttn[0, 1] = btn01; bttn[0, 2] = btn02;
 
            bttn[1, 0] = btn10; bttn[1, 1] = btn11; bttn[1, 2] = btn12;
 
            bttn[2, 0] = btn20; bttn[2, 1] = btn21; bttn[2, 2] = btn22;
            clearall();
            
        }
 
        private void clearall()
        {
            foreach (Button b in bttn)
               b.Text="";
 
            count = 0;
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
 
        }
 
        private void buttnplay_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;
            if (btn.Text != "") return;
            btn.Text = currengame.ToString();
            count = count + 1;
            if (iswin())
            {
                MessageBox.Show("Carp you've won");
            clearall();
            return;
 
            }
            if (count == 9)
            {
                MessageBox.Show("tie");
                clearall();
            }
            switchGame();
        }
 
        private bool iswin()
        {
            for (int r = 0; r <= 2; r++)
            {
                int samegame = 0;
                for (int c = 0; c <= 2; c++)
                {
                    if (bttn[r, c].Text == currengame.ToString()) samegame = samegame + 1;
                }
                if (samegame == 3)
                {
                    return true;
                }
            }
           
                for (int c = 0; c <= 2; c++)
                {
                    int samegame = 0;
                    for (int r = 0; r <= 2; r++)
                    {
                        if (bttn[r, c].Text == currengame.ToString()) samegame = samegame + 1;
                    }
                    if (samegame == 3)
                    {
                        return true;
                    }
                }
                if (bttn[0, 0].Text == currengame.ToString() &&
                    bttn[1, 1].Text == currengame.ToString() &&
                    bttn[2, 2].Text == currengame.ToString()) return true;
 
 
                if (bttn[0, 2].Text == currengame.ToString() &&
                    bttn[1, 1].Text == currengame.ToString() &&
                    bttn[2, 0].Text == currengame.ToString()) return true;
                return false;
            }
       
        private void switchGame()
        {
            if (currengame == gametype.x)
                currengame = gametype.o;
            else
                currengame = gametype.x;
        }
 
        private void button8_Click(object sender, EventArgs e)
        {
 
        }
    }
}
 
رابط هذا التعليق
شارك

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

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

زائر
أضف رد على هذا الموضوع...

×   Pasted as rich text.   Paste as plain text instead

  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.

جاري التحميل
×
×
  • أضف...

برجاء الإنتباه

بإستخدامك للموقع فأنت تتعهد بالموافقة على هذه البنود: سياسة الخصوصية