Ik maak een geavanceerd galgje programma in C#.
Dat lukt tot nu toe aardig. Wel zal ik de volgende features erin willen als dat mogelijk zal zijn wat ik helaas niet voor elkaar krijg.Ik zal willen dat als je het woord goed hebt geraden de woorden groen gaan kleuren en als je het fout hebt en je kansen hebt verspilt dat ze dan rood word.
Dit is mijn code
Dat lukt tot nu toe aardig. Wel zal ik de volgende features erin willen als dat mogelijk zal zijn wat ik helaas niet voor elkaar krijg.Ik zal willen dat als je het woord goed hebt geraden de woorden groen gaan kleuren en als je het fout hebt en je kansen hebt verspilt dat ze dan rood word.
Dit is mijn code
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
| namespace Galgje { public partial class Form1 : Form { public Form1() { InitializeComponent(); Paint += Form1_Paint; //Load += Form1_Load; } string[] woorden = { "nederland", "autoventieldopje", "banketbakker", "applicatieontwikkelaar", "spiegel", "verwarming", "oplaadkabel", "interessant", "dierentuin", "fotolijst", "kroketten", "gitaarsnaar", "traktatie", "paardenbloem", "computermuis", "processor", "overclocken", "chocolademousse", "flamingo", "versnelling", "spijkerjack", "auto", "fiets", "scooter", }; Random r = new Random(); Button[] alfabetKnoppen; List<Label> labels = new List<Label>(); //negeer als het antwoord fout is bool negeer; // int voor de status van de galg int status = 0; private void Form1_Load(object sender, EventArgs e) { //welkomsbericht als je galgje opent notifyIcon1.BalloonTipText = "Welkom bij galgje"; notifyIcon1.Icon = SystemIcons.Exclamation; notifyIcon1.ShowBalloonTip(1000); this.DoubleBuffered = true; alfabetKnoppen = this.Controls.OfType<Button>().Except(new Button[] { Button }).ToArray(); Array.ForEach(alfabetKnoppen, b => b.Click += btn_click); Button.PerformClick(); } // de letterknoppen checked of geklikte opdracht matched met het woord in de array woorden private void btn_click(object sender, EventArgs e) { if (negeer) return; Button b = (Button)sender; b.Enabled = false; Array.ForEach(labels.ToArray(), lbl => lbl.Text = lbl.Tag.ToString() == b.Text ? b.Text : lbl.Text); for (int x = 1; x <= labels.Count - 1; x++) { labels[x].Left = labels[x - 1].Right; } if (labels[labels.Count - 1].Right > this.ClientSize.Width - 14) { this.SetClientSizeCore(labels[labels.Count - 1].Right + 14, 381); } status += !labels.Any(lbl => lbl.Text == b.Text) ? 1 : 0; negeer = labels.All(lbl => lbl.Text != " ") || status == 10; this.Invalidate(); } private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { //status 1 van het galgje poppetje if (status >= 1) { e.Graphics.DrawLine(new Pen(Color.Black, 2), 85, 190, 210, 190); } //status 2 van het galgje poppetje if (status >= 2) { e.Graphics.DrawLine(new Pen(Color.Black, 2), 148, 190, 148, 50); } //status 3 van het galgje poppetje if (status >= 3) { e.Graphics.DrawLine(new Pen(Color.Black, 2), 148, 50, 198, 50); } //status 4 van het galgje poppetje if (status >= 4) { e.Graphics.DrawLine(new Pen(Color.Black, 2), 198, 50, 198, 70); } //status 5 van het galgje poppetje if (status >= 5) { e.Graphics.DrawEllipse(new Pen(Color.Black, 2), new Rectangle(188, 70, 20, 20)); } //status 6 van het galgje poppetje if (status >= 6) { e.Graphics.DrawLine(new Pen(Color.Black, 2), 198, 90, 198, 130); } //status 7 van het galgje poppetje if (status >= 7) { e.Graphics.DrawLine(new Pen(Color.Black, 2), 198, 95, 183, 115); } //status 8 van het galgje poppetje if (status >= 8) { e.Graphics.DrawLine(new Pen(Color.Black, 2), 198, 95, 213, 115); } //status 9 van het galgje poppetje if (status >= 9) { e.Graphics.DrawLine(new Pen(Color.Black, 2), 198, 130, 183, 170); } //status 10 van het galgje poppetje if (status >= 10) { e.Graphics.DrawLine(new Pen(Color.Black, 2), 198, 130, 213, 170); } } //button voor het genereren van een nieuw woord aan de hand van mijn string woorden private void Button1_Click(object sender, EventArgs e) { this.SetClientSizeCore(546, 381); string word = woorden[r.Next(0, woorden.Length)].ToUpper(); Array.ForEach(this.Controls.OfType<Label>().ToArray(), lbl => lbl.Dispose()); Array.ForEach(alfabetKnoppen, b => b.Enabled = true); labels = new List<Label>(); int startX = 14; foreach (char c in word) { Label lbl = new Label(); lbl.Text = " "; lbl.Font = new Font(this.Font.Name, 35, FontStyle.Underline); lbl.Location = new Point(startX, 250); lbl.Tag = c.ToString(); lbl.AutoSize = true; this.Controls.Add(lbl); labels.Add(lbl); startX = lbl.Right; } negeer = false; status = 0; this.Invalidate(); } } } |