Konuyu Oyla:
  • Toplam: 0 Oy - Ortalama: 0
  • 1
  • 2
  • 3
  • 4
  • 5
C# arşivim
#1
C# Zar Oyunu

Windows Forms Application ile yapılmıştır.
Pek fazla görselliği olmasa da işinize yarayabilir.
Zar oyunundaki amaç 30 puanı geçen ilk oyuncu kazanıyor. 1. oyuncu başlamadan 2. oyuncu başlıyamıyor.
İşte Kodlar:

Kod:
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 Zar_oyunu
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        int Oyuncu1Puan = 0, Oyuncu2Puan = 0;
        bool Oyuncu1Durum = false, Oyuncu2Durum = false;


        private string Rasgele(Label label)
        {
            Random rastgele = new Random();
            int zar = rastgele.Next(1, 7);
                label.Text = zar.ToString();
            return label.Text;


        }


        void ButonKontrol()
        {
            if(Oyuncu1Durum==false)
        {
            button1.Enabled=true;
            button2.Enabled=false;
        }
            if (Oyuncu2Durum == false)
            {
                button2.Enabled = true;
                button1.Enabled = false;
            }
        }


        void YeniOyun()
        {
            Oyuncu1Durum = false;
            Oyuncu2Durum = false;
            Oyuncu1Puan = 0;
            Oyuncu2Puan = 0;
            button1.Enabled = true;
            button2.Enabled = true;
            label1.Text = "";
            label2.Text = "";
            label3.Text = "";
            label4.Text = "";
        }


        private void button1_Click(object sender, EventArgs e)
        {
            Rasgele(label1);
            Oyuncu1Puan = Oyuncu1Puan + Convert.ToInt16(label1.Text);
            label3.Text = Oyuncu1Puan.ToString();
            Oyuncu1Durum = true;
            Oyuncu2Durum = false;
            ButonKontrol();
            if (Oyuncu1Puan >= 30)
            {
                MessageBox.Show("Tebrikler, 1.Oyuncu Kazandı.", "Tebrikler..");
            }
        }


        private void button2_Click(object sender, EventArgs e)
        {
            
            if (button1.Enabled == true)
            {
                MessageBox.Show("Önce 1.Oyuncu Oynamalıdır!", "Hata");
            }


            else
            {
                Rasgele(label2);
                Oyuncu2Puan = Oyuncu2Puan + Convert.ToInt16(label2.Text);
                label4.Text = Oyuncu2Puan.ToString();
                Oyuncu2Durum = true;
                Oyuncu1Durum = false;
                ButonKontrol();
                if (Oyuncu2Puan >= 30)
                {
                    MessageBox.Show("Tebrikler, 2.Oyuncu Kazandı.", "Tebrikler..");
                }
            }
        }


        private void button3_Click(object sender, EventArgs e)

        {
            YeniOyun();
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            YeniOyun();
        }
    }
}

C# / Factöriyel Bulma

Kod:
{
int  sayi, sonuc;

sonuc=1;
sayi =Int32.Parse(textbox1.text);
for (int  i = sayi;  i > 1; i++)
     sonuc *= i;
textbox2.text = sonuc.ToString();

}

Metinden dosya ve klasör adı üretme
Kod:
public static string FilenameFromTitle(string name)
{
    string safe = name.Trim();

    safe = safe.Replace(" ", "-").ToLower();

    if(safe.IndexOf("--") > -1)
        while(safe.IndexOf("--") > -1)
            safe = safe.Replace("--", "-");

    safe = Regex.Replace(safe, "[^a-z0-9\\-]", "");

    if(safe.Length > 50)
        safe = safe.Substring(0, 49);

    // clean the beginning and end of the filename
    char[] replace = {'-','.'};
    safe = safe.TrimStart(replace);
    safe = safe.TrimEnd(replace);

    return safe;
}

Kapat butonunu pasifleştirmek
Kod:
private const int SC_CLOSE = 0xF060;
          private const int MF_GRAYED = 0x1;

          [DllImport("user32.dll")]
          private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);

          [DllImport("user32.dll")]
          private static extern int EnableMenuItem(IntPtr hMenu, int wIDEnableItem, int wEnable);

          private void Form1_Load(object sender, System.EventArgs e)
          {
               EnableMenuItem(GetSystemMenu(this.Handle, false), SC_CLOSE, MF_GRAYED);
          }

Okul Ziyaretçi Takip

Kod:
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using System.Data.OleDb;

namespace Okul_Ziyaretçi_Takip

{

public partial class Form1 : Form

{

public Ekle FrmEkle;

public Ara FrmAra;

public Güncelle frmGuncelle;

public Form1()

{

InitializeComponent();

FrmEkle=new Ekle();

FrmAra=new Ara();

frmGuncelle=new Güncelle();

FrmEkle.frmAnaSayfa = this;

FrmAra.frmAnaSayfa = this;

frmGuncelle.frmAnaSayfa = this;

}

OleDbConnection baglantı = new OleDbConnection("Provider=Microsoft.Ace.OleDb.12.0;Data Source=data.accdb");

void bag()

{

DataTable tablo = new DataTable();

OleDbDataAdapter adaptör = new OleDbDataAdapter("Select * From okul", baglantı);

adaptör.Fill(tablo);

dataGridView1.DataSource = tablo;

}

private void Form1_Load(object sender, EventArgs e)

{

bag();

dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

dataGridView1.Columns[0].HeaderText = "TC Kimlik No";

dataGridView1.Columns[4].HeaderText = "Giriş Saati";

dataGridView1.Columns[5].HeaderText = "Çıkış Saati";

dataGridView1.Columns[6].HeaderText = "Kimi Ziyaret Etti";

}

private void btnEkle_Click(object sender, EventArgs e)

{

FrmEkle.ShowDialog();

}

private void btnGüncelle_Click(object sender, EventArgs e)

{

frmGuncelle.ShowDialog();

}

private void btnAra_Click(object sender, EventArgs e)

{

this.Hide();

FrmAra.Show();

}

private void btnCıkıs_Click(object sender, EventArgs e)

{

DialogResult soru;

soru = MessageBox.Show("Program Kapatılsınmı","Çıkış",MessageBoxButtons.YesNo,MessageBoxIcon.Question);

if (soru == DialogResult.Yes) Application.Exit();

}

private void btnSil_Click(object sender, EventArgs e)

{

DialogResult Soru;

Soru = MessageBox.Show("Ziyaretçi Silinsinmi","Soru",MessageBoxButtons.YesNo,MessageBoxIcon.Question);

if (Soru == DialogResult.Yes)

{

OleDbCommand komut = new OleDbCommand();

baglantı.Open();

komut.Connection = baglantı;

komut.CommandText = "DELETE FROM okul Where TcKimlikNo=İ" + dataGridView1.CurrentRow.Cells[0].Value.ToString() + "İ";

komut.ExecuteNonQuery();

baglantı.Close();

bag();

}

}

}

}

Çalıştır Komutu
Kod:
System.Diagnostics.Process.Start("buraya açilacak dosyayi yaziyoruz")

Dizideki tekrarlanan elemanları silme
Kod:
// Fonksiyon Kodları
public static Array DeleteDuplicates(Array arr)
{
   // this procedure works only with vectors
   if (arr.Rank != 1 )
      throw new ArgumentException("Multiple-dimension arrays are not supported");

   // we use a hashtable to track duplicates
   // make the hash table large enough to avoid memory re-allocations
   Hashtable ht = new Hashtable(arr.Length * 2);
   // we will store unique elements in this ArrayList
   ArrayList elements = new ArrayList();

   foreach (object Value in arr)
   {
      if ( !ht.Contains(Value) )
      {
         // we've found a non duplicate
         elements.Add(Value);
         // remember it for later
         ht.Add(Value, null);
      }
   }
   // return an array of same type as the original array
   return elements.ToArray(arr.GetType().GetElementType());
}

// Örnek Kullanım:
int[] numbers = new int[] {1, 3, 5, 2, 3, 1, 4};
int[] result = (int[]) DropDuplicates(numbers);
foreach (int num in result)
   Console.WriteLine(num);

C# Öğrenmeye çalışırken denediğim bazı kodlardır.
Okyanusta batan gemidir yalnızlık,
Çok derinlerdedir gücün yetmez onu oradan çıkarmaya.
Kaybolup gider daha sonra.
Kendi kendine konuşmaktır yalnızlık...
Belkide en iyi tarafıdır bu
Kendini sorgularsın, bir kez olsun çekersin köşeye nefsini hayatı anlamaya çalışırsın.

Cevapla


Hızlı Menü:


Şu anda bu konuyu okuyanlar: 1 Ziyaretçi

Online Shopping App
Online Shopping - E-Commerce Platform
Online Shopping - E-Commerce Platform
Feinunze Schmuck Jewelery Online Shopping