Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ChallengeCasino
- {
- public partial class Default : System.Web.UI.Page
- {
- Random randomLocationValue = new Random();
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!Page.IsPostBack)
- {
- DisplayFirstImage();
- DisplaySecondImage();
- DisplayThirdImage();
- }
- }
- protected void okButton_Click(object sender, EventArgs e)
- {
- DisplayFirstImage();
- DisplaySecondImage();
- DisplayThirdImage();
- DisplayWinOrLoss();
- DisplayPlayerBalance();
- }
- protected string ImageAddress(int randomLocationValue)
- {
- string myImage;
- string[] imageLocation = new string[] { "Images/Bar.png", "Images/Bell.png", "Images/Cherry.png", "Images/Clover.png", "Images/Diamond.png",
- "Images/HorseShoe.png", "Images/Lemon.png", "Images/Orange.png", "Images/Plum.png", "Images/Seven.png", "Images/Strawberry.png", "Images/Watermellon.png"};
- return myImage = imageLocation[randomLocationValue];
- }
- protected int FirstImageLocation()
- {
- int firstImage = randomLocationValue.Next(0, 11);
- return firstImage;
- }
- protected int SecondImageLocation()
- {
- int secondImage = randomLocationValue.Next(0, 11);
- return secondImage;
- }
- protected int ThirdImageLocation()
- {
- int thirdImage = randomLocationValue.Next(0, 11);
- return thirdImage;
- }
- protected int DisplayFirstImage()
- {
- int myFirstImage = FirstImageLocation();
- firstImage.ImageUrl = ImageAddress(myFirstImage);
- firstImagePositionResultLabel.Text = String.Format("First Image location {0}", myFirstImage);
- return myFirstImage;
- }
- protected int DisplaySecondImage()
- {
- int mySecondImage = SecondImageLocation();
- secondImage.ImageUrl = ImageAddress(mySecondImage);
- secondImagePositionResultLabel.Text = String.Format("Second Image location {0}", mySecondImage);
- return mySecondImage;
- }
- protected int DisplayThirdImage()
- {
- int myThirdImage = ThirdImageLocation();
- thirdImage.ImageUrl = ImageAddress(myThirdImage);
- thirdImagePositionResultLabel.Text = String.Format("Third Image location {0}", myThirdImage);
- return myThirdImage;
- }
- protected int PlayerStartingMoney()
- {
- return 100;
- }
- protected int BetAmount()
- {
- int betValue = int.Parse(yourBetTextBox.Text);
- return betValue;
- }
- protected bool CheckForBar()
- {
- bool validateForBar = false;
- if (DisplayFirstImage() == 0 || DisplaySecondImage() == 0 || DisplayThirdImage() == 0)
- {
- validateForBar = true;
- }
- return validateForBar;
- }
- protected bool CheckForSeven()
- {
- bool validateForSeven = false;
- if (DisplayFirstImage() == 9 && DisplaySecondImage() == 9 && DisplayThirdImage() == 9)
- {
- validateForSeven = true;
- }
- return validateForSeven;
- }
- protected bool CheckForCherry()
- {
- bool validateForCherry = false;
- if (DisplayFirstImage() == 2 || DisplaySecondImage() == 2 || DisplayThirdImage() == 2)
- {
- validateForCherry = true;
- }
- return validateForCherry;
- }
- protected int BarReturnValue()
- {
- return 0;
- }
- protected int SevenReturnValue()
- {
- return 100 * BetAmount();
- }
- protected int CherryMultiplier()
- {
- int multiplier = 0;
- if (DisplayFirstImage() == 2) multiplier++;
- if (DisplaySecondImage() == 2) multiplier++;
- if (DisplayThirdImage() == 2) multiplier++;
- return multiplier * BetAmount();
- }
- protected int CalculateWinAmount()
- {
- if (CheckForBar() == true)
- {
- return BarReturnValue();
- }
- else if (CheckForSeven() == true)
- {
- return SevenReturnValue();
- }
- else if (CheckForCherry() == true)
- {
- return CherryMultiplier();
- }
- else
- {
- return 0;
- }
- }
- protected void DisplayWinOrLoss()
- {
- int winningAmount = CalculateWinAmount();
- if (winningAmount > 0)
- {
- resultLabel.Text = String.Format("You bet {0:C} and won {1:C}", BetAmount(), winningAmount);
- }
- else
- {
- resultLabel.Text = String.Format("Sorry, you lost {0:C}. Better luck next time.", BetAmount());
- }
- }
- static int balance = 100;
- protected int PlayerBalance()
- {
- int winAmount = CalculateWinAmount();
- if (winAmount > 0)
- {
- balance += winAmount;
- }
- else
- {
- int betAmount = BetAmount();
- balance -= betAmount;
- }
- return balance;
- }
- protected double ValidateForOkButton()
- {
- int myBalane = PlayerBalance();
- return myBalane;
- }
- protected void DisplayPlayerBalance()
- {
- int myBalance = PlayerBalance();
- playerTotalAmountLabel.Text = myBalance.ToString();
- if (myBalance <= 0)
- {
- okButton.Enabled = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement