using System; using System.Collections.Generic; using System.ComponentModel; usi
ID: 3685646 • Letter: U
Question
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _12SlotMachineApplication
{
public partial class Form1 : Form
{
private double total;
public Form1()
{
InitializeComponent();
}
private void SpinButton_Click(object sender, EventArgs e)
{
Random rand = new Random();
int index1 = rand.Next(imageList1.Images.Count);
int index2 = rand.Next(imageList1.Images.Count);
int index3 = rand.Next(imageList1.Images.Count);
pictureBox1.Image = imageList1.Images[index1];
pictureBox2.Image = imageList1.Images[index2];
pictureBox3.Image = imageList1.Images[index3];
if (index1 == index2 | index2 == index3 | index1 == index3)
{
double AmountInstered;
AmountInstered = double.Parse(textBox1.Text);
total += AmountInstered * 2;
MessageBox.Show("Congrats! You won double the money!!");
}
else if (index1 == index2 && index2 == index3)
{
double AmountInstered;
AmountInstered = double.Parse(textBox1.Text);
total += AmountInstered * 3;
MessageBox.Show("Contrats! You won triple the money!!");
}
}
}
}
Question: 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 money that the slot machine dispenses back to the user. c Create an application that simulates a slot machine. Figure shows an example of how the form should look. 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 randomly selected symbols. (Slot machines traditionally display fruit symbols. You will find a set of fruit symbols in the ImagesFruit Symbols folder of the Student Sample Programs.) Figure Slot Machine application Slot Machine Amourt ineeted s Spin If none of the randomly 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 slot 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.Threading.Tasks;
using System.Windows.Forms;
namespace _12SlotMachineApplication
{
public partial class Form1 : Form
{
private double total;
public Form1()
{
InitializeComponent();
}
private void SpinButton_Click(object sender, EventArgs e)
{
Random rand = new Random();
int index1 = rand.Next(0, imageList1.Images.Count);
int index2 = rand.Next(0, imageList1.Images.Count);
int index3 = rand.Next(0, imageList1.Images.Count);
pictureBox1.Image = imageList1.Images[index1];
pictureBox2.Image = imageList1.Images[index2];
pictureBox3.Image = imageList1.Images[index3];
if (index1 == index2 || index2 == index3 || index1 == index3)
{
double AmountInstered;
AmountInstered = double.Parse(textBox1.Text);
total += AmountInstered * 2;
MessageBox.Show("Congrats! You won double the money!!");
}
else if (index1 == index2 && index2 == index3)
{
double AmountInstered;
AmountInstered = double.Parse(textBox1.Text);
total += AmountInstered * 3;
MessageBox.Show("Contrats! You won triple the money!!");
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.