TIC TAC TOE
Download(87KB) |
Sourcecode:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace TTT
{
/// <summary>
/// Zusammenfassung für Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnEnde;
private System.Windows.Forms.Button btn0;
private System.Windows.Forms.Button btn1;
private System.Windows.Forms.Button btn2;
private System.Windows.Forms.Button btn5;
private System.Windows.Forms.Button btn4;
private System.Windows.Forms.Button btn3;
private System.Windows.Forms.Button btn8;
private System.Windows.Forms.Button btn7;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btnReset;
private System.Windows.Forms.Button btn6;
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Erforderlich für die Windows Form-Designerunterstützung
//
InitializeComponent();
//
// TODO: Fügen Sie den Konstruktorcode nach dem Aufruf von InitializeComponent
hinzu
//
}
/// <summary>
/// Die verwendeten Ressourcen bereinigen.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Vom Windows Form-Designer generierter Code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
private void InitializeComponent()
{
this.btnEnde = new System.Windows.Forms.Button();
this.btn0 = new System.Windows.Forms.Button();
this.btn1 = new System.Windows.Forms.Button();
this.btn2 = new System.Windows.Forms.Button();
this.btn5 = new System.Windows.Forms.Button();
this.btn4 = new System.Windows.Forms.Button();
this.btn3 = new System.Windows.Forms.Button();
this.btn8 = new System.Windows.Forms.Button();
this.btn7 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.btnReset = new System.Windows.Forms.Button();
this.btn6 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnEnde
//
this.btnEnde.Location = new System.Drawing.Point(160, 112);
this.btnEnde.Name = "btnEnde";
this.btnEnde.Size = new System.Drawing.Size(120, 32);
this.btnEnde.TabIndex = 0;
this.btnEnde.Text = "&Ende";
this.btnEnde.Click += new System.EventHandler(this.btnEnde_Click);
//
// btn0
//
this.btn0.Font = new System.Drawing.Font("Verdana Ref", 15.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btn0.Location = new System.Drawing.Point(32, 32);
this.btn0.Name = "btn0";
this.btn0.Size = new System.Drawing.Size(32, 32);
this.btn0.TabIndex = 1;
this.btn0.Click += new System.EventHandler(this.btn0_Click);
//
// btn1
//
this.btn1.Font = new System.Drawing.Font("Verdana Ref", 15.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btn1.Location = new System.Drawing.Point(64, 32);
this.btn1.Name = "btn1";
this.btn1.Size = new System.Drawing.Size(32, 32);
this.btn1.TabIndex = 2;
this.btn1.Click += new System.EventHandler(this.btn1_Click);
//
// btn2
//
this.btn2.Font = new System.Drawing.Font("Verdana Ref", 15.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btn2.Location = new System.Drawing.Point(96, 32);
this.btn2.Name = "btn2";
this.btn2.Size = new System.Drawing.Size(32, 32);
this.btn2.TabIndex = 3;
this.btn2.Click += new System.EventHandler(this.btn2_Click);
//
// btn5
//
this.btn5.Font = new System.Drawing.Font("Verdana Ref", 15.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btn5.Location = new System.Drawing.Point(96, 64);
this.btn5.Name = "btn5";
this.btn5.Size = new System.Drawing.Size(32, 32);
this.btn5.TabIndex = 6;
this.btn5.Click += new System.EventHandler(this.btn5_Click);
//
// btn4
//
this.btn4.Font = new System.Drawing.Font("Verdana Ref", 15.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btn4.Location = new System.Drawing.Point(64, 64);
this.btn4.Name = "btn4";
this.btn4.Size = new System.Drawing.Size(32, 32);
this.btn4.TabIndex = 5;
this.btn4.Click += new System.EventHandler(this.btn4_Click);
//
// btn3
//
this.btn3.Font = new System.Drawing.Font("Verdana Ref", 15.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btn3.Location = new System.Drawing.Point(32, 64);
this.btn3.Name = "btn3";
this.btn3.Size = new System.Drawing.Size(32, 32);
this.btn3.TabIndex = 4;
this.btn3.Click += new System.EventHandler(this.btn3_Click);
//
// btn8
//
this.btn8.Font = new System.Drawing.Font("Verdana Ref", 15.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btn8.Location = new System.Drawing.Point(96, 96);
this.btn8.Name = "btn8";
this.btn8.Size = new System.Drawing.Size(32, 32);
this.btn8.TabIndex = 8;
this.btn8.Click += new System.EventHandler(this.btn8_Click);
//
// btn7
//
this.btn7.Font = new System.Drawing.Font("Verdana Ref", 15.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btn7.Location = new System.Drawing.Point(64, 96);
this.btn7.Name = "btn7";
this.btn7.Size = new System.Drawing.Size(32, 32);
this.btn7.TabIndex = 7;
this.btn7.Click += new System.EventHandler(this.btn7_Click);
//
// label1
//
this.label1.Font = new System.Drawing.Font("Verdana", 14.25F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.Location = new System.Drawing.Point(168, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(112, 32);
this.label1.TabIndex = 10;
this.label1.Text = "Spieler 1";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// btnReset
//
this.btnReset.Location = new System.Drawing.Point(160, 72);
this.btnReset.Name = "btnReset";
this.btnReset.Size = new System.Drawing.Size(120, 32);
this.btnReset.TabIndex = 11;
this.btnReset.Text = "&Reset";
this.btnReset.Click += new System.EventHandler(this.btnReset_Click);
//
// btn6
//
this.btn6.Font = new System.Drawing.Font("Verdana Ref", 15.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btn6.Location = new System.Drawing.Point(32, 96);
this.btn6.Name = "btn6";
this.btn6.Size = new System.Drawing.Size(32, 32);
this.btn6.TabIndex = 12;
this.btn6.Click += new System.EventHandler(this.btn6_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 166);
this.Controls.Add(this.btn6);
this.Controls.Add(this.btnReset);
this.Controls.Add(this.label1);
this.Controls.Add(this.btn8);
this.Controls.Add(this.btn7);
this.Controls.Add(this.btn5);
this.Controls.Add(this.btn4);
this.Controls.Add(this.btn3);
this.Controls.Add(this.btn2);
this.Controls.Add(this.btn1);
this.Controls.Add(this.btn0);
this.Controls.Add(this.btnEnde);
this.Name = "Form1";
this.Text = "Tic Tac Toe";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void btnEnde_Click(object sender, System.EventArgs
e)
{
this.Close();
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
private void btn0_Click(object sender, System.EventArgs e)
{
if(btn0.Text!="")
{
MessageBox.Show ("Bitte eine andere Wahl!", "Tic Tac Toe ERROR",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if(label1.Text=="Spieler 1")
{
btn0.Text="O";
label1.Text="Spieler 2";
}
else
{
btn0.Text="X";
label1.Text="Spieler 1";
}
}
pruefe();
}
private void btn3_Click(object sender, System.EventArgs e)
{
if(btn3.Text!="")
{
MessageBox.Show ("Bitte eine andere Wahl!", "Tic Tac Toe ERROR",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if(label1.Text=="Spieler 1")
{
btn3.Text="O";
label1.Text="Spieler 2";
}
else
{
btn3.Text="X";
label1.Text="Spieler 1";
}
}
pruefe();
}
private void btn2_Click(object sender, System.EventArgs e)
{
if(btn2.Text!="")
{
MessageBox.Show ("Bitte eine andere Wahl!", "Tic Tac Toe ERROR",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if(label1.Text=="Spieler 1")
{
btn2.Text="O";
label1.Text="Spieler 2";
}
else
{
btn2.Text="X";
label1.Text="Spieler 1";
}
}
pruefe();
}
private void btn8_Click(object sender, System.EventArgs e)
{
if(btn8.Text!="")
{
MessageBox.Show ("Bitte eine andere Wahl!", "Tic Tac Toe ERROR",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if(label1.Text=="Spieler 1")
{
btn8.Text="O";
label1.Text="Spieler 2";
}
else
{
btn8.Text="X";
label1.Text="Spieler 1";
}
}
pruefe();
}
private void btn7_Click(object sender, System.EventArgs e)
{
if(btn7.Text!="")
{
MessageBox.Show ("Bitte eine andere Wahl!", "Tic Tac Toe ERROR",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if(label1.Text=="Spieler 1")
{
btn7.Text="O";
label1.Text="Spieler 2";
}
else
{
btn7.Text="X";
label1.Text="Spieler 1";
}
}
pruefe();
}
private void btn6_Click(object sender, System.EventArgs e)
{
if(btn6.Text!="")
{
MessageBox.Show ("Bitte eine andere Wahl!", "Tic Tac Toe ERROR",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if(label1.Text=="Spieler 1")
{
btn6.Text="O";
label1.Text="Spieler 2";
}
else
{
btn6.Text="X";
label1.Text="Spieler 1";
}
}
pruefe();
}
private void btn4_Click(object sender, System.EventArgs e)
{
if(btn4.Text!="")
{
MessageBox.Show ("Bitte eine andere Wahl!", "Tic Tac Toe ERROR",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if(label1.Text=="Spieler 1")
{
btn4.Text="O";
label1.Text="Spieler 2";
}
else
{
btn4.Text="X";
label1.Text="Spieler 1";
}
}
pruefe();
}
private void btn5_Click(object sender, System.EventArgs e)
{
if(btn5.Text!="")
{
MessageBox.Show ("Bitte eine andere Wahl!", "Tic Tac Toe ERROR",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if(label1.Text=="Spieler 1")
{
btn5.Text="O";
label1.Text="Spieler 2";
}
else
{
btn5.Text="X";
label1.Text="Spieler 1";
}
}
pruefe();
}
private void btn1_Click(object sender, System.EventArgs e)
{
if(btn1.Text!="")
{
MessageBox.Show ("Bitte eine andere Wahl!", "Tic Tac Toe ERROR",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if(label1.Text=="Spieler 1")
{
btn1.Text="O";
label1.Text="Spieler 2";
}
else
{
btn1.Text="X";
label1.Text="Spieler 1";
}
}
pruefe();
}
private void btnReset_Click(object sender, System.EventArgs
e)
{
btn0.Text="";
btn1.Text="";
btn2.Text="";
btn3.Text="";
btn4.Text="";
btn5.Text="";
btn6.Text="";
btn7.Text="";
btn8.Text="";
label1.Text="Spieler 1";
}
private void pruefe()
{
if(btn0.Text!=""&&btn0.Text==btn1.Text&&btn1.Text==btn2.Text)
{
MessageBox.Show("Gewonnen!");
}
if(btn3.Text!=""&&btn3.Text==btn4.Text&&btn4.Text==btn5.Text)
{
MessageBox.Show("Gewonnen!");
}
if(btn6.Text!=""&&btn6.Text==btn7.Text&&btn7.Text==btn8.Text)
{
MessageBox.Show("Gewonnen!");
}
if(btn0.Text!=""&&btn0.Text==btn3.Text&&btn3.Text==btn6.Text)
{
MessageBox.Show("Gewonnen!");
}
if(btn1.Text!=""&&btn1.Text==btn4.Text&&btn4.Text==btn7.Text)
{
MessageBox.Show("Gewonnen!");
}
if(btn2.Text!=""&&btn2.Text==btn5.Text&&btn5.Text==btn8.Text)
{
MessageBox.Show("Gewonnen!");
}
if(btn0.Text!=""&&btn0.Text==btn4.Text&&btn4.Text==btn8.Text)
{
MessageBox.Show("Gewonnen!");
}
if(btn2.Text!=""&&btn2.Text==btn4.Text&&btn4.Text==btn6.Text)
{
MessageBox.Show("Gewonnen!");
}
}
}
}