Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Collections.Generic;
  4. using Gtk;
  5.  
  6. public class Leikur : Window
  7. {
  8.     private int teljari = 0;
  9.     private Entry display = new Entry();
  10.    
  11.     /* Fastayrðing Gagna:
  12.         display er aðalinntak sem er texta gluggi.
  13.         teljari er heiltala sem telur fjölda ágiskana.
  14.     */
  15.    
  16.     public Leikur() : base("Calculator")
  17.     {
  18.         SetDefaultSize(250, 200);
  19.         SetPosition(WindowPosition.Center);
  20.        
  21.         VBox vbox = new VBox(false, 2);
  22.         Table table = new Table(4, 4, true);
  23.        
  24.         Button nyrleikur = new Button("Nýr leikur");
  25.         Button giska = new Button("Giska");
  26.         Button haetta = new Button("Hætta");
  27.         Label teljarix = new Label();
  28.         Label birtingarsv = new Label();
  29.        
  30.         Random r = new Random();
  31.         int tala = r.Next(1000);
  32.        
  33.         System.Console.WriteLine(r.Next(1000));
  34.         teljarix.Text = "fjöldi tilrauna er = " + teljari;
  35.        
  36.         haetta.Clicked += delegate
  37.         {
  38.             Application.Quit();
  39.         };
  40.    
  41.         nyrleikur.Clicked += delegate
  42.         {
  43.             teljari = 0;
  44.             teljarix.Text = " ";
  45.             r = new Random();
  46.             System.Console.WriteLine(r.Next(1000));
  47.             tala = r.Next(1000);
  48.    
  49.         };
  50.    
  51.         giska.Clicked += delegate
  52.         {
  53.             teljari++;
  54.             int x = Convert.ToInt32(display.Text);
  55.         //try
  56.         //{
  57.             if(x < tala)
  58.             {
  59.                 birtingarsv.Text = "talan er of lág";
  60.             }
  61.             if(x > tala)
  62.             {
  63.                 birtingarsv.Text = "talan er of há";
  64.             }
  65.             if(x == tala)
  66.             {
  67.                 birtingarsv.Text = "þú giskaðir á rétta tölu";
  68.             }
  69.         };
  70.         //catch
  71.        
  72.    
  73.         table.Attach(nyrleikur,2,3,2,3);
  74.         table.Attach(haetta,0,1,2,3);
  75.         table.Attach(giska,1,2,2,3);
  76.         table.Attach(teljarix,1,2,0,1);
  77.         table.Attach(birtingarsv, 1,2,1,2);
  78.    
  79.    
  80.         teljarix.Text = "fjöldi tilrauna er" + teljari;
  81.    
  82.    
  83.    
  84.    
  85.    
  86.    
  87.     vbox.PackStart(this.display, false, false,1);
  88.     vbox.PackEnd(table, true, true, 1);
  89.    
  90.     Add(vbox);
  91.     ShowAll();
  92.    
  93.     }
  94.     public static void Main()
  95.     {
  96.         Application.Init();
  97.         new Leikur();
  98.         Application.Run();
  99.    
  100.     }
  101.    
  102.    
  103.    
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement