diff --git a/Lernprogramm3_Matchinggame/.vs/Lernprogramm3_Matchinggame/v17/.suo b/Lernprogramm3_Matchinggame/.vs/Lernprogramm3_Matchinggame/v17/.suo index 8d562f4..edccf3f 100644 Binary files a/Lernprogramm3_Matchinggame/.vs/Lernprogramm3_Matchinggame/v17/.suo and b/Lernprogramm3_Matchinggame/.vs/Lernprogramm3_Matchinggame/v17/.suo differ diff --git a/Lernprogramm3_Matchinggame/Lernprogramm3_Matchinggame/Form1.Designer.cs b/Lernprogramm3_Matchinggame/Lernprogramm3_Matchinggame/Form1.Designer.cs index df0037f..0939c35 100644 --- a/Lernprogramm3_Matchinggame/Lernprogramm3_Matchinggame/Form1.Designer.cs +++ b/Lernprogramm3_Matchinggame/Lernprogramm3_Matchinggame/Form1.Designer.cs @@ -29,22 +29,22 @@ private void InitializeComponent() { this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); - this.label1 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); - this.label3 = new System.Windows.Forms.Label(); - this.label4 = new System.Windows.Forms.Label(); - this.label5 = new System.Windows.Forms.Label(); - this.label6 = new System.Windows.Forms.Label(); - this.label7 = new System.Windows.Forms.Label(); - this.label8 = new System.Windows.Forms.Label(); - this.label9 = new System.Windows.Forms.Label(); - this.label10 = new System.Windows.Forms.Label(); - this.label11 = new System.Windows.Forms.Label(); - this.label12 = new System.Windows.Forms.Label(); - this.label13 = new System.Windows.Forms.Label(); - this.label14 = new System.Windows.Forms.Label(); - this.label15 = new System.Windows.Forms.Label(); this.label16 = new System.Windows.Forms.Label(); + this.label15 = new System.Windows.Forms.Label(); + this.label14 = new System.Windows.Forms.Label(); + this.label13 = new System.Windows.Forms.Label(); + this.label12 = new System.Windows.Forms.Label(); + this.label11 = new System.Windows.Forms.Label(); + this.label10 = new System.Windows.Forms.Label(); + this.label9 = new System.Windows.Forms.Label(); + this.label8 = new System.Windows.Forms.Label(); + this.label7 = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); this.tableLayoutPanel1.SuspendLayout(); this.SuspendLayout(); // @@ -84,101 +84,89 @@ this.tableLayoutPanel1.Size = new System.Drawing.Size(534, 511); this.tableLayoutPanel1.TabIndex = 0; // - // label1 - // - this.label1.AutoSize = true; - this.label1.Dock = System.Windows.Forms.DockStyle.Fill; - this.label1.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); - this.label1.Location = new System.Drawing.Point(3, 0); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(127, 127); - this.label1.TabIndex = 0; - this.label1.Text = "label1"; - this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // label2 + // label16 // - this.label2.AutoSize = true; - this.label2.Dock = System.Windows.Forms.DockStyle.Fill; - this.label2.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); - this.label2.Location = new System.Drawing.Point(136, 0); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(127, 127); - this.label2.TabIndex = 1; - this.label2.Text = "label2"; - this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label16.AutoSize = true; + this.label16.Dock = System.Windows.Forms.DockStyle.Fill; + this.label16.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this.label16.Location = new System.Drawing.Point(402, 381); + this.label16.Name = "label16"; + this.label16.Size = new System.Drawing.Size(129, 130); + this.label16.TabIndex = 15; + this.label16.Text = "label16"; + this.label16.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // label3 + // label15 // - this.label3.AutoSize = true; - this.label3.Dock = System.Windows.Forms.DockStyle.Fill; - this.label3.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); - this.label3.Location = new System.Drawing.Point(269, 0); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(127, 127); - this.label3.TabIndex = 2; - this.label3.Text = "label3"; - this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label15.AutoSize = true; + this.label15.Dock = System.Windows.Forms.DockStyle.Fill; + this.label15.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this.label15.Location = new System.Drawing.Point(269, 381); + this.label15.Name = "label15"; + this.label15.Size = new System.Drawing.Size(127, 130); + this.label15.TabIndex = 14; + this.label15.Text = "label15"; + this.label15.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // label4 + // label14 // - this.label4.AutoSize = true; - this.label4.Dock = System.Windows.Forms.DockStyle.Fill; - this.label4.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); - this.label4.Location = new System.Drawing.Point(402, 0); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(129, 127); - this.label4.TabIndex = 3; - this.label4.Text = "label4"; - this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label14.AutoSize = true; + this.label14.Dock = System.Windows.Forms.DockStyle.Fill; + this.label14.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this.label14.Location = new System.Drawing.Point(136, 381); + this.label14.Name = "label14"; + this.label14.Size = new System.Drawing.Size(127, 130); + this.label14.TabIndex = 13; + this.label14.Text = "label14"; + this.label14.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // label5 + // label13 // - this.label5.AutoSize = true; - this.label5.Dock = System.Windows.Forms.DockStyle.Fill; - this.label5.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); - this.label5.Location = new System.Drawing.Point(3, 127); - this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(127, 127); - this.label5.TabIndex = 4; - this.label5.Text = "label5"; - this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label13.AutoSize = true; + this.label13.Dock = System.Windows.Forms.DockStyle.Fill; + this.label13.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this.label13.Location = new System.Drawing.Point(3, 381); + this.label13.Name = "label13"; + this.label13.Size = new System.Drawing.Size(127, 130); + this.label13.TabIndex = 12; + this.label13.Text = "label13"; + this.label13.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // label6 + // label12 // - this.label6.AutoSize = true; - this.label6.Dock = System.Windows.Forms.DockStyle.Fill; - this.label6.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); - this.label6.Location = new System.Drawing.Point(136, 127); - this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(127, 127); - this.label6.TabIndex = 5; - this.label6.Text = "label6"; - this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label12.AutoSize = true; + this.label12.Dock = System.Windows.Forms.DockStyle.Fill; + this.label12.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this.label12.Location = new System.Drawing.Point(402, 254); + this.label12.Name = "label12"; + this.label12.Size = new System.Drawing.Size(129, 127); + this.label12.TabIndex = 11; + this.label12.Text = "label12"; + this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // label7 + // label11 // - this.label7.AutoSize = true; - this.label7.Dock = System.Windows.Forms.DockStyle.Fill; - this.label7.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); - this.label7.Location = new System.Drawing.Point(269, 127); - this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(127, 127); - this.label7.TabIndex = 6; - this.label7.Text = "label7"; - this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label11.AutoSize = true; + this.label11.Dock = System.Windows.Forms.DockStyle.Fill; + this.label11.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this.label11.Location = new System.Drawing.Point(269, 254); + this.label11.Name = "label11"; + this.label11.Size = new System.Drawing.Size(127, 127); + this.label11.TabIndex = 10; + this.label11.Text = "label11"; + this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // label8 + // label10 // - this.label8.AutoSize = true; - this.label8.Dock = System.Windows.Forms.DockStyle.Fill; - this.label8.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); - this.label8.Location = new System.Drawing.Point(402, 127); - this.label8.Name = "label8"; - this.label8.Size = new System.Drawing.Size(129, 127); - this.label8.TabIndex = 7; - this.label8.Text = "label8"; - this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label10.AutoSize = true; + this.label10.Dock = System.Windows.Forms.DockStyle.Fill; + this.label10.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this.label10.Location = new System.Drawing.Point(136, 254); + this.label10.Name = "label10"; + this.label10.Size = new System.Drawing.Size(127, 127); + this.label10.TabIndex = 9; + this.label10.Text = "label10"; + this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // label9 // @@ -192,89 +180,101 @@ this.label9.Text = "label9"; this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // label10 + // label8 // - this.label10.AutoSize = true; - this.label10.Dock = System.Windows.Forms.DockStyle.Fill; - this.label10.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); - this.label10.Location = new System.Drawing.Point(136, 254); - this.label10.Name = "label10"; - this.label10.Size = new System.Drawing.Size(127, 127); - this.label10.TabIndex = 9; - this.label10.Text = "label10"; - this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label8.AutoSize = true; + this.label8.Dock = System.Windows.Forms.DockStyle.Fill; + this.label8.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this.label8.Location = new System.Drawing.Point(402, 127); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(129, 127); + this.label8.TabIndex = 7; + this.label8.Text = "label8"; + this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // label11 + // label7 // - this.label11.AutoSize = true; - this.label11.Dock = System.Windows.Forms.DockStyle.Fill; - this.label11.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); - this.label11.Location = new System.Drawing.Point(269, 254); - this.label11.Name = "label11"; - this.label11.Size = new System.Drawing.Size(127, 127); - this.label11.TabIndex = 10; - this.label11.Text = "label11"; - this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label7.AutoSize = true; + this.label7.Dock = System.Windows.Forms.DockStyle.Fill; + this.label7.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this.label7.Location = new System.Drawing.Point(269, 127); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(127, 127); + this.label7.TabIndex = 6; + this.label7.Text = "label7"; + this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // label12 + // label6 // - this.label12.AutoSize = true; - this.label12.Dock = System.Windows.Forms.DockStyle.Fill; - this.label12.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); - this.label12.Location = new System.Drawing.Point(402, 254); - this.label12.Name = "label12"; - this.label12.Size = new System.Drawing.Size(129, 127); - this.label12.TabIndex = 11; - this.label12.Text = "label12"; - this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label6.AutoSize = true; + this.label6.Dock = System.Windows.Forms.DockStyle.Fill; + this.label6.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this.label6.Location = new System.Drawing.Point(136, 127); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(127, 127); + this.label6.TabIndex = 5; + this.label6.Text = "label6"; + this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // label13 + // label5 // - this.label13.AutoSize = true; - this.label13.Dock = System.Windows.Forms.DockStyle.Fill; - this.label13.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); - this.label13.Location = new System.Drawing.Point(3, 381); - this.label13.Name = "label13"; - this.label13.Size = new System.Drawing.Size(127, 130); - this.label13.TabIndex = 12; - this.label13.Text = "label13"; - this.label13.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label5.AutoSize = true; + this.label5.Dock = System.Windows.Forms.DockStyle.Fill; + this.label5.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this.label5.Location = new System.Drawing.Point(3, 127); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(127, 127); + this.label5.TabIndex = 4; + this.label5.Text = "label5"; + this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // label14 + // label4 // - this.label14.AutoSize = true; - this.label14.Dock = System.Windows.Forms.DockStyle.Fill; - this.label14.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); - this.label14.Location = new System.Drawing.Point(136, 381); - this.label14.Name = "label14"; - this.label14.Size = new System.Drawing.Size(127, 130); - this.label14.TabIndex = 13; - this.label14.Text = "label14"; - this.label14.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label4.AutoSize = true; + this.label4.Dock = System.Windows.Forms.DockStyle.Fill; + this.label4.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this.label4.Location = new System.Drawing.Point(402, 0); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(129, 127); + this.label4.TabIndex = 3; + this.label4.Text = "label4"; + this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // label15 + // label3 // - this.label15.AutoSize = true; - this.label15.Dock = System.Windows.Forms.DockStyle.Fill; - this.label15.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); - this.label15.Location = new System.Drawing.Point(269, 381); - this.label15.Name = "label15"; - this.label15.Size = new System.Drawing.Size(127, 130); - this.label15.TabIndex = 14; - this.label15.Text = "label15"; - this.label15.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label3.AutoSize = true; + this.label3.Dock = System.Windows.Forms.DockStyle.Fill; + this.label3.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this.label3.Location = new System.Drawing.Point(269, 0); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(127, 127); + this.label3.TabIndex = 2; + this.label3.Text = "label3"; + this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // label16 + // label2 // - this.label16.AutoSize = true; - this.label16.Dock = System.Windows.Forms.DockStyle.Fill; - this.label16.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); - this.label16.Location = new System.Drawing.Point(402, 381); - this.label16.Name = "label16"; - this.label16.Size = new System.Drawing.Size(129, 130); - this.label16.TabIndex = 15; - this.label16.Text = "label16"; - this.label16.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label2.AutoSize = true; + this.label2.Dock = System.Windows.Forms.DockStyle.Fill; + this.label2.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this.label2.Location = new System.Drawing.Point(136, 0); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(127, 127); + this.label2.TabIndex = 1; + this.label2.Text = "label2"; + this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Dock = System.Windows.Forms.DockStyle.Fill; + this.label1.Font = new System.Drawing.Font("Webdings", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this.label1.Location = new System.Drawing.Point(3, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(127, 127); + this.label1.TabIndex = 0; + this.label1.Text = "label1"; + this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // Form1 // diff --git a/Lernprogramm3_Matchinggame/Lernprogramm3_Matchinggame/Form1.cs b/Lernprogramm3_Matchinggame/Lernprogramm3_Matchinggame/Form1.cs index 3ee54e3..57a40b3 100644 --- a/Lernprogramm3_Matchinggame/Lernprogramm3_Matchinggame/Form1.cs +++ b/Lernprogramm3_Matchinggame/Lernprogramm3_Matchinggame/Form1.cs @@ -6,5 +6,108 @@ namespace Lernprogramm3_Matchinggame { InitializeComponent(); } + + private void RefreshWindowTitle() + { + Text = string.Format("Lernprogramm 3: MatchingGame [Moves: {0}]", Math.Floor((double)moves / 2)); + } + + Random rdm = new(); + + List icons = new() + { + "!", + "!", + "N", + "N", + ",", + ",", + "k", + "k", + "b", + "b", + "v", + "v", + "w", + "w", + "z", + "z" + }; + + Dictionary controlIcons = new(); + + Control flipped1; + Control flipped2; + + int moves = 0; + + private void Form1_Load(object sender, EventArgs e) + { + foreach (Control con in tableLayoutPanel1.Controls) + { + int nextIndex = rdm.Next(icons.Count); + + string icon = icons[nextIndex]; + icons.RemoveAt(nextIndex); + + con.Text = ""; + controlIcons[con] = new ControlIconDefinition() { Icon = icon }; + + con.Click += (_, _) => + { + if (flipped1 != null && flipped2 != null) + { + flipped1.BackColor = Color.CornflowerBlue; + flipped2.BackColor = Color.CornflowerBlue; + flipped1.Text = ""; + flipped2.Text = ""; + flipped1 = null; + flipped2 = null; + } + if (controlIcons[con].Found) + { + return; + } + + moves++; + RefreshWindowTitle(); + + con.BackColor = Color.Orange; + + if (flipped1 == null) + { + flipped1 = con; + + flipped1.Text = controlIcons[flipped1].Icon; + + return; + } + if (flipped2 == null) + { + flipped2 = con; + + flipped2.Text = controlIcons[flipped2].Icon; + + if (flipped2.Text == flipped1.Text) + { + // success + foreach (Control cont in new Control[] { flipped1, flipped2 }) + { + cont.BackColor = Color.Green; + controlIcons[cont].Found = true; + } + flipped1 = null; + flipped2 = null; + } + } + }; + } + } + } + + class ControlIconDefinition + { + public string Icon { get; set; } + public bool Found { get; set; } = false; } } \ No newline at end of file