Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 21st, 2012  |  syntax: None  |  size: 6.72 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace Inbetweens
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         /////////////////////////////////////////////////////
  15.         /// Variables declarations used for:
  16.         /// the intial random generation
  17.         /// percentage of winning value
  18.         /// and cash varaibles
  19.         /////////////////////////////////////////////////////
  20.        
  21.         int intValue1;
  22.         int intValue2;
  23.         int intValue3;
  24.         double intCash = 100.00;
  25.         double cashBet;
  26.         double percentageOfWinning;
  27.  
  28.         //////////////////////////////////////////////////////////////
  29.         /// The class used to assign a random number to a variable
  30.         ///////////////////////////////////////////////////////////////
  31.         static Random rndValue = new Random();
  32.        
  33.         public Form1()
  34.         {
  35.             InitializeComponent();
  36.             //////////////////////////////////////////////////////////////////
  37.             /// assigning a random number (to 15) to intValue1
  38.             //////////////////////////////////////////////////////////////////
  39.             intValue1 = rndValue.Next(15)+1;
  40.             lblIntValue1.Text = Convert.ToString(intValue1);
  41.            
  42.             ////////////////////////////////////////////////////////////
  43.             /// assigning a random number (to 15) to intValue1
  44.             //////////////////////////////////////////////////////////////
  45.             intValue2 = rndValue.Next(15)+1;
  46.             lblIntValue2.Text = Convert.ToString(intValue2);
  47.  
  48.             //////////////////////////////////////////////////////////////////////////
  49.             ///Show the cash total
  50.             ///////////////////////////////////////////////////////////////////////////////
  51.             lblCash.Text = "$" + Convert.ToString(intCash);
  52.  
  53.             ////////////////////////////////////////////////////////////////////////////////////////
  54.             /// assigns the percentage of winning via a function that determines the percentage
  55.             //////////////////////////////////////////////////////////////////////////////////////////
  56.             percentageOfWinning = getWinningPercentage();
  57.             LBLpercentage.Text = "Percentage of winning is: " + (percentageOfWinning * 100) + " %";
  58.  
  59.             ////////////////////////////////////////////////////////////////////////////////////////
  60.             /// disables the player from playing any further because they have no money left
  61.             //////////////////////////////////////////////////////////////////////////////////////
  62.             if (intCash < 0)
  63.             {
  64.                 MessageBox.Show("sorry you have lost all of your money goodbye", "Inbetweeners Game Notice", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  65.                 lblIntValue1.Text = " N/A ";
  66.                 lblIntValue2.Text = " N/A ";
  67.                 lblIntValue3.Text = " N/A";
  68.  
  69.                 butClickMe.Enabled = false;
  70.                 button1.Enabled = false;
  71.             }
  72.        
  73.  
  74.         }
  75.  
  76.         private void butClickMe_Click(object sender, EventArgs e)
  77.         {
  78.            
  79.  
  80.             intValue3 = rndValue.Next(15) + 1;
  81.             lblIntValue3.Text = Convert.ToString(intValue3);
  82.  
  83.             if (intValue3 > intValue1 && intValue3 < intValue2 || intValue3 < intValue1 && intValue3 > intValue2)
  84.             {
  85.                 double temp = Convert.ToInt32(txtInput.Text);
  86.                 intCash += temp;
  87.                 lblCash.Text = "$" + Convert.ToString(intCash);
  88.  
  89.                 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);
  90.             }
  91.             else
  92.             {
  93.                 double temp = Convert.ToInt32(txtInput.Text);
  94.                 intCash -= temp;
  95.                 lblCash.Text = "$" + Convert.ToString(intCash);
  96.  
  97.                 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);
  98.             }
  99.         }
  100.  
  101.         private void lblOutput_Click(object sender, EventArgs e)
  102.         {
  103.  
  104.         }
  105.  
  106.         private void lblCash_Click(object sender, EventArgs e)
  107.         {
  108.  
  109.         }
  110.  
  111.         private void txtInput_TextChanged(object sender, EventArgs e)
  112.         {
  113.             double cashBet = 0;
  114.  
  115.             try
  116.             {  
  117.                 cashBet = Convert.ToDouble(txtInput.Text);
  118.             }
  119.             catch (System.Exception exception)
  120.             {
  121.                 butClickMe.Enabled = false; //MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  122.             }
  123.  
  124.             if (cashBet > intCash)
  125.             {
  126.                 MessageBox.Show("You Do Not Have Enough Cash", "Inbetweeners Game Notice", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  127.                 butClickMe.Enabled = false;
  128.             }
  129.             if (cashBet < 0)
  130.             {
  131.                 MessageBox.Show("You Cannot Bet A Negative Number ", "Inbetweeners Game Notice", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  132.                 butClickMe.Enabled = false;
  133.             }
  134.             else
  135.             {
  136.                 butClickMe.Enabled = true;
  137.             }
  138.         }
  139.  
  140.         private void button1_Click(object sender, EventArgs e)
  141.         {
  142.             // assigning a random number (to 15) to intValue1
  143.             intValue1 = rndValue.Next(15) + 1;
  144.             lblIntValue1.Text = Convert.ToString(intValue1);
  145.  
  146.             // assigning a random number (to 15) to intValue1
  147.             intValue2 = rndValue.Next(15) + 1;
  148.             lblIntValue2.Text = Convert.ToString(intValue2);
  149.  
  150.             percentageOfWinning = getWinningPercentage();
  151.             LBLpercentage.Text = "Percentage of winning is: " + (percentageOfWinning * 100) + " %";
  152.         }
  153.  
  154.         private double getWinningPercentage()
  155.         {
  156.             double percentage;
  157.             double newPercentage;
  158.             int higherValue;
  159.             int lowerValue;
  160.  
  161.             if (intValue1 > intValue2)
  162.             {
  163.                 higherValue = intValue1;
  164.                 lowerValue = intValue2;
  165.             }
  166.             else
  167.             {
  168.                 higherValue = intValue2;
  169.                 lowerValue = intValue1;
  170.             }
  171.  
  172.             percentage = (higherValue - lowerValue)  / 15.0;
  173.             newPercentage =  Math.Round(percentage, 2);
  174.  
  175.             return newPercentage;
  176.         }
  177.     }
  178. }