Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.Collections.Generic;
- using Gtk;
- public class Leikur : Window
- {
- private int teljari = 0;
- private Entry display = new Entry();
- /* Fastayrðing Gagna:
- display er aðalinntak sem er texta gluggi.
- teljari er heiltala sem telur fjölda ágiskana.
- */
- public Leikur() : base("Calculator")
- {
- SetDefaultSize(250, 200);
- SetPosition(WindowPosition.Center);
- VBox vbox = new VBox(false, 2);
- Table table = new Table(4, 4, true);
- Button nyrleikur = new Button("Nýr leikur");
- Button giska = new Button("Giska");
- Button haetta = new Button("Hætta");
- Label teljarix = new Label();
- Label birtingarsv = new Label();
- Random r = new Random();
- int tala = r.Next(1000);
- System.Console.WriteLine(r.Next(1000));
- teljarix.Text = "fjöldi tilrauna er = " + teljari;
- haetta.Clicked += delegate
- {
- Application.Quit();
- };
- nyrleikur.Clicked += delegate
- {
- teljari = 0;
- teljarix.Text = " ";
- r = new Random();
- System.Console.WriteLine(r.Next(1000));
- tala = r.Next(1000);
- };
- giska.Clicked += delegate
- {
- teljari++;
- int x = Convert.ToInt32(display.Text);
- //try
- //{
- if(x < tala)
- {
- birtingarsv.Text = "talan er of lág";
- }
- if(x > tala)
- {
- birtingarsv.Text = "talan er of há";
- }
- if(x == tala)
- {
- birtingarsv.Text = "þú giskaðir á rétta tölu";
- }
- };
- //catch
- table.Attach(nyrleikur,2,3,2,3);
- table.Attach(haetta,0,1,2,3);
- table.Attach(giska,1,2,2,3);
- table.Attach(teljarix,1,2,0,1);
- table.Attach(birtingarsv, 1,2,1,2);
- teljarix.Text = "fjöldi tilrauna er" + teljari;
- vbox.PackStart(this.display, false, false,1);
- vbox.PackEnd(table, true, true, 1);
- Add(vbox);
- ShowAll();
- }
- public static void Main()
- {
- Application.Init();
- new Leikur();
- Application.Run();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement