using System; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Collections.Generic; using System.Windows.Forms; namespace lab4SimonSays { public class SimonSays { private Color[] sequence; private Color [] colors = new Color[]{Color.Red, Color.Green, Color.Blue, Color.Yellow}; private Dictionary stringTocolor = new Dictionary(); public SimonSays () { GameProj.Form1 _MainForm = new GameProj.Form1(); string data = _MainForm.CallResults(); TextBox textBox1= new TextBox(); textBox1.Text = data; //'data' pulls the string in another project which contains randomly generates lines of 4 of R/G/B/Y //add content to Dictionary stringTocolor.Add('R', Color.Red); stringTocolor.Add('G', Color.Green); stringTocolor.Add('B', Color.Blue); stringTocolor.Add('Y', Color.Yellow); Color[] colourset = newSequence(textBox1.Text.Length); } StringCollection GetLinesCollectionFromTextBox(TextBox textBox) { StringCollection lines = new StringCollection(); // lineCount may be -1 if TextBox layout info is not up-to-date. int lineCount = textBox.LineCount; for (int line = 0; line < lineCount; line++) // GetLineText takes a zero-based line index. lines.Add(textBox.GetLineText(line)); return lines; } public Color[] newSequence(int length) { GameProj.Form1 _MainForm = new GameProj.Form1(); string data = _MainForm.CallResults(); TextBox textBox1= new TextBox(); textBox1.Text = data; //Make it so that it reads each line as new sequence Color[] array = new Color[length]; //check dictionary has the char key or not for (int i = 0; i < textBox1.Text.Length; i++) { if (stringTocolor.ContainsKey(textBox1.Text[i])) { array[i] = stringTocolor[textBox1.Text[i]]; } //give alert if wrong key else { MessageBox.Show("Wrong Colour input at index " + i + " of textbox string!"); } } this.sequence = array; return array; } public void newSequence (Color [] sequence) { this.sequence=sequence; } public int Compare (Color[] user_colors) { if(this.sequence ==null) throw new InvalidStateException("The game engine has not generated sequence yet"); for (int i=0; i