using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace _20Q { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private int qnum = 2; private string a; private string b; private string c; private string d; private string e2; private string f; private string g; private string h; private string i; private string j; private string k; private string l; private string m; private string n; private string o; private string p; private string q; private string r; private string s; private string t; private string anim; private void button3_Click(object sender, EventArgs e) { qnum = 2; q1(); } private void button2_Click(object sender, EventArgs e) { if (qnum == 2) { a = "yes"; q2(); } if (qnum == 3) { b = "yes"; q3(); } if (qnum == 4) { c = "yes"; q4(); } if (qnum == 5) { d = "yes"; q5(); } if (qnum == 6) { e2 = "yes"; q6(); } if (qnum == 7) { f = "yes"; q7(); } if (qnum == 8) { g = "yes"; q8(); } if (qnum == 9) { h = "yes"; q9(); } if (qnum == 10) { i = "yes"; q10(); } if (qnum == 11) { j = "yes"; q11(); } if (qnum == 12) { k = "yes"; q12(); } if (qnum == 13) { l = "yes"; q13(); } if (qnum == 14) { m = "yes"; q14(); } if (qnum == 15) { n = "yes"; q15(); } if (qnum == 16) { o = "yes"; q16(); } if (qnum == 17) { p = "yes"; q17(); } if (qnum == 18) { q = "yes"; q18(); } if (qnum == 19) { r = "yes"; q19(); } if (qnum == 20) { s = "yes"; q20(); } if (qnum == 21) { t = "yes"; guess(); } if (qnum == 22) { textBox1.Text = "I Win!"; qnum = 24; } if (qnum == 23) { tell(); } qnum += 1; } private void button1_Click(object sender, EventArgs e) { if (qnum == 2) { a = "no"; q2(); } if (qnum == 3) { b = "no"; q3(); } if (qnum == 4) { c = "no"; q4(); } if (qnum == 5) { d = "no"; q5(); } if (qnum == 6) { e2 = "no"; q6(); } if (qnum == 7) { f = "no"; q7(); } if (qnum == 8) { g = "no"; q8(); } if (qnum == 9) { h = "no"; q9(); } if (qnum == 10) { i = "no"; q10(); } if (qnum == 11) { j = "no"; q11(); } if (qnum == 12) { k = "no"; q12(); } if (qnum == 13) { l = "no"; q13(); } if (qnum == 14) { m = "no"; q14(); } if (qnum == 15) { n = "no"; q15(); } if (qnum == 16) { o = "no"; q16(); } if (qnum == 17) { p = "no"; q17(); } if (qnum == 18) { q = "no"; q18(); } if (qnum == 19) { r = "no"; q19(); } if (qnum == 20) { s = "no"; q20(); } if (qnum == 21) { t = "no"; guess(); } if (qnum == 22) { textBox1.Text = "Type what it actually is in here and click yes."; } qnum += 1; } private void q1() { textBox1.Text = "Is it a mammal?"; } private void q2() { textBox1.Text = "Does it have paws?"; } private void q3() { textBox1.Text = "It is a herbivore?"; } private void q4() { textBox1.Text = "Can you find it in a zoo?"; } private void q5() { textBox1.Text = "Is it large?"; } private void q6() { textBox1.Text = "Are there many different types of it?"; } private void q7() { textBox1.Text = "Is it a specific color?"; } private void q8() { textBox1.Text = "Could it be dangerous if it wanted to?"; } private void q9() { textBox1.Text = "Would most people like to eat it?"; } private void q10() { textBox1.Text = "Does it live in forests?"; } private void q11() { textBox1.Text = "Can it swim?"; } private void q12() { textBox1.Text = "Is this animal a specific type?"; } private void q13() { textBox1.Text = "Has it been domesticated?"; } private void q14() { textBox1.Text = "Can it fly?"; } private void q15() { textBox1.Text = "Is it fast?"; } private void q16() { textBox1.Text = "Does it have fur or short hair?"; } private void q17() { textBox1.Text = "Can it climb?"; } private void q18() { textBox1.Text = "Is it useful?"; } private void q19() { textBox1.Text = "Can you buy it?"; } private void q20() { textBox1.Text = "Can it scratch?"; } private string read2; private string check; private void guess() { int loop = 1; while (loop == 1) { try { int found = 0; string[] search = Directory.GetFiles(@"C:\20Q\Brain", "*.animal"); textBox1.Text = "Let Me Guess Now!"; foreach (string word in search) { StreamReader read = new StreamReader(word); read2 = read.ReadToEnd(); check = a + b + c + d + e2 + f + g + h + i + j + k + l + m + n + o + p + q + r + s + t; if (read2 == check) { textBox1.Text = "Is your animal a " + word.Substring(13, word.Length - 20) + "?"; found = 1; loop = 0; } } if (read2 != check && found == 0) { textBox1.Text = "I can't guess! You win! Press No."; } loop = 0; } catch { string activeDir = @"C:/20Q"; string newPath = System.IO.Path.Combine(activeDir, "Brain"); System.IO.Directory.CreateDirectory(newPath); } } } private void tell() { StreamWriter str = new StreamWriter("C:/20Q/Brain/" + textBox1.Text + ".animal"); str.Write(a); str.Write(b); str.Write(c); str.Write(d); str.Write(e2); str.Write(f); str.Write(g); str.Write(h); str.Write(i); str.Write(j); str.Write(k); str.Write(l); str.Write(m); str.Write(n); str.Write(o); str.Write(p); str.Write(q); str.Write(r); str.Write(s); str.Write(t); str.Close(); textBox1.Text = "Thanks. I've stored that in my brain."; } private void Form1_Load(object sender, EventArgs e) { int loop = 1; while (loop == 1) { try { StreamWriter str = new StreamWriter("C:/20Q/Startup.txt"); str.Write("Everything loaded fine!"); str.Close(); loop = 0; } catch { string activeDir = @"C:\"; string newPath = System.IO.Path.Combine(activeDir, "20Q"); System.IO.Directory.CreateDirectory(newPath); } } } } }