Advertisement
Guest User

Untitled

a guest
Jan 11th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7.  
  8. namespace MegaChallangeCasino
  9. {
  10.     public partial class Default : System.Web.UI.Page
  11.     {
  12.         Random random = new Random();
  13.         decimal money = 100;
  14.         Image[] Pictures = new Image[3];
  15.  
  16.         protected void Page_Load(object sender, EventArgs e)
  17.         {
  18.             if (!IsPostBack)
  19.             {
  20.                 ViewState["money"] = money;
  21.                 SetImages();
  22.             }
  23.         }
  24.  
  25.         protected void Button1_Click(object sender, EventArgs e)
  26.         {
  27.             getitstarted();
  28.          
  29.  
  30.         }
  31.         private void getitstarted()
  32.         {
  33.             decimal winning = 0;
  34.             decimal multiplier = 0;
  35.             string[] images = new string[3];
  36.             // set the 3 random images and givve me the result
  37.  
  38.             //SetImages();
  39.  
  40.  
  41.             // lets roll the dice
  42.            
  43.             images = SetImages();
  44.             multiplier = PrepareGettingMultiplier(images);
  45.             decimal mybet = 0;
  46.             if (!getMyBetFromTextBox(out mybet)) return;
  47.  
  48.             decimal result;
  49.             result = mybet * multiplier;
  50.            
  51.             //well if you lost
  52.             if (ilost(mybet,multiplier, out money)) return;
  53.  
  54.             //well if you won
  55.             iWon(winning, mybet, multiplier);
  56.            
  57.         }
  58.  
  59.  
  60.         private string[] SetImages()
  61.         {
  62.             string[] selected = new string[3];
  63.             string[] images = new string[10] { "Bar.png", "Bell.png", "Lemon.png", "Orange.png", "Plum.png", "Seven.png", "Strawberry.png", "Watermellon.png", "Diamond.png", "HorseShoe.png" };
  64.  
  65.             Pictures[0] = Image1;
  66.             Pictures[1] = Image2;
  67.             Pictures[2] = Image3;
  68.             Pictures[0].ImageUrl = images[random.Next(0, 10)];
  69.             Pictures[1].ImageUrl = images[random.Next(0, 10)];
  70.             Pictures[2].ImageUrl = images[random.Next(0, 10)];
  71.             selected = new string[] { Pictures[0].ImageUrl, Pictures[1].ImageUrl, Pictures[2].ImageUrl};
  72.             return selected;
  73.  
  74.         }
  75.         private decimal PrepareGettingMultiplier(string[] images)
  76.         {
  77.             int bar = 0;
  78.             int orange = 0;
  79.             int sevens = 0;
  80.  
  81.             HowManyTimesAreBarSevenAndOrangeInTheImages(out bar, out orange, out sevens, images);
  82.            
  83.            return GettingMultiplier(orange, sevens,bar);
  84.         }
  85.         private void HowManyTimesAreBarSevenAndOrangeInTheImages(out int bar,out int orange,out int sevens,string[] images)
  86.         {
  87.             bar = 0;
  88.             sevens = 0;
  89.             orange = 0;
  90.  
  91.             for (int i = 0; i < images.Length; i++)
  92.             {
  93.                 if (images[i] == "Bar.png")
  94.                     bar = 0;
  95.  
  96.  
  97.                 else if (images[i] == "Seven.png")
  98.                     sevens += 1;
  99.                 else if (images[i] == "Orange.png")
  100.                     orange += 1;
  101.  
  102.             }
  103.         }
  104.         private decimal GettingMultiplier(int orange,int sevens,int bar)
  105.         {
  106.             decimal multiplier = 0;
  107.             if (bar != 0)
  108.                 multiplier = 0;
  109.             else if (orange == 1)
  110.                 multiplier = 2;
  111.             else if (orange == 2)
  112.                 multiplier = 3;
  113.             else if (orange == 3)
  114.                 multiplier = 4;
  115.             else if (sevens == 3)
  116.                 multiplier = 100;
  117.             else multiplier = 0;
  118.             return multiplier;
  119.         }
  120.         private bool getMyBetFromTextBox(out decimal mybet)
  121.         {
  122.             mybet = 0;
  123.             if (decimal.TryParse(TextBox1.Text.Trim(), out mybet)) return true;
  124.             else return false;
  125.         }
  126.         private bool ilost(decimal mybet,decimal multiplier,out decimal money)
  127.         {
  128.             money = (decimal)ViewState["money"];
  129.             if(multiplier==0)
  130.             {
  131.                 resultLabel.Text = "Sorry, you lost " + mybet.ToString("C") + " Better luck next time";
  132.              
  133.                 money -= mybet;
  134.                 moneyLabel.Text = "The Money You Have: " + money.ToString("C");
  135.                 ViewState["money"] = money;
  136.                 return true;
  137.             }
  138.             return false;
  139.         }
  140.         private void iWon(decimal winning,decimal mybet,decimal multiplier)
  141.         {
  142.      
  143.             money = (decimal)ViewState["money"];
  144.             winning = mybet * multiplier;
  145.             money += (mybet * multiplier);
  146.  
  147.             resultLabel.Text = "You've won: " + winning.ToString("C");
  148.             moneyLabel.Text = "Your Money: " + money.ToString("C");
  149.             ViewState["money"] = money;
  150.  
  151.         }
  152.  
  153.         protected void TextBox1_TextChanged(object sender, EventArgs e)
  154.         {
  155.            
  156.  
  157.         }
  158.     }
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement