diff --git a/Form1.Designer.cs b/Form1.Designer.cs
index 70a454b..f8decc1 100644
--- a/Form1.Designer.cs
+++ b/Form1.Designer.cs
@@ -1,14 +1,14 @@
-namespace Lotto040625
+namespace LottoGame
{
partial class Form1
{
///
- /// Required designer variable.
+ /// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
- /// Clean up any resources being used.
+ /// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
@@ -23,17 +23,17 @@
#region Windows Form Designer generated code
///
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
- this.Text = "Form1";
+ this.Text = "Lotto Game";
}
#endregion
}
-}
+}
\ No newline at end of file
diff --git a/Form1.cs b/Form1.cs
index 2aab53b..14cb93f 100644
--- a/Form1.cs
+++ b/Form1.cs
@@ -1,10 +1,261 @@
-namespace Lotto040625
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Windows.Forms;
+
+namespace LottoGame
{
public partial class Form1 : Form
{
+
+ private int meinGeld = 2000;
+ private List meineZahlen = new List();
+ private int spielAnzahl = 0;
+
+
+ private Button[] alleButtons = new Button[49];
+ private Label geldAnzeige;
+ private Label ergebnisAnzeige;
+ private Button spielButton;
+ private Label spielZaehler;
+
+
+ private const int KOSTEN_PRO_SPIEL = 5;
+ private const int ZAHLEN_AUSWAHL = 7;
+ private const int MAX_ZAHL = 49;
+
public Form1()
{
InitializeComponent();
+ SpielfeldErstellen();
+ }
+
+ private void SpielfeldErstellen()
+ {
+
+ this.Text = "Lotto Spiel";
+ this.Size = new Size(800, 600);
+ this.BackColor = Color.FromArgb(240, 248, 255);
+
+
+ int buttonGroesse = 45;
+ int abstand = 8;
+ int startX = 30;
+ int startY = 30;
+
+
+ ErstelleZahlenButtons(buttonGroesse, abstand, startX, startY);
+
+
+ int rechteSeiteX = startX + 7 * (buttonGroesse + abstand) + 40;
+ int rechteSeiteY = startY + 30;
+
+
+ ErstelleSpielButton(rechteSeiteX, rechteSeiteY);
+
+
+ ErstelleGeldAnzeige(rechteSeiteX, rechteSeiteY);
+
+
+ ErstelleSpielZaehler(rechteSeiteX, rechteSeiteY);
+
+
+ ErstelleErgebnisAnzeige(startX, startY, buttonGroesse, abstand);
+ }
+
+ private void ErstelleZahlenButtons(int buttonGroesse, int abstand, int startX, int startY)
+ {
+ for (int i = 0; i < MAX_ZAHL; i++)
+ {
+ alleButtons[i] = new Button();
+ alleButtons[i].Size = new Size(buttonGroesse, buttonGroesse);
+ alleButtons[i].Location = new Point(
+ startX + (i % 7) * (buttonGroesse + abstand),
+ startY + (i / 7) * (buttonGroesse + abstand)
+ );
+ alleButtons[i].Text = (i + 1).ToString();
+ alleButtons[i].Tag = i + 1;
+ alleButtons[i].BackColor = Color.White;
+ alleButtons[i].FlatStyle = FlatStyle.Flat;
+ alleButtons[i].Font = new Font("Segoe UI", 11, FontStyle.Bold);
+ alleButtons[i].Click += ZahlenButton_Click;
+ this.Controls.Add(alleButtons[i]);
+ }
+ }
+
+ private void ErstelleSpielButton(int x, int y)
+ {
+ spielButton = new Button();
+ spielButton.Size = new Size(180, 60);
+ spielButton.Location = new Point(x, y);
+ spielButton.Text = "Spielen";
+ spielButton.Font = new Font("Segoe UI", 14, FontStyle.Bold);
+ spielButton.BackColor = Color.FromArgb(0, 120, 215);
+ spielButton.ForeColor = Color.White;
+ spielButton.FlatStyle = FlatStyle.Flat;
+ spielButton.Enabled = false;
+ spielButton.Click += SpielButton_Click;
+ this.Controls.Add(spielButton);
+ }
+
+ private void ErstelleGeldAnzeige(int x, int y)
+ {
+ geldAnzeige = new Label();
+ geldAnzeige.Size = new Size(180, 50);
+ geldAnzeige.Location = new Point(x, y + 80);
+ geldAnzeige.Text = "Mein Geld: " + meinGeld + "€";
+ geldAnzeige.Font = new Font("Segoe UI", 13, FontStyle.Bold);
+ geldAnzeige.ForeColor = Color.DarkGreen;
+ geldAnzeige.BackColor = Color.FromArgb(230, 255, 230);
+ geldAnzeige.TextAlign = ContentAlignment.MiddleCenter;
+ geldAnzeige.BorderStyle = BorderStyle.FixedSingle;
+ this.Controls.Add(geldAnzeige);
+ }
+
+ private void ErstelleSpielZaehler(int x, int y)
+ {
+ spielZaehler = new Label();
+ spielZaehler.Size = new Size(180, 50);
+ spielZaehler.Location = new Point(x, y + 150);
+ spielZaehler.Text = "Spiele gespielt: 0";
+ spielZaehler.Font = new Font("Segoe UI", 13, FontStyle.Bold);
+ spielZaehler.ForeColor = Color.DarkBlue;
+ spielZaehler.BackColor = Color.FromArgb(230, 230, 255);
+ spielZaehler.TextAlign = ContentAlignment.MiddleCenter;
+ spielZaehler.BorderStyle = BorderStyle.FixedSingle;
+ this.Controls.Add(spielZaehler);
+ }
+
+ private void ErstelleErgebnisAnzeige(int startX, int startY, int buttonGroesse, int abstand)
+ {
+ ergebnisAnzeige = new Label();
+ ergebnisAnzeige.Size = new Size(700, 120);
+ ergebnisAnzeige.Location = new Point(startX, startY + 7 * (buttonGroesse + abstand) + 30);
+ ergebnisAnzeige.Text = "Wähle 7 Zahlen aus";
+ ergebnisAnzeige.Font = new Font("Segoe UI", 11, FontStyle.Bold);
+ ergebnisAnzeige.TextAlign = ContentAlignment.TopLeft;
+ ergebnisAnzeige.AutoSize = false;
+ ergebnisAnzeige.BorderStyle = BorderStyle.FixedSingle;
+ ergebnisAnzeige.BackColor = Color.FromArgb(255, 255, 224);
+ this.Controls.Add(ergebnisAnzeige);
+ }
+
+ private void ZahlenButton_Click(object sender, EventArgs e)
+ {
+ Button geklickterButton = (Button)sender;
+ int zahl = (int)geklickterButton.Tag;
+
+ if (meineZahlen.Contains(zahl))
+ {
+
+ meineZahlen.Remove(zahl);
+ geklickterButton.BackColor = Color.White;
+ }
+ else if (meineZahlen.Count < ZAHLEN_AUSWAHL)
+ {
+
+ meineZahlen.Add(zahl);
+ geklickterButton.BackColor = Color.LightGreen;
+ }
+
+
+ spielButton.Enabled = (meineZahlen.Count == ZAHLEN_AUSWAHL);
+ ergebnisAnzeige.Text = "Ausgewählte Zahlen: " + string.Join(", ", meineZahlen);
+ }
+
+ private void SpielButton_Click(object sender, EventArgs e)
+ {
+
+ if (meinGeld < KOSTEN_PRO_SPIEL)
+ {
+ MessageBox.Show("Du hast nicht genug Geld zum Spielen!");
+ return;
+ }
+
+
+ meinGeld -= KOSTEN_PRO_SPIEL;
+
+
+ List gezogeneZahlen = ZieheZufallszahlen();
+
+
+ int treffer = ZaehleTreffer(gezogeneZahlen);
+
+
+ int gewinn = BerechneGewinn(treffer);
+ meinGeld += gewinn;
+
+
+ AktualisiereAnzeigen(gezogeneZahlen, treffer, gewinn);
+
+
+ SetzeSpielZurueck();
+ }
+
+ private List ZieheZufallszahlen()
+ {
+ List zahlen = new List();
+ Random zufall = new Random();
+
+ while (zahlen.Count < ZAHLEN_AUSWAHL)
+ {
+ int zahl = zufall.Next(1, MAX_ZAHL + 1);
+ if (!zahlen.Contains(zahl))
+ {
+ zahlen.Add(zahl);
+ }
+ }
+
+ return zahlen;
+ }
+
+ private int ZaehleTreffer(List gezogeneZahlen)
+ {
+ int treffer = 0;
+ foreach (int zahl in meineZahlen)
+ {
+ if (gezogeneZahlen.Contains(zahl))
+ {
+ treffer++;
+ }
+ }
+ return treffer;
+ }
+
+ private int BerechneGewinn(int treffer)
+ {
+ switch (treffer)
+ {
+ case 3: return 20;
+ case 4: return 400;
+ case 5: return 20000;
+ case 6: return 100000;
+ case 7: return 1000000;
+ default: return 0;
+ }
+ }
+
+ private void AktualisiereAnzeigen(List gezogeneZahlen, int treffer, int gewinn)
+ {
+ geldAnzeige.Text = "Mein Geld: " + meinGeld + "€";
+ ergebnisAnzeige.Text = "Gezogene Zahlen: " + string.Join(", ", gezogeneZahlen) + "\n" +
+ "Deine Zahlen: " + string.Join(", ", meineZahlen) + "\n" +
+ "Treffer: " + treffer + "\n" +
+ "Einsatz: -" + KOSTEN_PRO_SPIEL + "€\n" +
+ "Gewinn: " + (gewinn > 0 ? "+" : "") + gewinn + "€";
+
+ spielAnzahl++;
+ spielZaehler.Text = "Spiele gespielt: " + spielAnzahl;
+ }
+
+ private void SetzeSpielZurueck()
+ {
+ meineZahlen.Clear();
+ foreach (Button button in alleButtons)
+ {
+ button.BackColor = Color.White;
+ }
+ spielButton.Enabled = false;
}
}
-}
+}
\ No newline at end of file
diff --git a/Lotto040625.sln b/Lotto040625.sln
index 9ba3adb..c38a119 100644
--- a/Lotto040625.sln
+++ b/Lotto040625.sln
@@ -1,25 +1,34 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
-VisualStudioVersion = 17.13.35931.197 d17.13
+VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lotto040625", "Lotto040625.csproj", "{9622014C-5CF3-4CD4-A636-ADF77F9AF6D7}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lotto040625", "Lotto040625.csproj", "{3319E86D-5768-434F-85FD-A534B15BB2A5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {9622014C-5CF3-4CD4-A636-ADF77F9AF6D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {9622014C-5CF3-4CD4-A636-ADF77F9AF6D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {9622014C-5CF3-4CD4-A636-ADF77F9AF6D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {9622014C-5CF3-4CD4-A636-ADF77F9AF6D7}.Release|Any CPU.Build.0 = Release|Any CPU
+ {3319E86D-5768-434F-85FD-A534B15BB2A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {3319E86D-5768-434F-85FD-A534B15BB2A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {3319E86D-5768-434F-85FD-A534B15BB2A5}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {3319E86D-5768-434F-85FD-A534B15BB2A5}.Debug|x64.Build.0 = Debug|Any CPU
+ {3319E86D-5768-434F-85FD-A534B15BB2A5}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {3319E86D-5768-434F-85FD-A534B15BB2A5}.Debug|x86.Build.0 = Debug|Any CPU
+ {3319E86D-5768-434F-85FD-A534B15BB2A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {3319E86D-5768-434F-85FD-A534B15BB2A5}.Release|Any CPU.Build.0 = Release|Any CPU
+ {3319E86D-5768-434F-85FD-A534B15BB2A5}.Release|x64.ActiveCfg = Release|Any CPU
+ {3319E86D-5768-434F-85FD-A534B15BB2A5}.Release|x64.Build.0 = Release|Any CPU
+ {3319E86D-5768-434F-85FD-A534B15BB2A5}.Release|x86.ActiveCfg = Release|Any CPU
+ {3319E86D-5768-434F-85FD-A534B15BB2A5}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
- GlobalSection(ExtensibilityGlobals) = postSolution
- SolutionGuid = {585A201C-AC20-4588-BBC9-BBAE18C88DD0}
- EndGlobalSection
EndGlobal
diff --git a/Program.cs b/Program.cs
index 08b5828..17312f1 100644
--- a/Program.cs
+++ b/Program.cs
@@ -1,17 +1,16 @@
-namespace Lotto040625
+using System;
+using System.Windows.Forms;
+
+namespace LottoGame
{
- internal static class Program
+ static class Program
{
- ///
- /// The main entry point for the application.
- ///
[STAThread]
static void Main()
{
- // To customize application configuration such as set high DPI settings or default font,
- // see https://aka.ms/applicationconfiguration.
- ApplicationConfiguration.Initialize();
+ Application.EnableVisualStyles();
+ Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
-}
\ No newline at end of file
+}
\ No newline at end of file