-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
81 lines (69 loc) · 1.98 KB
/
Form1.cs
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
/*
* Cows and Bulls (Main Class):
*/
using System.Windows.Forms;
namespace cb
{
/*
* UI Controls:
* title: UI title.
* input: Input for the user's guess.
* guesses: User's guesess
*/
public partial class Form1 : Form
{
Wordlist wl = new Wordlist();
private string pickedWord;
public Form1()
{
InitializeComponent();
pickedWord = wl.pickWord();
}
//Evaluate:
private void evaluate(string pickedWord, string guessedWord)
{
int i = 0;
int j = 0;
int cows = 0;
int bulls = 0;
for (i = 0; i < pickedWord.Length; i++)
{
for (j = 0; j < guessedWord.Length; j++)
{
if (pickedWord[i] == guessedWord[j])
{
if (i == j)
{
bulls++;
}
else
{
cows++;
}
}
}
}
cowlist.AppendText(cows.ToString() + "\n");
bulllist.AppendText(bulls.ToString() + "\n");
if (bulls == 4)
{
MessageBox.Show("You Win!");
input.Enabled = false;
}
}
//When the 'Go' button is clicked:
private void button1_Click(object sender, System.EventArgs e)
{
string guessedWord = input.Text;
guessedWord = guessedWord.ToUpper();
if (guessedWord.Length != 4)
{
input.Text = "";
return;
}
guesses.AppendText(guessedWord + "\n");
this.evaluate(this.pickedWord, guessedWord);
input.Text = "";
}
}
}