Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15.  
  16. namespace KruunaKlaava
  17. {
  18.     /// <summary>
  19.     /// Interaction logic for MainWindow.xaml
  20.     /// </summary>
  21.     public partial class MainWindow : Window
  22.     {
  23.         public static BitmapImage kr = new BitmapImage();
  24.         public static BitmapImage kl = new BitmapImage();
  25.         public static BitmapImage side1 = new BitmapImage();
  26.         public static BitmapImage side2 = new BitmapImage();
  27.         public MainWindow()
  28.         {
  29.             InitializeComponent();
  30.             generatePics();
  31.             label.Content = "Paina \"heitä kolikkoa\" nappulaa!";
  32.             imageBox.Source = side1;
  33.            
  34.         }
  35.  
  36.         public static void generatePics()
  37.         {
  38.             try
  39.             {
  40.                 kr.BeginInit();
  41.                 kr.UriSource = new Uri("/KruunaKlaava;component/Resources/kr.png", UriKind.RelativeOrAbsolute);
  42.                 kr.EndInit();
  43.  
  44.  
  45.                 kl.BeginInit();
  46.                 kl.UriSource = new Uri("/KruunaKlaava;component/Resources/kl.png", UriKind.RelativeOrAbsolute);
  47.                 kl.EndInit();
  48.  
  49.  
  50.                 side1.BeginInit();
  51.                 side1.UriSource = new Uri("/KruunaKlaava;component/Resources/side.png", UriKind.RelativeOrAbsolute);
  52.                 side1.EndInit();
  53.  
  54.  
  55.                 side2.BeginInit();
  56.                 side2.UriSource = new Uri("/KruunaKlaava;component/Resources/side2.png", UriKind.RelativeOrAbsolute);
  57.                 side2.EndInit();
  58.             }
  59.             catch (Exception e)
  60.             {
  61.                 MessageBox.Show(e.Message);
  62.             }
  63.            
  64.         }
  65.         public int tossCoin()
  66.         {
  67.              
  68.  
  69.             Random rnd = new Random();
  70.             return rnd.Next(1, 3);
  71.         }
  72.  
  73.         public void spinCoin()
  74.         {
  75.             for (int i = 0; i < 200; i++)
  76.             {
  77.                 try
  78.                 {
  79.                     imageBox.Source = side1;
  80.                     imageBox.Source = side2;
  81.                 }
  82.                 catch (Exception e)
  83.                 {
  84.                     MessageBox.Show(e.Message);
  85.                 }
  86.                
  87.             }
  88.         }
  89.  
  90.         public void button1_Click(object sender, RoutedEventArgs e)
  91.         {
  92.             spinCoin();
  93.             if (tossCoin() == 1)
  94.             {
  95.                 imageBox.Source = kr;
  96.                 label.Content = "Kruuna!";
  97.             }
  98.             else
  99.             {
  100.                 imageBox.Source = kl;
  101.                 label.Content = "Klaava!";
  102.             }
  103.         }
  104.     }
  105.  
  106.    
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement