Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace KruunaKlaava
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- public static BitmapImage kr = new BitmapImage();
- public static BitmapImage kl = new BitmapImage();
- public static BitmapImage side1 = new BitmapImage();
- public static BitmapImage side2 = new BitmapImage();
- public MainWindow()
- {
- InitializeComponent();
- generatePics();
- label.Content = "Paina \"heitä kolikkoa\" nappulaa!";
- imageBox.Source = side1;
- }
- public static void generatePics()
- {
- try
- {
- kr.BeginInit();
- kr.UriSource = new Uri("/KruunaKlaava;component/Resources/kr.png", UriKind.RelativeOrAbsolute);
- kr.EndInit();
- kl.BeginInit();
- kl.UriSource = new Uri("/KruunaKlaava;component/Resources/kl.png", UriKind.RelativeOrAbsolute);
- kl.EndInit();
- side1.BeginInit();
- side1.UriSource = new Uri("/KruunaKlaava;component/Resources/side.png", UriKind.RelativeOrAbsolute);
- side1.EndInit();
- side2.BeginInit();
- side2.UriSource = new Uri("/KruunaKlaava;component/Resources/side2.png", UriKind.RelativeOrAbsolute);
- side2.EndInit();
- }
- catch (Exception e)
- {
- MessageBox.Show(e.Message);
- }
- }
- public int tossCoin()
- {
- Random rnd = new Random();
- return rnd.Next(1, 3);
- }
- public void spinCoin()
- {
- for (int i = 0; i < 200; i++)
- {
- try
- {
- imageBox.Source = side1;
- imageBox.Source = side2;
- }
- catch (Exception e)
- {
- MessageBox.Show(e.Message);
- }
- }
- }
- public void button1_Click(object sender, RoutedEventArgs e)
- {
- spinCoin();
- if (tossCoin() == 1)
- {
- imageBox.Source = kr;
- label.Content = "Kruuna!";
- }
- else
- {
- imageBox.Source = kl;
- label.Content = "Klaava!";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement