Hi Everyone,
It has been some time since I've posted here but I am truly having trouble seeing the forest for the trees so to speak. I have changed my code so many times I missed the time it worked because I want it to do more.
Upon Exit btn click event total winnings and total spent should display in a msgbx. Spin click event shows msgbx with winner and winnings.
I would really appreciate a fresh set of eyes and a shove in the right direction. For some reason it shows only the amtEntered in the text box and 0.00 winnings - as if it is always branching to the else in the btnExit_Click. I'm sure I have some superfluous stuff hanging out in here...pls be kind.
Thanks.
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();
}
}
}