202: LOTTO

Create a Simple Lotto Game

1. Come to class as there may be corrections, changes and additions.   Significant late penalty per day.
2. Follow these directions to create a C# Windows program.  
3. Follow these directions to SUBMIT a zipped folder called "LOTTO"

1.program 2.program

3.program 4.program


INTERFACE & OPERATION: ======================= Make Form1 title bar = the number to match! Fields: Random rnd = new Random( ); // to avoid repeats when seeding from clock int numberToMatch; int winnings; Any variables that need to be shared (scope) or that need to maintain their value (lifetime) Reset Button(ESC) to generate a random number to be matched Call method to get "numberToMatch" - show number in Text property of form - store number in class level variable called "numberToMatch" Make "Play" button operational - enabled = true Clear - listBox - output label Play Button(ENTER) to generate 12 random numbers using a LOOP Loop 12 times Call method to get number if number matches "numberToMatch" count it as a winner play a sound: SystemSounds.Asterisk.Play(); // needs using System.Media; add number to ListBox: lstOut.Items.Add( ) WITH *** refresh list: lstOut.Refresh() pause 1 second between numbers: System.Threading.Thread.Sleep(1000); // 1000 milliseconds add 1 to count of matches else add number to a ListBox: lstOut.Items.Add( ) refresh list: lstOut.Refresh() pause 1 second between numbers: System.Threading.Thread.Sleep(1000); // 1000 milliseconds Report number of matches/ $ winnings ListBox main output RadioButtons(3) determine range of numbers 1-15 - make this the default (checked property is true in designer) 1-25 1-50 Label shows: $ Money won $15 per win, 1-15 $25 per win, 1-25 $50 per win, 1-50 Method: GetNumberInRange() See which radio button is selected (smallest set as default) - set "winnings" based on radio button (class-level variable called "winnings") - determine high boundary of random number selection(15+1 or 25+1 or 50+1) and choose random number = rnd.Next(1, x+1); // numbers 1 - x - return number NOTE: A method is a named group of statements that are executed only when called. A method performs a specific task. Example: A method to return a random number between 1-100 when it is called: int GetNum100() { Random rnd = new Random(); int num = rnd(1, 101); return num; }

CODE ===== 1. Interface: a. name the objects well (btn, txt, lbl, pic, rad, chk etc...) b. make interface clear (organize, label, size, color, placement) use groupboxes to organize related elements c. Escape = New Problem, Enter = Check Answer 2. Code: Readability / Naming (see guidelines) a. Main form (top): Name, Class, Date and Purpose b. EVERY Event Procedure one line (min) explaining what it does at TOP c. Good variable and object names d. Indenting, spacing e. Remove empty methods Make a sound: SystemSounds.Asterisk.Play(); // needs using System.Media; Pause 1 Second: System.Threading.Thread.Sleep(1000); // pause n milliseconds