rendered paste body// /home/jason/Projects/DiffyGame/Main.cs created with MonoDevelop
// User: jason at 5:04 AM 7/14/2007
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//
// project created on 7/14/2007 at 5:04 AM
using System;
using Gtk;
namespace DiffyGame
{
class MainClass
{
static public void Main ()
{
//create our window
WindowClass window = new WindowClass();
}
}
class WindowClass
{
DiffyCompute diffy = new DiffyCompute();
Entry entry_1;
Entry entry_2;
Entry entry_3;
Entry entry_4;
public WindowClass ()
{
//Start up our diffy object
Application.Init ();
Window win = new Window("Window");
win.DeleteEvent += new DeleteEventHandler(delete_event);
Button compute_button = new Button("Compute");
compute_button.Clicked += new EventHandler(dupdate);
Button cancel_button = new Button("Close");
cancel_button.Clicked += new EventHandler(exit_event);
//wrapper around buttons
HBox button_box = new HBox();
button_box.PackStart(compute_button, true, true, 10);
button_box.PackStart(cancel_button, true, true, 10);
//whole main box
VBox main_box = new VBox();
main_box.PackEnd(button_box, false, true, 0);
//Wrapper around text area
HBox text_wrapper = new HBox();
main_box.PackStart(text_wrapper, true, true, 5);
//text area setup
Label label_1 = new Label("1st Number:");
Label label_2 = new Label("2nd Number:");
Label label_3 = new Label("3rd Number:");
Label label_4 = new Label("4th Number:");
entry_1 = new Entry("0");
entry_1.SetSizeRequest(60, 20);
entry_1.MaxLength = 4;
entry_2 = new Entry("0");
entry_2.SetSizeRequest(60, 20);
entry_2.MaxLength = 4;
entry_3 = new Entry("0");
entry_3.SetSizeRequest(60, 20);
entry_3.MaxLength = 4;
entry_4 = new Entry("0");
entry_4.SetSizeRequest(60, 20);
entry_4.MaxLength = 4;
//packing text area
text_wrapper.PackStart(label_1, false, true, 10);
text_wrapper.PackStart(entry_1, true, true, 0);
text_wrapper.PackStart(label_2, false, true, 10);
text_wrapper.PackStart(entry_2, true, true, 0);
text_wrapper.PackStart(label_3, false, true, 10);
text_wrapper.PackStart(entry_3, true, true, 0);
text_wrapper.PackStart(label_4, false, true, 10);
text_wrapper.PackStart(entry_4, true, true, 0);
win.Add(main_box);
win.ShowAll ();
Application.Run ();
}
public void exit_event(object obj, EventArgs args)
{
Application.Quit();
}
public void delete_event(object obj, DeleteEventArgs args)
{
Application.Quit();
}
public void dupdate(object obj, EventArgs args)
{
//string str = "4";
diffy.update(entry_1, entry_2, entry_3, entry_4);
}
}
class DiffyCompute
{
public DiffyCompute()
{
Console.Write("");
}
public void update(Entry entry_1, Entry entry_2, Entry entry_3, Entry entry_4)
{
int[] new_numbers = get_new(Convert.ToInt32(entry_1.Text),Convert.ToInt32(entry_2.Text),
Convert.ToInt32(entry_3.Text),Convert.ToInt32(entry_4.Text));
entry_1.Text = Convert.ToString(new_numbers[0]);
entry_2.Text = Convert.ToString(new_numbers[1]);
entry_3.Text = Convert.ToString(new_numbers[2]);
entry_4.Text = Convert.ToString(new_numbers[3]);
}
public int[] get_new(int num1, int num2, int num3, int num4)
{
int new_num1 = do_math(num1, num2);
int new_num2 = do_math(num2, num3);
int new_num3 = do_math(num3, num4);
int new_num4 = do_math(num4, num1);
int[] output = new int[]{ new_num1, new_num2, new_num3, new_num4 };
return output;
}
public int do_math(int num1, int num2)
{
int output;
if ( num1 >= num2 )
{
output = num1 - num2;
}
else
{
output = num2 - num1;
}
return output;
}
}
}