using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; namespace Final public partial class Game : Form //holds class level variables string OddEven ; String choose ; String contnum; String color; int amountbet = 0; string numpick; String Color1 = null; const int big=35; public Game() InitializeComponent(); Main Game Code //this is in the file drop down and takes you to the main page private void maintoolstripmenuitem_click(object sender, EventArgs e) Main newform = new Main(); newform.show(); this.hide(); //this is in the file drop down and exits the application private void exittoolstripmenuitem_click(object sender, EventArgs e) Application.Exit(); //this is the site i got the hide show from: http://stackoverflow.com/questions/1513887/ //this is the timer object on the form, private void t_tick(object sender, EventArgs e) //creates a method timer called t MethodTimer t = (MethodTimer)sender; //calls to functions t.stop(); t.method.invoke(); //ok honestly im not sure, if i guess its a class ment for this page called methodtimer that //either uses the timer or set to timer..
internal class MethodTimer : Timer //MethodInvoker provides a simple delegate that is used to invoke a method with a void parameter list. //This delegate can be used when making calls to a control's Invoke method, or when you need a simple delegate but do not want to define one yourself. public readonly MethodInvoker Method; public MethodTimer(MethodInvoker method) Method = method; public void user(int amountbet) // checks if the user entery can be parsed to an int try amountbet = int.parse(txtbet.text); lblshowbet.text = amountbet.tostring(); lblshowbet.visible = true; lbldiswin.visible = true; pctstop.visible = false; pctplay.visible = true; timer(); catch MessageBox.Show("Enter a Valid Number"); txtbet.backcolor = Color.Yellow; lblshowbet.visible = false; lbldiswin.visible = false; pctstop.visible = true; pctplay.visible = false; //sets the timer for the animation public void timer() hide //this is the code where the spin button is pressed and the animation runs for 5 seconds MethodTimer hide = new MethodTimer(hideAction);//calls the hide action which turns animation off stores in MethodTimer show = new MethodTimer(showAction);//turns on the animation stores is show MethodTimer showlbl = new MethodTimer(showAction);// hide.interval = 5000; show.interval = 1; lblshowbet.visible = true; hide.tick += new EventHandler(t_Tick);//use the windows timer for tick counter adds to it show.tick += new EventHandler(t_Tick);//uses the windows timer for tick counter adds to it hide.start(); show.start();
//handles the button spin event private void btnspin_click(object sender, EventArgs e) int winnum = 0; //creates random number for the winning number and displays it Random rnd = new Random(); winnum = rnd.next(1, 10); // creates a number between 1 and 10 //stores the winning number in var winnum //parse the total money and stores it in variable total int total = int.parse(lbltotal.text); //tryparse the amount bet and puts it int variable amountbet int.tryparse(txtbet.text, out amountbet); if (txtbet.text == null) MessageBox.Show("Please Bet your amount"); else if (txtbet.text!= null) lbldiswin.text = ("The Winning Number Is: ") + winnum.tostring(); // creates 2 numbers and assigns it case of red or black and changes //the color of the winning number text int wincolor = rnd.next(0, 2); Color1 = wincolor.tostring(); switch (Color1) case "0": lbldiswin.forecolor = Color.Red; choose = "Red"; case "1": lbldiswin.forecolor = Color.Black; choose = "Black"; //displays what the user chooses for the group boxes stores //the color red or black into color var if (radblack.checked) color = "Black"; else if (radred.checked) color = "Red";
//displays what the user chooses for the group boxes stores //the odd or even into contnum var if (radodd.checked) contnum = "Odd"; else if (radeven.checked) contnum = "Even"; // takes the win number and sees if its odd or even int workdamit; workdamit = winnum % 2; if (workdamit == 1) OddEven = "Odd"; else if (workdamit == 0) OddEven = "Even"; //makes sure your not betting more than you have if (total < amountbet) MessageBox.Show("You can't bet more then you have"); txtbet.text = ""; //tests if the betting properties are decided if (numpick == null && color == null && contnum == null) MessageBox.Show("place your bet"); lbltest.visible = false; clear(); else //checks if the number is picked out of list box, then check if it matches winning number while //the other conditions are null if (numpick!= null && color == null && contnum == null) if (int.parse(numpick) == winnum) total = total + (amountbet * big); lbltest.text = ("you win") + (amountbet * big); else if (int.parse(numpick)!= winnum) total = total - amountbet; lbltest.text = ("you lose ") + amountbet;
winner //checks that the list number is blank and the color is chosen, and oddeven is blank then checks if its a if (numpick == null && choose!= null && contnum == null) if (color == choose) total = total + (amountbet + amountbet); lbltest.text = ("you win ") + (amountbet + amountbet); else if (color!= choose) total = total - amountbet; lbltest.text = ("you Lose ") + amountbet; //checks that the odd even is picked and the others empty if (numpick == null && color == null && contnum!= null) if (contnum == OddEven) total = total + (amountbet + amountbet); lbltest.text = ("you win ") + (amountbet + amountbet); else if (contnum!= OddEven) total = total - amountbet; lbltest.text = ("you Lose ") + amountbet;
//test 2 conditions are true, the number and the color if (numpick!= null && color!= null && contnum == null) if (int.parse(numpick) == winnum && color == choose) total = total + ((amountbet * big) + (amountbet * 2)); lbltest.text = ("you win ") + ((amountbet *big) + (amountbet * 2)); else if (int.parse(numpick)!= winnum color!= choose) total = total - (amountbet * 2); lbltest.text = ("you Lose ") + (amountbet * 2); //test 2 conditions are true, the number and the type if (numpick!= null && color == null && contnum!= null) if (int.parse(numpick) == winnum && contnum == OddEven) total = total + ((amountbet * big) + (amountbet * 2)); lbltest.text = ("you win ") + ((amountbet * big) + (amountbet * 2)); else if (int.parse(numpick)!= winnum contnum!= OddEven) total = total - amountbet; lbltest.text = ("you Lose ") + (amountbet * 2); //test 2 conditions are true, the color and the type if (numpick == null && color!= null && contnum!= null) if (color == choose && contnum == OddEven)
total = total + ((amountbet * 2) + (amountbet * 2)); lbltest.text = ("you win ") + (amountbet * 4); else if (color!= choose contnum!= OddEven) total = total - amountbet; lbltest.text = ("you lose ") + (amountbet * 2); //checks all conditions are picked if (numpick!= null && color!= null && contnum!= null) if (int.parse(numpick) == winnum && color == choose && contnum == OddEven) total = total + ((amountbet * 4) + (amountbet * 35)); lbltest.text = ("you win ") + ((amountbet * 4) + (amountbet * 35)); else if (int.parse(numpick)!= winnum color!= choose contnum == OddEven) total = total - (amountbet * 4); lbltest.text = ("you lose ") + (amountbet * 4); // calls the functions user and clear if (pctstop.visible == true) user(amountbet); clear(); //function to hide aniamtion
private void hideaction() pctplay.visible = false; pctstop.visible = true; //function to start aniamtion private void showaction() pctplay.visible = true; pctstop.visible = false; // this group shows pictures if buttons are changed private void radred_checkedchanged(object sender, EventArgs e) pctred.visible = true; pctblsck.visible = false; private void radblack_checkedchanged(object sender, EventArgs e) pctblsck.visible = true; pctred.visible = false; private void radodd_checkedchanged(object sender, EventArgs e) pctodd.visible = true; pcteven.visible = false; private void radeven_checkedchanged(object sender, EventArgs e) pctodd.visible = false; pcteven.visible = true; //shows what your bet is on the table based on the number selected private void lstpicknum_selectedindexchanged(object sender, EventArgs e) if (lstpicknum.selectedindex!= -1) numpick = lstpicknum.selecteditem.tostring(); switch (numpick) case "1": pct1.visible = true;
case "2": pct2.visible = true; case "3": pct3.visible = true; case "4": pct4.visible = true; case "5": pct5.visible = true; case "6":
pct6.visible = true; case "7": pct7.visible = true; case "8": pct8.visible = true; case "9": pct9.visible = true; case "10":
pct10.visible = true; //clears all feilds public void clear() contnum = null; choose = null; color = null; radeven.checked = false; radodd.checked = false; radred.checked = false; radblack.checked = false; txtbet.text = ""; numpick = null; pctblsck.visible = false; pctred.visible = false; pctodd.visible = false; pcteven.visible = false; lstpicknum.selectedindex = -1; //creates a file and saves the text in total into a document private void btnsave_click(object sender, EventArgs e) StreamWriter Saved; Saved = File.CreateText("Saved_Game.txt"); Saved.WriteLine(lbltotal.Text); Saved.Close(); //exits the application private void btnexit_click(object sender, EventArgs e) Application.Exit(); //reads the file Saved_Game and displays the total that was saved private void btnload_click(object sender, EventArgs e) string line; int counter = 0; // Read the file and display it line by line. StreamReader file = new StreamReader("Saved_Game.txt");
while ((line = file.readline())!= null) lbltotal.text=(line); counter++; file.close(); //takes you to the rules page private void rulestoolstripmenuitem_click(object sender, EventArgs e) Rules newform = new Rules(); newform.show(); this.hide();