// /home/jason/Projects/DiffyGame2/Main.cs created with MonoDevelop // User: jason at 8:33 PM 7/14/2007 // // To change standard headers go to Edit->Preferences->Coding->Standard Headers // // project created on 7/14/2007 at 8:33 PM using System; using Gtk; using Pango; using System.Collections; namespace DiffyGame2 { class MainClass { public static DiffySolve diffy_compute = new DiffySolve(); public static WindowClass window = new WindowClass(); public static void Main() { //god this is utterly useless... why oh why must I have you? //I hope you die... die die die die die } } public class WindowClass { public ArrayList entry_list = new ArrayList(); public ArrayList label_list = new ArrayList(); public ArrayList button_list = new ArrayList(); public ArrayList buffer_list = new ArrayList(); //public ScrolledWindow text_scroll = new ScrolledWindow(); //public //entry.Add(new Entry(5)); public WindowClass() { //Start Up GTK Application.Init(); //define our window Window win = new Window("Diffy Game"); win.DeleteEvent += new DeleteEventHandler(delete_event); VBox main_box = new VBox(); HBox text_box = new HBox(); HBox button_box = new HBox(); //top label Label top_label = new Label("Diffy Game"); //add entry boxes to list for ( int i = 0; i < 4; i++ ) { Entry entry = new Entry(); entry_list.Add(entry); } //configure entry boxes foreach ( Entry i in entry_list ) { i.MaxLength = 5; i.SetSizeRequest(60, 20); i.Text = "0"; text_box.PackStart(i); } //create 4 labels for ( int i = 0; i < 4; i++ ) { Label label = new Label("Num " + Convert.ToString(i+1) + ": "); label_list.Add(label); } foreach ( Label i in label_list ) { text_box.PackStart(i); } //pack in labels every other, perhaps redundant //but this seemed to be the only really clean way int num = 0; foreach ( Label i in label_list) { text_box.ReorderChild(i, num); num += 2; } //create text storage area Pango.FontDescription monoFont = new FontDescription(); monoFont.Family = "monospace"; ScrolledWindow text_scroll = new ScrolledWindow(); TextView text_storage = new TextView(); buffer_list.Add(text_storage); TextBuffer text_storage_buffer = text_storage.Buffer; text_storage.ModifyFont(monoFont); text_storage_buffer.Text = "Enter numbers and press compute..."; text_storage.Editable = false; text_scroll.Add(text_storage); main_box.PackEnd(text_scroll); text_storage.Buffer.Changed += new EventHandler(scroll_bottom); //add buttons Button compute_button = new Button("Compute"); compute_button.Clicked += new EventHandler(update_event); Button close_button = new Button("Close"); close_button.Clicked += new EventHandler(close_event); Button clear_button = new Button("Clear"); clear_button.Clicked += new EventHandler(clear_event); Button end_button = new Button("End"); end_button.Clicked += new EventHandler(scroll_bottom); button_list.Add(compute_button); button_list.Add(clear_button); button_list.Add(end_button); button_list.Add(close_button); foreach ( Button i in button_list ) { button_box.PackStart(i, true, false, 10); } //setup packing main_box.PackStart(top_label, false, true, 15); main_box.PackStart(text_box, false, true, 5); main_box.PackStart(button_box, false, true, 5); win.Add(main_box); win.ShowAll(); Application.Run(); } public void delete_event(object obj, DeleteEventArgs args) { Application.Quit(); } public void close_event(object obj, EventArgs args) { Application.Quit(); } public void clear_event(object obj, EventArgs args) { foreach ( TextView i in buffer_list ) { i.Buffer.Text = "Enter numbers and press compute..."; } } public void update_event(object obj, EventArgs args) { int[] solution = MainClass.diffy_compute.diffyUpdate(entry_list); update_textarea(); update_buttons(solution); } public void update_textarea() { int[] integers = new int[4]; int num = 0; foreach ( Entry i in entry_list ) { try { //make sure out integer is an integer integers[num]=Convert.ToInt32(i.Text); num++; } catch { //if its not, set it to zero integers[num]=0; num++; } } foreach ( TextView i in buffer_list ) { string text = "\r"; int zeroCount = 0; foreach ( Entry x in entry_list ) { try { text += Convert.ToString(x.Text).PadRight(7); if ( Convert.ToInt32(x.Text) == 0 ) { zeroCount++; } if ( zeroCount == 4 ) { text = "\rZero Reached!!!"; } } catch { text += "ERROR".PadRight(7) + "\r-------------------------"; break; } } TextIter end = new TextIter(); end = i.Buffer.EndIter; i.Buffer.Insert( end, text ); } } public void scroll_bottom(object obj, EventArgs args) { foreach ( TextView i in buffer_list ) { i.ScrollToMark( i.Buffer.CreateMark( "mark", i.Buffer.EndIter, false ), 0.0, false, 0.0, 0.0 ); } } public void update_buttons(int[] integers) { int num = 0; foreach ( Entry i in entry_list ) { i.Text = Convert.ToString(integers[num]); num++; } } } public class DiffySolve { public int[] diffyUpdate(ArrayList obj) { int[] integers = new int[4]; int num = 0; foreach ( Entry i in obj ) { try { integers[num]=Convert.ToInt32(i.Text); num++; } catch { integers[num]=0; num++; } } int[] solution = new int[4]; for ( int i = 0; i < 4; i++ ) { if ( i == 3 ) { solution[i] = Math.Abs(integers[i] - integers[0]); } else { solution[i] = Math.Abs(integers[i] - integers[i+1]); } } return solution; } } }