Creating a Slot Machine Game in C#

Today in C#, i will teach you how to create a program called Slot Machine Game. Now, let's start this tutorial! 1. Let's start with creating a Windows Form Application in C# for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application. 2. Next, add only one Button named Button1 and labeled it as "SPIN". Insert three PictureBox named PictureBox1,PictureBox2, and PictureBox3. Add also a timer named Timer1. You must design your interface like this: design 3. Insert the following image files to the resources of your project. design design design design 4. Put this code in your code module.
  1. using System.Diagnostics;
  2. using System;
  3. using System.Windows.Forms;
  4. using System.Collections;
  5. using System.Drawing;
  6. using Microsoft.VisualBasic;
  7. using System.Data;
  8. using System.Collections.Generic;
  9.  
  10. namespace Slot_Machine
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.         // initialize global variables
  19.         int m;
  20.         int a;
  21.         int b;
  22.         int c;
  23.                
  24.         private void Button1_Click(object sender, EventArgs e)
  25.         {
  26.             // make timer enabled to true
  27.             timer1.Enabled = true;
  28.         }
  29.  
  30.      
  31.    
  32.  
  33.         private void Form1_Load(object sender, EventArgs e)
  34.         {
  35.             // make timer enabled to stop time
  36.             timer1.Enabled = false;
  37.         }
  38.  
  39.         private void timer1_Tick(object sender, EventArgs e)
  40.         {
  41.  
  42.             // variable m will increment by 10
  43.             m = m + 10;
  44.             // if m will be equal to 1000 and above
  45.             if (m <= 1000)
  46.             {
  47.                 // randomize variable a
  48.                 a = (int)(Conversion.Int(1 + VBMath.Rnd() * 3));
  49.                 // randomize variable b
  50.                 b = (int)(Conversion.Int(1 + VBMath.Rnd() * 3));
  51.  
  52.                 c = (int)(Conversion.Int(1 + VBMath.Rnd() * 3));
  53.                 // randomize variable c
  54.  
  55.                 //contents of variable a
  56.                 switch (a)
  57.                 {
  58.                     case 1:
  59.                         //path of the image file of apple
  60.                         PictureBox1.Image = Image.FromFile("C:\\Users\\don\\Desktop\\bg.o sa vb.net\\Slot Machine\\Slot Machine\\Resources\\apple.jpg");
  61.                         break;
  62.                     //path of the image file of grapes
  63.                     case 2:
  64.                         PictureBox1.Image = Image.FromFile("C:\\Users\\don\\Desktop\\bg.o sa vb.net\\Slot Machine\\Slot Machine\\Resources\\grapes.jpg");
  65.                         break;
  66.                     //path of the image file of strawberry
  67.                     case 3:
  68.                         PictureBox1.Image = Image.FromFile("C:\\Users\\don\\Desktop\\bg.o sa vb.net\\Slot Machine\\Slot Machine\\Resources\\strawberry.jpg");
  69.                         break;
  70.  
  71.                 }
  72.                 //contents of b variable
  73.                 switch (b)
  74.                 {
  75.                     //path of the image file of apple
  76.                     case 1:
  77.                         PictureBox2.Image = Image.FromFile("C:\\Users\\don\\Desktop\\bg.o sa vb.net\\Slot Machine\\Slot Machine\\Resources\\apple.jpg");
  78.                         break;
  79.                     //path of the image file of grapes
  80.                     case 2:
  81.                         PictureBox2.Image = Image.FromFile("C:\\Users\\don\\Desktop\\bg.o sa vb.net\\Slot Machine\\Slot Machine\\Resources\\grapes.jpg");
  82.                         break;
  83.                     //path of the image file of strawberry
  84.                     case 3:
  85.                         PictureBox2.Image = Image.FromFile("C:\\Users\\don\\Desktop\\bg.o sa vb.net\\Slot Machine\\Slot Machine\\Resources\\strawberry.jpg");
  86.                         break;
  87.  
  88.                 }
  89.                 //contents of variable c
  90.                 switch (c)
  91.                 {
  92.                     //path of the image file of apple
  93.                     case 1:
  94.                         PictureBox3.Image = Image.FromFile("C:\\Users\\don\\Desktop\\bg.o sa vb.net\\Slot Machine\\Slot Machine\\Resources\\apple.jpg");
  95.                         break;
  96.                     //path of the image file of grapes
  97.                     case 2:
  98.                         PictureBox3.Image = Image.FromFile("C:\\Users\\don\\Desktop\\bg.o sa vb.net\\Slot Machine\\Slot Machine\\Resources\\grapes.jpg");
  99.                         break;
  100.                     //path of the image file of strawberry
  101.                     case 3:
  102.                         PictureBox3.Image = Image.FromFile("C:\\Users\\don\\Desktop\\bg.o sa vb.net\\Slot Machine\\Slot Machine\\Resources\\strawberry.jpg");
  103.                         break;
  104.  
  105.                 }
  106.  
  107.             }
  108.             else
  109.             {
  110.                 // after reaching m variable to 1000 the timer will be disabled
  111.                 timer1.Enabled = false;
  112.                 // m variable will be back to 0
  113.                 m = 0;
  114.                 // if contents of a will be equal to b and c, you will win the prize
  115.                 if (System.Convert.ToInt32(a == b) == c)
  116.                 {
  117.                     lblMsg.Text = "Jackpot! You won P1,000,000″";
  118.                 }
  119.                     // otherwise, you've lost
  120.                 else
  121.                 {
  122.                     lblMsg.Text = "No luck, try again";
  123.  
  124.                 }
  125.             }
  126.                
  127.         }
  128.     }
  129. }
Output: output For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards, Engr. Lyndon Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer If you have some queries, feel free to contact the number or e-mail below. Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Comments

It says the VBMath and Conversion doesn't exist. I am using Visual Studio 2012 ultimate. Please help as quick as possible.

Omg 🥵

Add new comment