c# matris boyutu kadar textbox oluşturma - sos oyunu oluşturma

637 views
Skip to first unread message

mriz...@gmail.com

unread,
May 22, 2014, 2:31:05 PM5/22/14
to
Arkadaşlar yapmak istediğim şu:

Kullanıcıdan 2 boyutlu matris boyutlarını isteyeceğim

Kullanıcının girdiği boyuta göre formun dizaynında o kadar textbox açılacak

Mesela kullanıcı 5*5 lik bir matris istediyse toplam 25 tane textbox açılması lazım dizaynda.

Bunu nasıl yapabilirm.Acil yardım!!!

c sharp uygulamalar

unread,
May 22, 2014, 4:32:31 PM5/22/14
to
iki tane textbox ve bir tane buton ekleyerek form üzerinde aşağıdaki gibi yapabilirsin 

        private void buttonYukle_Click(object sender, EventArgs e)
        {
            int satir = int.Parse (textBoxSatir.Text);
            int kolon = int.Parse(textBoxKolon.Text);

            for (int i = 0; i < satir; i++)
            {
                for (int j = 0; j < kolon; j++)
                {

                    TextBox yenitextBox = new TextBox();
                    yenitextBox.Location = new System.Drawing.Point(i * 120 + 100, 100 + j * 30);
                    yenitextBox.Name = i + " * " + j;
                    yenitextBox.Size = new System.Drawing.Size(100, 20);
                    yenitextBox.TabIndex = 1;

                    this.Controls.Add(yenitextBox);
                }
            }
        }


21 Mayıs 2014 Çarşamba 14:15:55 UTC+3 tarihinde yazdı:

mriz...@gmail.com

unread,
May 21, 2014, 11:03:26 AM5/21/14
to c-sharp-uygu...@googlegroups.com, Muhammet Rıza Rızaoğlu
Hocam peki bu textboxlara nasıl ulaşacağım.Hepsine tek tek ulaşmam lazım

c sharp uygulamalar

unread,
May 21, 2014, 11:51:33 AM5/21/14
to
Tam olarak textboxlar ile ne yapmak isyorsun?

C SHARP UYGULAMALAR FORUM

unread,
May 22, 2014, 4:33:34 PM5/22/14
to
bir tane generic list oluştur. Oluşturduğun textleri bu listeye ekleyebilirsin. veya en iyisi iki boyutlu bir dizi oluştur.

        TextBox[,] alanlar;

        private void Form_oyun_Load(object sender, EventArgs e)
        {
            alanlar = new TextBox[Form_giriş.satır_sayısı,Form_giriş.sütun_sayısı];

            for (int i = 0; i < Form_giriş.satır_sayısı; i++)
            {
                for (int j = 0; j < Form_giriş.sütun_sayısı; j++)
                {

                    TextBox yenitextBox = new TextBox();
                    yenitextBox.Location = new System.Drawing.Point(i * 25 + 100, 100 + j * 25);
                    yenitextBox.Name = i + " * " + j;
                    yenitextBox.Size = new System.Drawing.Size(20, 20);
                    yenitextBox.TabIndex = 1;
                    yenitextBox.BorderStyle = BorderStyle.FixedSingle;
                  
                    yenitextBox.KeyPress += new KeyPressEventHandler(yenitextBox_KeyPress);

                    this.Controls.Add(yenitextBox);
                    alanlar [i,j] = yenitextBox;
                    
                }
            }
        }

        void yenitextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextBox text =sender as TextBox;
            if (text.TextLength > 1)
                e.Handled = true;

            else
            {

                /// sos pyunu algoritması
            }
        }

21 Mayıs 2014 18:17 tarihinde Muhammet Rıza Rızaoğlu yazdı:
Hocam asıl yapmak istediğim bir sos oyunu.Numericupdownlar ile girilen matris boyutu kadar textbox oluşması tamam.
Bu oluşan textboxlarla sos oyunu yapmam lazım. O yüzden textboxlara erişip kontrol etmem lazım.
Ekte projeyi gönderiyorum.Yardımcı olabilirseniz çok sevinirim...
Teşekkürler


21 Mayıs 2014 18:08 tarihinde c sharp uygulamalar  yazdı:

C SHARP UYGULAMALAR FORUM

unread,
May 22, 2014, 2:40:06 AM5/22/14
to
Aşağıdaki gibi yapabilirsin.



 for (int i = 0; i < Form_giriş.satır_sayısı; i++)
            {
                for (int j = 0; j < Form_giriş.sütun_sayısı; j++)
                {
                    bool sosOlduMu = false;



                    try
                    {
                        if (alanlar[i, j].Text == "S" && alanlar[i, j + 1].Text == "O" && alanlar[i, j + 2].Text == "S")
                            sosOlduMu = true;
                    }
                    catch (Exception) { }
                    try
                    {
                        if (alanlar[i, j].Text == "S" && alanlar[i, j - 1].Text == "O" && alanlar[i, j - 2].Text == "S")
                            sosOlduMu = true;
                    }
                    catch (Exception) { }
                    try
                    {
                        if (alanlar[i, j].Text == "S" && alanlar[i + 1, j].Text == "O" && alanlar[i + 2, j].Text == "S")
                            sosOlduMu = true;
                    }
                    catch (Exception) { }
                    try
                    {
                        if (alanlar[i, j].Text == "S" && alanlar[i - 1, j].Text == "O" && alanlar[i - 2, j].Text == "S")
                            sosOlduMu = true;
                    }
                    catch (Exception) { }
                    try
                    {
                        if (alanlar[i, j].Text == "S" && alanlar[i + 1, j + 1].Text == "O" && alanlar[i + 2, j + 2].Text == "S")
                            sosOlduMu = true;
                    }
                    catch (Exception) { }
                    try
                    {
                        if (alanlar[i, j].Text == "S" && alanlar[i + 1, j - 1].Text == "O" && alanlar[i + 2, j - 2].Text == "S")
                            sosOlduMu = true;
                    }
                    catch (Exception) { }
                    try
                    {
                        if (alanlar[i, j].Text == "S" && alanlar[i - 1, j - 1].Text == "O" && alanlar[i - 2, j - 2].Text == "S")
                            sosOlduMu = true;
                    }
                    catch (Exception) { }
                    try
                    {
                        if (alanlar[i, j].Text == "S" && alanlar[i - 1, j + 1].Text == "O" && alanlar[i - 2, j + 2].Text == "S")

                            sosOlduMu = true;
                    }
                    catch (Exception) { }

                    if (sosOlduMu)
                    {
                        break;
                        MessageBox.Show("SOS");
                    }
                }
            }
22 Mayıs 2014 08:55 tarihinde Muhammet Rıza Rızaoğlu yazdı:
Hocam oyunu algoritma kısmını şöyle yaptım ama dizinin dışına çıkıyor.Bunu nasıl engelleyebilirim?

for (int i = 0; i < Form_giriş.satır_sayısı; i++)
                {
                    for (int j = 0; j < Form_giriş.sütun_sayısı; j++)
                    {
                        if  
                            (
                            (alanlar[i,j].Text=="S" && alanlar[i,j+1].Text=="O"   && alanlar[i,j+2].Text=="S")||
                            (alanlar[i,j].Text=="S" && alanlar[i,j-1].Text=="O"   && alanlar[i,j-2].Text=="S")||
                            (alanlar[i,j].Text=="S" && alanlar[i+1,j].Text=="O"   && alanlar[i+2,j].Text=="S")||
                            (alanlar[i,j].Text=="S" && alanlar[i-1,j].Text=="O"   && alanlar[i-2,j].Text=="S")||
                            (alanlar[i,j].Text=="S" && alanlar[i+1,j+1].Text=="O" && alanlar[i+2,j+2].Text=="S")||
                            (alanlar[i,j].Text=="S" && alanlar[i+1,j-1].Text=="O" && alanlar[i+2,j-2].Text=="S")||
                            (alanlar[i,j].Text=="S" && alanlar[i-1,j-1].Text=="O" && alanlar[i-2,j-2].Text=="S")||
                            (alanlar[i,j].Text=="S" && alanlar[i-1,j+1].Text=="O" && alanlar[i-2,j+2].Text=="S")
                             )
                            
                        {
                           
                            MessageBox.Show("SOS");
                        }
                    }
                }




C SHARP UYGULAMALAR FORUM

unread,
May 22, 2014, 8:09:12 AM5/22/14
to c-sharp-uygu...@googlegroups.com, c-sharp-uygu...@googlegroups.com
Sos oyun son hali

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 sos
{
    public partial class Form_oyun : Form
    {

        int birinci_oyuncu = 0, ikinci_oyuncu = 0;
        public Form_oyun()
        {
            InitializeComponent();
        }
        TextBox[,] alanlar;
        private void Form_oyun_Load(object sender, EventArgs e)
        {


            alanlar = new TextBox[Form_giriş.satır_sayısı, Form_giriş.sütun_sayısı];

            for (int i = 0; i < Form_giriş.satır_sayısı; i++)
            {
                for (int j = 0; j < Form_giriş.sütun_sayısı; j++)
                {

                    TextBox yenitextBox = new TextBox();
                    yenitextBox.Location = new System.Drawing.Point(100 + j * 25, i * 25 + 100);
                    yenitextBox.Name = i + " * " + j;
                    yenitextBox.Size = new System.Drawing.Size(20, 20);
                    yenitextBox.TabIndex = 1;
                    yenitextBox.BorderStyle = BorderStyle.FixedSingle;
 
                    yenitextBox.KeyUp += new KeyEventHandler(yenitextBox_KeyUp);
                    this.Controls.Add(yenitextBox);
                    alanlar[i, j] = yenitextBox;


                }
            }
        }

        void yenitextBox_KeyUp(object sender, KeyEventArgs e)
        {
            this.Focus();
            TextBox text = sender as TextBox;
            label1.Focus();

            if (text.TextLength > 1)
                text.Text = text.Text.Substring(0, 1);
            else
            {
                text.Text = text.Text.ToUpper();
                            MessageBox.Show("SOS :" + text.Text + " OYUNCUSU OYUNUU KAZANDI.", "TEBRİKLER", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            break;
                        }
                    }
                }
            }
        }
    }

}



c sharp uygulamalar

unread,
Mar 25, 2016, 3:43:32 PM3/25/16
to C SHARP UYGULAMALAR FORUM
Reply all
Reply to author
Forward
0 new messages