This is C# code for Deal or No Deal game. The player chooses a boxes to knock an amount of money off the board.The objective is to leave the game with greatest amount.There are 21 boxes. Each time a player opens 3 boxes her or she receives an offer with an option to accept or reject an offer.The last box will be the amount the player leaves with.I hope you will find it useful.
Deal or No Deal :
Download this project from: www.ScriptHood.com
Code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace DealNotDeal { ////// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { long[] scoreList = new long[21] { 100, 200, 300, 400, 500, 800, 1000, 5000, 8000, 10000, 15000, 20000, 30000, 50000, 60000, 80000, 100000, 130000, 160000, 180000, 200000 }; long[] buttonList = new long[21]; long[] offerGen = new long[21] { 100, 200, 300, 400, 500, 800, 1000, 5000, 8000, 10000, 15000, 20000, 30000, 50000, 60000, 80000, 100000, 130000, 160000, 180000, 200000 }; int[] tempList=new int[21]; long finalValue; bool[] buttonFlag = new bool[21]; long newOffer; bool accept = false; int offerCounter=0; int offerRemainder; string tempLabel; Random random = new Random(); public MainWindow() { int temp; for (int i = 0; i < 21; i++) { buttonFlag[i] = false; } for (int i = 0; i < 21; i++) { tempList[i] = 30; } for (int i = 0; i < 21; i++) { temp = random.Next(21); while (IsUsed(temp)) { temp = random.Next(21); } buttonList[i] = scoreList[temp]; tempList[i] = temp; } InitializeComponent(); } private bool IsUsed(int temp) { bool flag = false; for (int i = 0; i < 21; i++) { if (tempList[i] == temp) { flag= true; } } return flag; } private void LostValues(string p) { if (label1.Content.ToString() == p) { label1.Content += " (lost)"; } else if (label2.Content.ToString() == p) { label2.Content += " (lost)"; } else if (label3.Content.ToString() == p) { label3.Content += " (lost)"; } else if (label4.Content.ToString() == p) { label4.Content += " (lost)"; } else if (label5.Content.ToString() == p) { label5.Content += " (lost)"; } else if (label6.Content.ToString() == p) { label6.Content += " (lost)"; } else if (label7.Content.ToString() == p) { label7.Content += " (lost)"; } else if (label8.Content.ToString() == p) { label8.Content += " (lost)"; } else if (label9.Content.ToString() == p) { label9.Content += " (lost)"; } else if (label10.Content.ToString() == p) { label10.Content += " (lost)"; } else if (label11.Content.ToString() == p) { label11.Content += " (lost)"; } else if (label12.Content.ToString() == p) { label12.Content += " (lost)"; } else if (label13.Content.ToString() == p) { label13.Content += " (lost)"; } else if (label14.Content.ToString() == p) { label14.Content += " (lost)"; } else if (label15.Content.ToString() == p) { label15.Content += " (lost)"; } else if (label16.Content.ToString() == p) { label16.Content += " (lost)"; } else if (label17.Content.ToString() == p) { label17.Content += " (lost)"; } else if (label18.Content.ToString() == p) { label18.Content += " (lost)"; } else if (label19.Content.ToString() == p) { label19.Content += " (lost)"; } else if (label20.Content.ToString() == p) { label20.Content += " (lost)"; } else if (label21.Content.ToString() == p) { label21.Content += " (lost)"; } } private void GenerateNewOffer() { long sum = 0; long avg; for (int i = 0; i < 21; i++) { sum += offerGen[i]; } avg = sum / (21 - offerCounter); newOffer = avg; } private void CallZero(string tempLabel) { long val = Convert.ToInt64(tempLabel); for (int i = 0; i < 21; i++) { if (offerGen[i] == val) { offerGen[i] = 0; } } } private long GetFinalValue() { for (int i = 0; i < 21; i++) { if (offerGen[i] != 0) { finalValue = offerGen[i]; } } return finalValue; } private void button1_Click(object sender, RoutedEventArgs e) { if (buttonFlag[0]) { return; } buttonFlag[0] = true; if (accept) { return; } textBox2.Text = ""; textBox1.Text = ""; offerCounter++; button1.Content=tempLabel=buttonList[0].ToString(); LostValues(tempLabel); textBox1.Text = "-> You just opened " + tempLabel+"\n"; CallZero(tempLabel); if (offerCounter == 20) { finalValue= GetFinalValue(); MessageBox.Show("Game is over.You won "+finalValue.ToString()); textBox1.Text = "Game is over" + "\n"; textBox1.Text += "You Won: " + finalValue.ToString(); label28.Content = "You Won:"; label29.Content = finalValue.ToString(); textBlock1.Text = "Game Over"; accept = true; } if (offerCounter <= 18) { if ((offerCounter % 3) == 0) { GenerateNewOffer(); textBox1.Text += "-> You have a new offer "; MessageBox.Show("You received an offer !"); textBox2.Text = newOffer.ToString(); } else { offerRemainder = 3 - (offerCounter % 3); textBox1.Text += "-> Open " + offerRemainder.ToString() + " more box(es) for a new offer"; } } else textBox2.Text = ""; } private void button2_Click(object sender, RoutedEventArgs e) { if (buttonFlag[1]) { return; } buttonFlag[1] = true; if (accept) { return; } textBox2.Text = ""; textBox1.Text = ""; offerCounter++; button2.Content =tempLabel= buttonList[1].ToString(); LostValues(tempLabel); textBox1.Text = "-> You just opened " + tempLabel + "\n"; CallZero(tempLabel); if (offerCounter == 20) { finalValue = GetFinalValue(); MessageBox.Show("Game is over.You won " + finalValue.ToString()); textBox1.Text = "Game is over" + "\n"; textBox1.Text += "You Won: " + finalValue.ToString(); label28.Content = "You Won:"; label29.Content = finalValue.ToString(); textBlock1.Text = "Game Over"; accept = true; } if (offerCounter <= 18) { if ((offerCounter % 3) == 0) { GenerateNewOffer(); textBox1.Text += "-> You have a new offer "; MessageBox.Show("You received an offer !"); textBox2.Text = newOffer.ToString(); } else { offerRemainder = 3 - (offerCounter % 3); textBox1.Text += "-> Open " + offerRemainder.ToString() + " more box(es) for a new offer"; } } else textBox2.Text = ""; } private void button3_Click(object sender, RoutedEventArgs e) { if (buttonFlag[2]) { return; } buttonFlag[2] = true; if (accept) { return; } textBox2.Text = ""; textBox1.Text = ""; offerCounter++; button3.Content=tempLabel = buttonList[2].ToString(); LostValues(tempLabel); textBox1.Text = "-> You just opened " + tempLabel + "\n"; CallZero(tempLabel); if (offerCounter == 20) { finalValue = GetFinalValue(); MessageBox.Show("Game is over.You won " + finalValue.ToString()); textBox1.Text = "Game is over" + "\n"; textBox1.Text += "You Won: " + finalValue.ToString(); label28.Content = "You Won:"; label29.Content = finalValue.ToString(); textBlock1.Text = "Game Over"; accept = true; } if (offerCounter <= 18) { if ((offerCounter % 3) == 0) { GenerateNewOffer(); textBox1.Text += "-> You have a new offer "; MessageBox.Show("You received an offer !"); textBox2.Text = newOffer.ToString(); } else { offerRemainder = 3 - (offerCounter % 3); textBox1.Text += "-> Open " + offerRemainder.ToString() + " more box(es) for a new offer"; } } else textBox2.Text = ""; } private void button4_Click(object sender, RoutedEventArgs e) { if (buttonFlag[3]) { return; } buttonFlag[3] = true; if (accept) { return; } textBox2.Text = ""; textBox1.Text = ""; offerCounter++; button4.Content = tempLabel = buttonList[3].ToString(); LostValues(tempLabel); textBox1.Text = "-> You just opened " + tempLabel + "\n"; CallZero(tempLabel); if (offerCounter == 20) { finalValue = GetFinalValue(); MessageBox.Show("Game is over.You won " + finalValue.ToString()); textBox1.Text = "Game is over" + "\n"; textBox1.Text += "You Won: " + finalValue.ToString(); label28.Content = "You Won:"; label29.Content = finalValue.ToString(); textBlock1.Text = "Game Over"; accept = true; } if (offerCounter <= 18) { if ((offerCounter % 3) == 0) { GenerateNewOffer(); textBox1.Text += "-> You have a new offer "; MessageBox.Show("You received an offer !"); textBox2.Text = newOffer.ToString(); } else { offerRemainder = 3 - (offerCounter % 3); textBox1.Text += "-> Open " + offerRemainder.ToString() + " more box(es) for a new offer"; } } else textBox2.Text = ""; } private void button5_Click(object sender, RoutedEventArgs e) { if (buttonFlag[4]) { return; } buttonFlag[4] = true; if (accept) { return; } textBox2.Text = ""; textBox1.Text = ""; offerCounter++; button5.Content = tempLabel = buttonList[4].ToString(); LostValues(tempLabel); textBox1.Text = "-> You just opened " + tempLabel + "\n"; CallZero(tempLabel); if (offerCounter == 20) { finalValue = GetFinalValue(); MessageBox.Show("Game is over.You won " + finalValue.ToString()); textBox1.Text = "Game is over" + "\n"; textBox1.Text += "You Won: " + finalValue.ToString(); label28.Content = "You Won:"; label29.Content = finalValue.ToString(); textBlock1.Text = "Game Over"; accept = true; } if (offerCounter <= 18) { if ((offerCounter % 3) == 0) { GenerateNewOffer(); textBox1.Text += "-> You have a new offer "; MessageBox.Show("You received an offer !"); textBox2.Text = newOffer.ToString(); } else { offerRemainder = 3 - (offerCounter % 3); textBox1.Text += "-> Open " + offerRemainder.ToString() + " more box(es) for a new offer"; } } else textBox2.Text = ""; } private void button6_Click(object sender, RoutedEventArgs e) { if (buttonFlag[5]) { return; } buttonFlag[5] = true; if (accept) { return; } textBox2.Text = ""; textBox1.Text = ""; offerCounter++; button6.Content = tempLabel = buttonList[5].ToString(); LostValues(tempLabel); textBox1.Text = "-> You just opened " + tempLabel + "\n"; CallZero(tempLabel); if (offerCounter == 20) { finalValue = GetFinalValue(); MessageBox.Show("Game is over.You won " + finalValue.ToString()); textBox1.Text = "Game is over" + "\n"; textBox1.Text += "You Won: " + finalValue.ToString(); label28.Content = "You Won:"; label29.Content = finalValue.ToString(); textBlock1.Text = "Game Over"; accept = true; } if (offerCounter <= 18) { if ((offerCounter % 3) == 0) { GenerateNewOffer(); textBox1.Text += "-> You have a new offer "; MessageBox.Show("You received an offer !"); textBox2.Text = newOffer.ToString(); } else { offerRemainder = 3 - (offerCounter % 3); textBox1.Text += "-> Open " + offerRemainder.ToString() + " more box(es) for a new offer"; } } else textBox2.Text = ""; } private void button7_Click(object sender, RoutedEventArgs e) { if (buttonFlag[6]) { return; } buttonFlag[6] = true; if (accept) { return; } textBox2.Text = ""; textBox1.Text = ""; offerCounter++; button7.Content = tempLabel = buttonList[6].ToString(); LostValues(tempLabel); textBox1.Text = "-> You just opened " + tempLabel + "\n"; CallZero(tempLabel); if (offerCounter == 20) { finalValue = GetFinalValue(); MessageBox.Show("Game is over.You won " + finalValue.ToString()); textBox1.Text = "Game is over" + "\n"; textBox1.Text += "You Won: " + finalValue.ToString(); label28.Content = "You Won:"; label29.Content = finalValue.ToString(); textBlock1.Text = "Game Over"; accept = true; } if (offerCounter <= 18) { if ((offerCounter % 3) == 0) { GenerateNewOffer(); textBox1.Text += "-> You have a new offer "; MessageBox.Show("You received an offer !"); textBox2.Text = newOffer.ToString(); } else { offerRemainder = 3 - (offerCounter % 3); textBox1.Text += "-> Open " + offerRemainder.ToString() + " more box(es) for a new offer"; } } else textBox2.Text = ""; } private void button8_Click(object sender, RoutedEventArgs e) { if (buttonFlag[7]) { return; } buttonFlag[7] = true; if (accept) { return; } textBox2.Text = ""; textBox1.Text = ""; offerCounter++; button8.Content = tempLabel = buttonList[7].ToString(); LostValues(tempLabel); textBox1.Text = "-> You just opened " + tempLabel + "\n"; CallZero(tempLabel); if (offerCounter == 20) { finalValue = GetFinalValue(); MessageBox.Show("Game is over.You won " + finalValue.ToString()); textBox1.Text = "Game is over" + "\n"; textBox1.Text += "You Won: " + finalValue.ToString(); label28.Content = "You Won:"; label29.Content = finalValue.ToString(); textBlock1.Text = "Game Over"; accept = true; } if (offerCounter <= 18) { if ((offerCounter % 3) == 0) { GenerateNewOffer(); textBox1.Text += "-> You have a new offer "; MessageBox.Show("You received an offer !"); textBox2.Text = newOffer.ToString(); } else { offerRemainder = 3 - (offerCounter % 3); textBox1.Text += "-> Open " + offerRemainder.ToString() + " more box(es) for a new offer"; } } else textBox2.Text = ""; } private void button9_Click(object sender, RoutedEventArgs e) { if (buttonFlag[8]) { return; } buttonFlag[8] = true; if (accept) { return; } textBox2.Text = ""; textBox1.Text = ""; offerCounter++; button9.Content = tempLabel = buttonList[8].ToString(); LostValues(tempLabel); textBox1.Text = "-> You just opened " + tempLabel + "\n"; CallZero(tempLabel); if (offerCounter == 20) { finalValue = GetFinalValue(); MessageBox.Show("Game is over.You won " + finalValue.ToString()); textBox1.Text = "Game is over" + "\n"; textBox1.Text += "You Won: " + finalValue.ToString(); label28.Content = "You Won:"; label29.Content = finalValue.ToString(); textBlock1.Text = "Game Over"; accept = true; } if (offerCounter <= 18) { if ((offerCounter % 3) == 0) { GenerateNewOffer(); textBox1.Text += "-> You have a new offer "; MessageBox.Show("You received an offer !"); textBox2.Text = newOffer.ToString(); } else { offerRemainder = 3 - (offerCounter % 3); textBox1.Text += "-> Open " + offerRemainder.ToString() + " more box(es) for a new offer"; } } else textBox2.Text = ""; } private void button10_Click(object sender, RoutedEventArgs e) { if (buttonFlag[9]) { return; } buttonFlag[9] = true; if (accept) { return; } textBox2.Text = ""; textBox1.Text = ""; offerCounter++; button10.Content = tempLabel = buttonList[9].ToString(); LostValues(tempLabel); textBox1.Text = "-> You just opened " + tempLabel + "\n"; CallZero(tempLabel); if (offerCounter == 20) { finalValue = GetFinalValue(); MessageBox.Show("Game is over.You won " + finalValue.ToString()); textBox1.Text = "Game is over" + "\n"; textBox1.Text += "You Won: " + finalValue.ToString(); label28.Content = "You Won:"; label29.Content = finalValue.ToString(); textBlock1.Text = "Game Over"; accept = true; } if (offerCounter <= 18) { if ((offerCounter % 3) == 0) { GenerateNewOffer(); textBox1.Text += "-> You have a new offer "; MessageBox.Show("You received an offer !"); textBox2.Text = newOffer.ToString(); } else { offerRemainder = 3 - (offerCounter % 3); textBox1.Text += "-> Open " + offerRemainder.ToString() + " more box(es) for a new offer"; } } else textBox2.Text = ""; } private void button11_Click(object sender, RoutedEventArgs e) { if (buttonFlag[10]) { return; } buttonFlag[10] = true; if (accept) { return; } textBox2.Text = ""; textBox1.Text = ""; offerCounter++; button11.Content = tempLabel = buttonList[10].ToString(); LostValues(tempLabel); textBox1.Text = "-> You just opened " + tempLabel + "\n"; CallZero(tempLabel); if (offerCounter == 20) { finalValue = GetFinalValue(); MessageBox.Show("Game is over.You won " + finalValue.ToString()); textBox1.Text = "Game is over" + "\n"; textBox1.Text += "You Won: " + finalValue.ToString(); label28.Content = "You Won:"; label29.Content = finalValue.ToString(); accept = true; } if (offerCounter <= 18) { if ((offerCounter % 3) == 0) { GenerateNewOffer(); textBox1.Text += "-> You have a new offer "; MessageBox.Show("You received an offer !"); textBox2.Text = newOffer.ToString(); } else { offerRemainder = 3 - (offerCounter % 3); textBox1.Text += "-> Open " + offerRemainder.ToString() + " more box(es) for a new offer"; } } else textBox2.Text = ""; } private void button12_Click(object sender, RoutedEventArgs e) { if (buttonFlag[11]) { return; } buttonFlag[11] = true; if (accept) { return; } textBox2.Text = ""; textBox1.Text = ""; offerCounter++; button12.Content = tempLabel = buttonList[11].ToString(); LostValues(tempLabel); textBox1.Text = "-> You just opened " + tempLabel + "\n"; CallZero(tempLabel); if (offerCounter == 20) { finalValue = GetFinalValue(); MessageBox.Show("Game is over.You won " + finalValue.ToString()); textBox1.Text = "Game is over" + "\n"; textBox1.Text += "You Won: " + finalValue.ToString(); label28.Content = "You Won:"; label29.Content = finalValue.ToString(); textBlock1.Text = "Game Over"; accept = true; } if (offerCounter <= 18) { if ((offerCounter % 3) == 0) { GenerateNewOffer(); textBox1.Text += "-> You have a new offer "; MessageBox.Show("You received an offer !"); textBox2.Text = newOffer.ToString(); } else { offerRemainder = 3 - (offerCounter % 3); textBox1.Text += "-> Open " + offerRemainder.ToString() + " more box(es) for a new offer"; } } else textBox2.Text = ""; } private void button13_Click(object sender, RoutedEventArgs e) { if (buttonFlag[12]) { return; } buttonFlag[12] = true; if (accept) { return; } textBox2.Text = ""; textBox1.Text = ""; offerCounter++; button13.Content = tempLabel = buttonList[12].ToString(); LostValues(tempLabel); textBox1.Text = "-> You just opened " + tempLabel + "\n"; CallZero(tempLabel); if (offerCounter == 20) { finalValue = GetFinalValue(); MessageBox.Show("Game is over.You won " + finalValue.ToString()); textBox1.Text = "Game is over" + "\n"; textBox1.Text += "You Won: " + finalValue.ToString(); label28.Content = "You Won:"; label29.Content = finalValue.ToString(); textBlock1.Text = "Game Over"; accept = true; } if (offerCounter <= 18) { if ((offerCounter % 3) == 0) { GenerateNewOffer(); textBox1.Text += "-> You have a new offer "; MessageBox.Show("You received an offer !"); textBox2.Text = newOffer.ToString(); } else { offerRemainder = 3 - (offerCounter % 3); textBox1.Text += "-> Open " + offerRemainder.ToString() + " more box(es) for a new offer"; } } else textBox2.Text = ""; } private void button14_Click(object sender, RoutedEventArgs e) { if (buttonFlag[13]) { return; } buttonFlag[13] = true; if (accept) { return; } textBox2.Text = ""; textBox1.Text = ""; offerCounter++; button14.Content = tempLabel = buttonList[13].ToString(); LostValues(tempLabel); textBox1.Text = "-> You just opened " + tempLabel + "\n"; CallZero(tempLabel); if (offerCounter == 20) { finalValue = GetFinalValue(); MessageBox.Show("Game is over.You won " + finalValue.ToString()); textBox1.Text = "Game is over" + "\n"; textBox1.Text += "You Won: " + finalValue.ToString(); label28.Content = "You Won:"; label29.Content = finalValue.ToString(); textBlock1.Text = "Game Over"; accept = true; } if (offerCounter <= 18) { if ((offerCounter % 3) == 0) { GenerateNewOffer(); textBox1.Text += "-> You have a new offer "; MessageBox.Show("You received an offer !"); textBox2.Text = newOffer.ToString(); } else { offerRemainder = 3 - (offerCounter % 3); textBox1.Text += "-> Open " + offerRemainder.ToString() + " more box(es) for a new offer"; } } else textBox2.Text = ""; } private void button15_Click(object sender, RoutedEventArgs e) { if (buttonFlag[14]) { return; } buttonFlag[14] = true; if (accept) { return; } textBox2.Text = ""; textBox1.Text = ""; offerCounter++; button15.Content = tempLabel = buttonList[14].ToString(); LostValues(tempLabel); textBox1.Text = "-> You just opened " + tempLabel + "\n"; CallZero(tempLabel); if (offerCounter == 20) { finalValue = GetFinalValue(); MessageBox.Show("Game is over.You won " + finalValue.ToString()); textBox1.Text = "Game is over" + "\n"; textBox1.Text += "You Won: " + finalValue.ToString(); label28.Content = "You Won:"; label29.Content = finalValue.ToString(); textBlock1.Text = "Game Over"; accept = true; } if (offerCounter <= 18) { if ((offerCounter % 3) == 0) { GenerateNewOffer(); textBox1.Text += "-> You have a new offer "; MessageBox.Show("You received an offer !"); textBox2.Text = newOffer.ToString(); } else { offerRemainder = 3 - (offerCounter % 3); textBox1.Text += "-> Open " + offerRemainder.ToString() + " more box(es) for a new offer"; } } else textBox2.Text = ""; } private void button16_Click(object sender, RoutedEventArgs e) { if (buttonFlag[15]) { return; } buttonFlag[15] = true; if (accept) { return; } textBox2.Text = ""; textBox1.Text = ""; offerCounter++; button16.Content = tempLabel = buttonList[15].ToString(); LostValues(tempLabel); textBox1.Text = "-> You just opened " + tempLabel + "\n"; CallZero(tempLabel); if (offerCounter == 20) { finalValue = GetFinalValue(); MessageBox.Show("Game is over.You won " + finalValue.ToString()); textBox1.Text = "Game is over" + "\n"; textBox1.Text += "You Won: " + finalValue.ToString(); label28.Content = "You Won:"; label29.Content = finalValue.ToString(); textBlock1.Text = "Game Over"; accept = true; } if (offerCounter <= 18) { if ((offerCounter % 3) == 0) { GenerateNewOffer(); textBox1.Text += "-> You have a new offer "; MessageBox.Show("You received an offer !"); textBox2.Text = newOffer.ToString(); } else { offerRemainder = 3 - (offerCounter % 3); textBox1.Text += "-> Open " + offerRemainder.ToString() + " more box(es) for a new offer"; } } else textBox2.Text = ""; } private void button17_Click(object sender, RoutedEventArgs e) { if (buttonFlag[16]) { return; } buttonFlag[16] = true; if (accept) { return; } textBox2.Text = ""; textBox1.Text = ""; offerCounter++; button17.Content = tempLabel = buttonList[16].ToString(); LostValues(tempLabel); textBox1.Text = "-> You just opened " + tempLabel + "\n"; CallZero(tempLabel); if (offerCounter == 20) { finalValue = GetFinalValue(); MessageBox.Show("Game is over.You won " + finalValue.ToString()); textBox1.Text = "Game is over" + "\n"; textBox1.Text += "You Won: " + finalValue.ToString(); label28.Content = "You Won:"; label29.Content = finalValue.ToString(); textBlock1.Text = "Game Over"; accept = true; } if (offerCounter <= 18) { if ((offerCounter % 3) == 0) { GenerateNewOffer(); textBox1.Text += "-> You have a new offer "; MessageBox.Show("You received an offer !"); textBox2.Text = newOffer.ToString(); } else { offerRemainder = 3 - (offerCounter % 3); textBox1.Text += "-> Open " + offerRemainder.ToString() + " more box(es) for a new offer"; } } else textBox2.Text = ""; } private void button18_Click(object sender, RoutedEventArgs e) { if (buttonFlag[17]) { return; } buttonFlag[17] = true; if (accept) { return; } textBox2.Text = ""; textBox1.Text = ""; offerCounter++; button18.Content = tempLabel = buttonList[17].ToString(); LostValues(tempLabel); textBox1.Text = "-> You just opened " + tempLabel + "\n"; CallZero(tempLabel); if (offerCounter == 20) { finalValue = GetFinalValue(); MessageBox.Show("Game is over.You won " + finalValue.ToString()); textBox1.Text = "Game is over" + "\n"; textBox1.Text += "You Won: " + finalValue.ToString(); label28.Content = "You Won:"; label29.Content = finalValue.ToString(); textBlock1.Text = "Game Over"; accept = true; } if (offerCounter <= 18) { if ((offerCounter % 3) == 0) { GenerateNewOffer(); textBox1.Text += "-> You have a new offer "; MessageBox.Show("You received an offer !"); textBox2.Text = newOffer.ToString(); } else { offerRemainder = 3 - (offerCounter % 3); textBox1.Text += "-> Open " + offerRemainder.ToString() + " more box(es) for a new offer"; } } else textBox2.Text = ""; } private void button19_Click(object sender, RoutedEventArgs e) { if (buttonFlag[18]) { return; } buttonFlag[18] = true; if (accept) { return; } textBox2.Text = ""; textBox1.Text = ""; offerCounter++; button19.Content = tempLabel = buttonList[18].ToString(); LostValues(tempLabel); textBox1.Text = "-> You just opened " + tempLabel + "\n"; CallZero(tempLabel); if (offerCounter == 20) { finalValue = GetFinalValue(); MessageBox.Show("Game is over.You won " + finalValue.ToString()); textBox1.Text = "Game is over" + "\n"; textBox1.Text += "You Won: " + finalValue.ToString(); label28.Content = "You Won:"; label29.Content = finalValue.ToString(); textBlock1.Text = "Game Over"; accept = true; } if (offerCounter <= 18) { if ((offerCounter % 3) == 0) { GenerateNewOffer(); textBox1.Text += "-> You have a new offer "; MessageBox.Show("You received an offer !"); textBox2.Text = newOffer.ToString(); } else { offerRemainder = 3 - (offerCounter % 3); textBox1.Text += "-> Open " + offerRemainder.ToString() + " more box(es) for a new offer"; } } else textBox2.Text = ""; } private void button20_Click(object sender, RoutedEventArgs e) { if (buttonFlag[19]) { return; } buttonFlag[19] = true; if (accept) { return; } textBox2.Text = ""; textBox1.Text = ""; offerCounter++; button20.Content = tempLabel = buttonList[19].ToString(); LostValues(tempLabel); textBox1.Text = "-> You just opened " + tempLabel + "\n"; CallZero(tempLabel); if (offerCounter == 20) { finalValue = GetFinalValue(); MessageBox.Show("Game is over.You won " + finalValue.ToString()); textBox1.Text = "Game is over" + "\n"; textBox1.Text += "You Won: " + finalValue.ToString(); label28.Content = "You Won:"; label29.Content = finalValue.ToString(); textBlock1.Text = "Game Over"; accept = true; } if (offerCounter <= 18) { if ((offerCounter % 3) == 0) { GenerateNewOffer(); textBox1.Text += "-> You have a new offer "; MessageBox.Show("You received an offer !"); textBox2.Text = newOffer.ToString(); } else { offerRemainder = 3 - (offerCounter % 3); textBox1.Text += "-> Open " + offerRemainder.ToString() + " more box(es) for a new offer"; } } else textBox2.Text = ""; } private void button21_Click(object sender, RoutedEventArgs e) { if (buttonFlag[20]) { return; } buttonFlag[20] = true; if (accept) { return; } textBox2.Text = ""; textBox1.Text = ""; offerCounter++; button21.Content = tempLabel = buttonList[20].ToString(); LostValues(tempLabel); textBox1.Text = "-> You just opened " + tempLabel + "\n"; CallZero(tempLabel); if (offerCounter == 20) { finalValue = GetFinalValue(); MessageBox.Show("Game is over.You won " + finalValue.ToString()); textBox1.Text = "Game is over" + "\n"; textBox1.Text += "You Won: " + finalValue.ToString(); label28.Content = "You Won:"; label29.Content = finalValue.ToString(); textBlock1.Text = "Game Over"; accept = true; } if (offerCounter <= 18) { if ((offerCounter % 3) == 0) { GenerateNewOffer(); textBox1.Text += "-> You have a new offer "; MessageBox.Show("You received an offer !"); textBox2.Text = newOffer.ToString(); } else { offerRemainder = 3 - (offerCounter % 3); textBox1.Text += "-> Open " + offerRemainder.ToString() + " more box(es) for a new offer"; } } else textBox2.Text = ""; } private void button24_Click(object sender, RoutedEventArgs e) // REJECT { if (accept) { return; } if (textBox2.Text == "") { return; } accept = false; textBox1.Text = "Open new box(es)"; textBox2.Text = ""; } private void button22_Click(object sender, RoutedEventArgs e) // ACCEPT { if (textBox2.Text == "") { return; } accept = true; textBox1.Text = "Game is over"+"\n"; textBox1.Text += "You Won: " + textBox2.Text; label28.Content = "You Won:"; label29.Content = textBox2.Text; textBlock1.Text = "Game Over"; } private void button23_Click(object sender, RoutedEventArgs e)// RESTART { int temp; // Declarations... newOffer = 0; accept = false; offerCounter = 0; offerRemainder=0; tempLabel = ""; textBox1.Text = textBox2.Text = ""; textBlock1.Text = ""; label28.Content = label29.Content = ""; // Initializations... for (int i = 0; i < 21; i++) { buttonFlag[i] = false; } for (int i = 0; i < 21; i++) { tempList[i] = 30; } for (int i = 0; i < 21; i++) { temp = random.Next(21); while (IsUsed(temp)) { temp = random.Next(21); } buttonList[i] = scoreList[temp]; tempList[i] = temp; } //Buttons... button1.Content = "1"; button2.Content = "2"; button3.Content = "3"; button4.Content = "4"; button5.Content = "5"; button6.Content = "6"; button7.Content = "7"; button8.Content = "8"; button9.Content = "9"; button10.Content = "10"; button11.Content = "11"; button12.Content = "12"; button13.Content = "13"; button14.Content = "14"; button15.Content = "15"; button16.Content = "16"; button17.Content = "17"; button18.Content = "18"; button19.Content = "19"; button20.Content = "20"; button21.Content = "21"; //Label contents... label1.Content = "100"; label2.Content = "200"; label3.Content = "300"; label4.Content = "400"; label5.Content = "500"; label6.Content = "800"; label7.Content = "1000"; label8.Content = "5000"; label9.Content = "8000"; label10.Content = "10000"; label11.Content = "15000"; label12.Content = "20000"; label13.Content = "30000"; label14.Content = "50000"; label15.Content = "60000"; label16.Content = "80000"; label17.Content = "100000"; label18.Content = "130000"; label19.Content = "160000"; label20.Content = "180000"; label21.Content = "200000"; } } }
Sos un dios
ReplyDelete