C # Course Design---guessing games

Source: Internet
Author: User

1: Game Requirements

1. Randomly display a name with several photos (such as 3 photos), select the correct photo.

2. Record the teacher's awareness of each student's probability p, and according to the probability of cognition, determine the frequency of the "guess" game in the middle school students.

Recognition probability P = exact number of recognition/(exact number of recognition + number of errors identified)

A) Principle 1: Students with high probability of cognition are relatively low in guessing the game.

b) Principle 2: Students with low awareness of the probability of guessing the game appear relatively high frequency.

c) Principle 3: Students who recognize probability 100% also have the possibility of appearing.

D) Principle 4: Students who recognize probability 0% do not have to appear every time.
Please design an algorithm to implement the above principles.

3. To achieve the function of attendance in the classroom, can according to the photo and the name of some students to take attendance (set a proportion, such as attendance 30%,50%, etc.); Setup can design an algorithm similar to target 3, which is random, while each student's attendance frequency varies (based on previous attendance experience).

2. Design Description:

This system for guessing the game and attendance system

This system was created with the Windows Forms interface design.

System features include:

1. Randomly draw 3 numbers from the set student number and randomly display the photos of the three students.

2. Select the selected student's information in the set text file.

2. Record the information of each guessing and the named information of each school number.

3, the current is the number of points to be guessed and be the point of information, as well as all the students are guessed and be point information.

4, each classmate up to three times, when the number of points more than 3 o'clock, display warning window, prompting the user

Re-name.

5. The total number of guesses or errors exceeds 10, the display window information, the game automatically end.

3. Detailed system design--control selection:

1, ListBox1: Used to store and display all the students were point information.

2, Button1: Is the start call button, used to control the random number, when the click the Start button, it will become a stop button, press the Stop button, display the final selected number and display the selected student photo.

3, Button2: is used to show the current is the point of the points of the students.

4, Button3: Is the reset button, used to clear the ListBox1 data information.

5, Button4: is to show ListBox1 in the records of all the students were point of the situation.

6, Timer1: Used to control the extraction process data in the blank place flashing.

7, Label1: Used to display the selected number and student information.

8, Label2: Used to display the total number of guesses.

9, Label3: Used to display the total number of guesses.

10, Label4: Used to show the game name "Guess."

11, Label5: Used to display the number, the total number of individual points, the total number of individuals guessed, the total number of individual guesses.

12, PictureBox1: Used to display the Arry1[i] array of pictures.

13, PictureBox2: Used to display the Arry2[i] array of pictures.

14, PictureBox3: Used to display the Arry3[i] array of pictures.

15, ImageList1: Used to store and display photos

4, the system detailed design-code implementation:

1.timer1 Event: Control the random selection of the number, for each of the array of photos stored in a random number, and in the selected number is randomly selected a number, as the guessed number, while in the created file, the corresponding reading number corresponds to the information of the school number.

private void Timer1_Tick (object sender, EventArgs e) {long Tick = DateTime.Now.Ticks; Random ran = new random ((int) (tick & 0xffffffffL) | (int)            (tick >> 32)); for (int i = 0; i < Arry1. Length && i < Arry2. Length && i < Arry3. Length; i++) {Arry1[i] = ran.                Next (0, imagelist1.images.count-1); Arry2[i] = ran.                Next (0, imagelist1.images.count-1); Arry3[i] = ran.                Next (0, imagelist1.images.count-1);                int[] ary = new Int[3] {arry1[i], arry2[i], arry3[i]};                d = R.next (0, 2);                x = Ary[d]; num = Ary[d].               ToString ();                p = (double) c1[x]/(C1[x] + c2[x]); String[] line = File.ReadAllLines (@ "C:\users\administrator\desktop\c#\a.txt", Unicodeencoding.getencoding ("GB2312"                )); Label1. Text = "number" + ary[d].            ToString () + "," + "Student Information" + line[ary[d]; }        }

2.button1 event: Start to guess the button to control the operation of the timer1, three images of the display and listBox1 inside the information and alert warning

private void Button1_Click (object sender, EventArgs e) {int[] ary = new Int[3] {arry1[i], arry2[i],            Arry3[i]};            d = R.next (0, 3);            First_click =!first_click; if (!first_click) {timer1.                Start (); Button1.            Text = "Stop"; } else {timer1.                Stop (); Button1.                Text = "Start";                New System.Drawing.Size (30, 30);                pictureBox1.Image = Imagelist1.images[arry1[i]];                Picturebox2.image = Imagelist1.images[arry2[i]];                Picturebox3.image = Imagelist1.images[arry3[i]];                             c[x]++;                        if (C[x] > 3) {MessageBox.Show ("Warning: The classmate has been named more than three times, please re-name"); Timer1.                        Start (); Button1.                Text = "Stop"; } this.listBox1.Items.Add (num + "" + c[x]+ "" +count+ "" +count1); }        }

3.picturebox1 event: A click on the picture event, determine whether the picture and student information is relative, and calculate the total number of guesses or wrong guesses and the total number of guesses or mistakes and tips guessed right or wrong and the game ended or passed. (And so on PictureBox2 event, PictureBox3 event)

 private void PictureBox1_Click (object sender, EventArgs e) {int[] ary = new Int[3] {arry1[i], arry2[i            ], Arry3[i]};            d = R.next (0, 2);                    if (arry1[i] = = x) {MessageBox.Show ("master, Congratulations, correct");                    count++;                    c1[x]++; Label2.                    Text = "Guess the total number of times" + count;                     THIS.LISTBOX1.ITEMS.ADD (num + "+ c[x] +" "+ c1[x] +" "+ c2[x]);                                            while (count==10) {MessageBox.Show ("Master, congratulations on your passing the game"); }} else {Messagebo                    X.show ("Master, wrong Oh, keep trying");                    count1++;                    c2[x]++; Label3.                    Text = "Total number of guesses" + count1;                    THIS.LISTBOX1.ITEMS.ADD (num + "+ c[x] +" "+ c1[x] +" "+ c2[x]); while (count1 = = {MessageBox.Show ("Master, unfortunately, you did not pass the game"); }                                   }        }

4.button2 event: Used as "show this student information" shows the current classmate is a bit of information, used as the attendance function

private void Button2_Click (object sender, EventArgs e)        {            if (c[x] = = 3)            {                MessageBox.Show ("the classmate was named the third time") ;            }             if (c[x] = = 2)            {                MessageBox.Show ("the classmate was named the second time");            }          if (c[x] = = 1)            {                MessageBox.Show ("the classmate was named for the first Time");}                  }

5. Button3 Event: Use as reset button to clear the information recorded in ListBox1

private void Button3_Click (object sender, EventArgs e)        {            this.listBox1.Items.Clear ();            Result. Clear ();        }

6. Button4 event: Used as the "show all guessed and used information" button to show all the students are currently guessing and being points of specific information

private void Button4_Click (object sender, EventArgs e)        {            this.listBox1.Visible =!this.listbox1.visible;            this.button3.Visible =!this.button3.visible;        }

5. System implementation

1. Click Start to Run




2. Click the Start Call button and the Start Call button becomes the stop button:


3. Click the Stop button: Display the currently randomly selected three photos and student information


4, click on the picture, Jochi, pop-up window display


5, click on the picture, if the wrong guess, pop-up window display



6. If the number of random name extraction exceeds three times, pop-up window warning.

7. If you guess the picture is wrong 10 times, pop-up window display, guess the picture failed


8. If the picture guessed 10 times, pop-up window display, guess the picture success


9. Click the button "the classmate is information", the pop-up window shows the information that the classmate was ordered.


10. Click the "all guessed and scored" and "Reset" buttons respectively, all the information that all students are named in the list box is displayed, and the reset button clears the contents of the list box.



11. Student information in the text




6, Summary:

        Make this game intermittently spent a lot of time, about half a month, of course, this is interspersed with a lot of assorted things, from a long time ago began to do, but for C # still too unfamiliar, and this semester I did not spend enough time to learn about, So at the beginning of the design, the head blank, a little clue is not, only from the contents of the previous work to find some inspiration. At first I took a lot of time in the way of selecting pictures, because the PictureBox contact is not very much, it has not been able to fully use, this gave me a lot of trouble at the beginning, stuck here, the mind is particularly irritable, the Internet search data are dazed, like a blind head flies, do not know, Later put it on hold a few days later, then the heart also calmed a lot, the head also began slowly into the subject, began to seriously think about the problem. Since I read the picture using the file stream function, read the picture from the established path, but I found that I can not display the student information in the picture, so I will change the name of the picture to the natural number, the student information inside the extracted into a TXT file, with the Lable label control display, But then another problem, I can not ensure that the picture and lable tag content only a pair of corresponding, so this problem again troubled me a day, and then asked the roommate, after her hint, the selected three picture number into an array, in this array and then random function randomly selected a, can guarantee the picture and the student information one by one correspondence; but I found that the picture number changed to the natural serial number and the student information have no common ground, so it can't even get up; After some thinking, I think of the database, my idea is to put student information and picture number into the database, read from the database can have a common link , so I took the way to read the photo from the file stream to read from the database, but the problem quickly appeared, because I am completely unfamiliar with the operation of the linked database, although the previous job has tried to connect, but at that time because the computer software problem has not been connected, and then has been shelved this operation, after trying a night, I gave up the idea of using the database. The question seems to be back to the beginning of the time, the photo exactly how to introduce and label information synchronization, because no idea, I began to search all kinds of information on the Internet, and then I found a way to use the ImageList, it used to store photos using an array method, so I can share this array, The introduction of each PictureBox inside, after many tests, changes, and finally the photo coding and label synchronization show out, then the mood is really excited to the extreme, finally completed the first step, sure enough is the beginning of everything is difficult ah, the introduction of other things can be gradual, so I started to click on the picture event, When I first wrote this part, I wasn't really thinking about it, because I was thinking that when I clicked on the picture and the tag information, the photo would bounce.Or flip, the result of drilling niu Jiao Jian, has struggled how to let the photo after the click can be moved, later after the program, debugging only know, as long as the number of photos and label information has one by one corresponding relationship, it can happen, so I wrote in each PictureBox event three the same program, As long as the conditional statements in the IF statement and each PictureBox corresponding to the statement on the line, and then in the IF statement corresponding to the addition of the MessageBox, guess right/Wrong total number of statements, after continuous modification, add attendance function and other steps, Finally completed the take shape of the guessing game, although there are still some imperfect features, but I am quite satisfied, from the ignorant, to their own to make a small game, in the process of harvesting the knowledge is very much, it is like a accumulation of wealth, 1.1 points of accumulation, the last possession must be others can not give, Practice is the truth, in fact I can do it.

The address of my Baidu network disk: Http://pan.baidu.com/s/1kTszg7H












Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

C # Course Design---guessing games

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.