// Click event handler method to exit slot machine form // and go to display winnings form. player object's score is total score. private void btnCashOut_Click(object sender, EventArgs e) { GlobalsClass.playerObject.setScore(totalScore); Form frmDisplayWinnings = new Forms.frmDisplayFinalWinnings(); frmDisplayWinnings.Show(); this.Hide(); }
// Click event handler method for the spin button. Uses the spin method. // Go and get the calculation of the winnings from calculate reels method. // Check for jackpot. Add winnings to score. Display score in text box. // Check for 0. If neither then player won. Add winnings to total. // Display Score and winnings in the text boxes. // Let user play until they have 0 coins. private void btnSpin_Click(object sender, EventArgs e) { //spinNoise.Play(); if (currentBet <= totalScore) { btnSpin.BackColor = Color.SteelBlue; spin(); winnings = calculateReelCombos(); txtWinnings.Text = winnings.ToString(); // Show form Display Winnings for winnings. // pass in the winnings. if (winnings > 0) { frmDisplayWinnings frmRef = new frmDisplayWinnings(txtWinnings.Text); frmRef.Show(); totalScore += winnings; txtBalance.Text = totalScore.ToString(); } else if (winnings == 0) { frmDisplayWinnings frmRef = new frmDisplayWinnings(txtWinnings.Text); frmRef.Show(); totalScore -= currentBet; txtBalance.Text = totalScore.ToString(); if (totalScore <= 0) { frmRef.Hide(); } } if (totalScore <= 0) { youFailed(); Form frmDisplayWinnings = new Forms.frmDisplayFinalWinnings(); frmDisplayWinnings.Show(); this.Hide(); } } else { MessageBox.Show("You don't have the coins for that bet...", "Error"); } }