Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help with C# coding. Slot Machine Simulation: A slot machine is a gambling devic

ID: 651638 • Letter: H

Question

Help with C# coding.

Slot Machine Simulation: A slot machine is a gambling device into which the user inserts money and then pulls a lever (or presses a button). The slot machine then displays a set of random images. If two or more of the images match, the user wins an amount of monet that the slot machine. The application should let the user enter into a TextBox the amount of money he or she is inserting into the machine. When the user clicks the spin button, the application should display three randomnly selected symbols (slot machines traditionally display fruit symbols)- The images have been provided for use.

If none of the randomnly displayed images match, the program should inform the user that he or she has won $0. If two of the images match, the program should inform the user that he or she has won two times the amount entered. If three of the images match, the program should inform the user that he or she has won three times the amount entered. When the user clicks the EXIT button to exit the application, the program should display the total amount of money entered into the machine and the total amount won.

Explanation / Answer

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace SlotMachine

{

    public partial class SlotMachine : Form

    {

        public SlotMachine()

        {

            InitializeComponent();

        }

        decimal amtEntered;

        Random rand = new Random();

        decimal total;

        decimal win1;

        decimal win2;

        decimal totalWin;

        private void GamePlay()

        {

            try

            {

                txtbxInputBet.Focus();

                int index1 = rand.Next(imageListFruit.Images.Count);

                int index2 = new int();

                index2 = rand.Next(imageListFruit.Images.Count);

                int index3 = new int();

                index3 = rand.Next(imageListFruit.Images.Count);

                pictbxOne.Image = imageListFruit.Images[index1];

                pictbxTwo.Image = imageListFruit.Images[index2];

                pictbxThree.Image = imageListFruit.Images[index3];

                amtEntered = decimal.Parse(txtbxInputBet.Text.Trim());

                total += amtEntered;

               

                win1 = amtEntered * 2;

                win2 = amtEntered * 3;

                totalWin = 0;

                if (index1 == index2 || index1 == index3 || index2 == index3)

                {

                    MessageBox.Show("Excellent! You win " + win1.ToString("c") + " !");

                   

                }

                else if (index1 == index2 && index1 == index3 && index2 == index3)

                {

                    MessageBox.Show("Excellent! You win " + win2.ToString("c") + " !");

                   

                }

                else

                {

                    MessageBox.Show("House Wins!");

                }

               

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

          

          

        }

        private void btnSpin_Click(object sender, EventArgs e)

        {

            GamePlay();

        }

        private void btnExit_Click(object sender, EventArgs e)

        {

            try

            {

                int index1 = rand.Next(imageListFruit.Images.Count);

                int index2 = new int();

                index2 = rand.Next(imageListFruit.Images.Count);

                int index3 = new int();

                index3 = rand.Next(imageListFruit.Images.Count);

                amtEntered = decimal.Parse(txtbxInputBet.Text.Trim());

              

                win1 = amtEntered * 2;

                win2 = amtEntered * 3;

                total = 0;

               

                    if (index1 == index2 || index1 == index3 || index2 == index3)

                    {

                        total += amtEntered;

                        totalWin += win1;

                        MessageBox.Show(" You spent " + total.ToString("c"));

                        MessageBox.Show("You won: " + win1.ToString("c"));

                        

                    }

                        else if (index1 == index2 && index1 == index3 && index2 == index3)

                        {

                            total += amtEntered;

                            totalWin += win2;

                            MessageBox.Show(" You spent " + total.ToString("c"));

                            MessageBox.Show("You won: " + win2.ToString("c"));

                        }

                        else

                        {

                            total += amtEntered;

                           

                            MessageBox.Show("Total Winnings: $0.00. You spent " + total.ToString("c"));

                        }

                   

                    txtbxInputBet.Clear();   

                    }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

           

            this.Close();

        }

       

        }

    }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote