- 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 Inbetweens
- {
- public partial class Form1 : Form
- {
- /////////////////////////////////////////////////////
- /// Variables declarations used for:
- /// the intial random generation
- /// percentage of winning value
- /// and cash varaibles
- /////////////////////////////////////////////////////
- int intValue1;
- int intValue2;
- int intValue3;
- double intCash = 100.00;
- double cashBet;
- double percentageOfWinning;
- //////////////////////////////////////////////////////////////
- /// The class used to assign a random number to a variable
- ///////////////////////////////////////////////////////////////
- static Random rndValue = new Random();
- public Form1()
- {
- InitializeComponent();
- //////////////////////////////////////////////////////////////////
- /// assigning a random number (to 15) to intValue1
- //////////////////////////////////////////////////////////////////
- intValue1 = rndValue.Next(15)+1;
- lblIntValue1.Text = Convert.ToString(intValue1);
- ////////////////////////////////////////////////////////////
- /// assigning a random number (to 15) to intValue1
- //////////////////////////////////////////////////////////////
- intValue2 = rndValue.Next(15)+1;
- lblIntValue2.Text = Convert.ToString(intValue2);
- //////////////////////////////////////////////////////////////////////////
- ///Show the cash total
- ///////////////////////////////////////////////////////////////////////////////
- lblCash.Text = "$" + Convert.ToString(intCash);
- ////////////////////////////////////////////////////////////////////////////////////////
- /// assigns the percentage of winning via a function that determines the percentage
- //////////////////////////////////////////////////////////////////////////////////////////
- percentageOfWinning = getWinningPercentage();
- LBLpercentage.Text = "Percentage of winning is: " + (percentageOfWinning * 100) + " %";
- ////////////////////////////////////////////////////////////////////////////////////////
- /// disables the player from playing any further because they have no money left
- //////////////////////////////////////////////////////////////////////////////////////
- if (intCash < 0)
- {
- MessageBox.Show("sorry you have lost all of your money goodbye", "Inbetweeners Game Notice", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- lblIntValue1.Text = " N/A ";
- lblIntValue2.Text = " N/A ";
- lblIntValue3.Text = " N/A";
- butClickMe.Enabled = false;
- button1.Enabled = false;
- }
- }
- private void butClickMe_Click(object sender, EventArgs e)
- {
- intValue3 = rndValue.Next(15) + 1;
- lblIntValue3.Text = Convert.ToString(intValue3);
- if (intValue3 > intValue1 && intValue3 < intValue2 || intValue3 < intValue1 && intValue3 > intValue2)
- {
- double temp = Convert.ToInt32(txtInput.Text);
- intCash += temp;
- lblCash.Text = "$" + Convert.ToString(intCash);
- MessageBox.Show("Congratulations you have won! " + "$" + temp + "\n Press Play Again to get a new set of Numbers", "Inbetweeners Game Notice", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- }
- else
- {
- double temp = Convert.ToInt32(txtInput.Text);
- intCash -= temp;
- lblCash.Text = "$" + Convert.ToString(intCash);
- MessageBox.Show("Sorry you have lost " + "$" + temp + "\n Press Play Again to get a new set of Numbers", "Inbetweeners Game Notice", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- }
- }
- private void lblOutput_Click(object sender, EventArgs e)
- {
- }
- private void lblCash_Click(object sender, EventArgs e)
- {
- }
- private void txtInput_TextChanged(object sender, EventArgs e)
- {
- double cashBet = 0;
- try
- {
- cashBet = Convert.ToDouble(txtInput.Text);
- }
- catch (System.Exception exception)
- {
- butClickMe.Enabled = false; //MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- if (cashBet > intCash)
- {
- MessageBox.Show("You Do Not Have Enough Cash", "Inbetweeners Game Notice", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- butClickMe.Enabled = false;
- }
- if (cashBet < 0)
- {
- MessageBox.Show("You Cannot Bet A Negative Number ", "Inbetweeners Game Notice", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- butClickMe.Enabled = false;
- }
- else
- {
- butClickMe.Enabled = true;
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- // assigning a random number (to 15) to intValue1
- intValue1 = rndValue.Next(15) + 1;
- lblIntValue1.Text = Convert.ToString(intValue1);
- // assigning a random number (to 15) to intValue1
- intValue2 = rndValue.Next(15) + 1;
- lblIntValue2.Text = Convert.ToString(intValue2);
- percentageOfWinning = getWinningPercentage();
- LBLpercentage.Text = "Percentage of winning is: " + (percentageOfWinning * 100) + " %";
- }
- private double getWinningPercentage()
- {
- double percentage;
- double newPercentage;
- int higherValue;
- int lowerValue;
- if (intValue1 > intValue2)
- {
- higherValue = intValue1;
- lowerValue = intValue2;
- }
- else
- {
- higherValue = intValue2;
- lowerValue = intValue1;
- }
- percentage = (higherValue - lowerValue) / 15.0;
- newPercentage = Math.Round(percentage, 2);
- return newPercentage;
- }
- }
- }