Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace MegaChallangeCasino
- {
- public partial class Default : System.Web.UI.Page
- {
- Random random = new Random();
- decimal money = 100;
- Image[] Pictures = new Image[3];
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- ViewState["money"] = money;
- SetImages();
- }
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- getitstarted();
- }
- private void getitstarted()
- {
- decimal winning = 0;
- decimal multiplier = 0;
- string[] images = new string[3];
- // set the 3 random images and givve me the result
- //SetImages();
- // lets roll the dice
- images = SetImages();
- multiplier = PrepareGettingMultiplier(images);
- decimal mybet = 0;
- if (!getMyBetFromTextBox(out mybet)) return;
- decimal result;
- result = mybet * multiplier;
- //well if you lost
- if (ilost(mybet,multiplier, out money)) return;
- //well if you won
- iWon(winning, mybet, multiplier);
- }
- private string[] SetImages()
- {
- string[] selected = new string[3];
- 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" };
- Pictures[0] = Image1;
- Pictures[1] = Image2;
- Pictures[2] = Image3;
- Pictures[0].ImageUrl = images[random.Next(0, 10)];
- Pictures[1].ImageUrl = images[random.Next(0, 10)];
- Pictures[2].ImageUrl = images[random.Next(0, 10)];
- selected = new string[] { Pictures[0].ImageUrl, Pictures[1].ImageUrl, Pictures[2].ImageUrl};
- return selected;
- }
- private decimal PrepareGettingMultiplier(string[] images)
- {
- int bar = 0;
- int orange = 0;
- int sevens = 0;
- HowManyTimesAreBarSevenAndOrangeInTheImages(out bar, out orange, out sevens, images);
- return GettingMultiplier(orange, sevens,bar);
- }
- private void HowManyTimesAreBarSevenAndOrangeInTheImages(out int bar,out int orange,out int sevens,string[] images)
- {
- bar = 0;
- sevens = 0;
- orange = 0;
- for (int i = 0; i < images.Length; i++)
- {
- if (images[i] == "Bar.png")
- bar = 0;
- else if (images[i] == "Seven.png")
- sevens += 1;
- else if (images[i] == "Orange.png")
- orange += 1;
- }
- }
- private decimal GettingMultiplier(int orange,int sevens,int bar)
- {
- decimal multiplier = 0;
- if (bar != 0)
- multiplier = 0;
- else if (orange == 1)
- multiplier = 2;
- else if (orange == 2)
- multiplier = 3;
- else if (orange == 3)
- multiplier = 4;
- else if (sevens == 3)
- multiplier = 100;
- else multiplier = 0;
- return multiplier;
- }
- private bool getMyBetFromTextBox(out decimal mybet)
- {
- mybet = 0;
- if (decimal.TryParse(TextBox1.Text.Trim(), out mybet)) return true;
- else return false;
- }
- private bool ilost(decimal mybet,decimal multiplier,out decimal money)
- {
- money = (decimal)ViewState["money"];
- if(multiplier==0)
- {
- resultLabel.Text = "Sorry, you lost " + mybet.ToString("C") + " Better luck next time";
- money -= mybet;
- moneyLabel.Text = "The Money You Have: " + money.ToString("C");
- ViewState["money"] = money;
- return true;
- }
- return false;
- }
- private void iWon(decimal winning,decimal mybet,decimal multiplier)
- {
- money = (decimal)ViewState["money"];
- winning = mybet * multiplier;
- money += (mybet * multiplier);
- resultLabel.Text = "You've won: " + winning.ToString("C");
- moneyLabel.Text = "Your Money: " + money.ToString("C");
- ViewState["money"] = money;
- }
- protected void TextBox1_TextChanged(object sender, EventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement