Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
13,496
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace SlotMachine
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         // DECLARING TOTAL, BET AND CREDITS
  21.         public static long credits = 100;
  22.         public static long total = 0;
  23.         public static int bet = 5;
  24.  
  25.         // DECLARING EACH ITEM
  26.         public static int p1;
  27.         public static int p2;
  28.         public static int p3;
  29.  
  30.         private void Form1_Load(object sender, EventArgs e)
  31.         {
  32.             pictureBox1.Image = Image.FromFile("2.png");
  33.             pictureBox2.Image = Image.FromFile("3.png");
  34.             pictureBox3.Image = Image.FromFile("1.png");
  35.         }
  36.  
  37.         // GENERATES RANDOM NUMBERS
  38.         public static class IntUtil
  39.         {
  40.             private static Random random;
  41.  
  42.             private static void Init()
  43.             {
  44.                 if (random == null) random = new Random();
  45.             }
  46.             public static int Random(int min, int max)
  47.             {
  48.                 Init();
  49.                 return random.Next(min, max);
  50.             }
  51.         }
  52.  
  53.         private void button1_Click(object sender, EventArgs e)
  54.         {
  55.             if (credits >= bet)
  56.             {
  57.                 credits = credits - bet;
  58.                 label1.Text = "Credits: " + credits.ToString();
  59.  
  60.                 for (var i = 0; i < 10; i++)
  61.                 {
  62.                     p1 = IntUtil.Random(1, 4);
  63.                     p2 = IntUtil.Random(1, 4);
  64.                     p3 = IntUtil.Random(1, 4);
  65.                 }
  66.  
  67.                 if (pictureBox1.Image != null) pictureBox1.Image.Dispose();
  68.                 pictureBox1.Image = Image.FromFile(p1.ToString() + ".png");
  69.  
  70.                 if (pictureBox2.Image != null) pictureBox2.Image.Dispose();
  71.                 pictureBox2.Image = Image.FromFile(p2.ToString() + ".png");
  72.  
  73.                 if (pictureBox3.Image != null) pictureBox3.Image.Dispose();
  74.                 pictureBox3.Image = Image.FromFile(p3.ToString() + ".png");
  75.  
  76.                 total = 0;
  77.  
  78.                 // GET RESULTS FROM PAYTABLE
  79.                 // CHECK IF 1, 2 OR 3 OCCURANCES
  80.                 if (p1 == 3) total = total + 5;
  81.                
  82.                 if (p1 == 2 & p2 == 2) total = total + 10;
  83.                 if (p1 == 3 & p2 == 3) total = total + 10;
  84.                
  85.                 if (p1 == 1 & p2 == 1 & p3 == 1) total = total + 20;
  86.                 if (p1 == 2 & p2 == 2 & p3 == 2) total = total + 30;
  87.                 if (p1 == 3 & p2 == 3 & p3 == 3) total = total + 50;
  88.  
  89.                 credits = credits + total;
  90.                 label3.Text = "Win: " + total.ToString();
  91.                 label1.Text = "Credits: " + credits.ToString();
  92.             }
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement