[C #] 24-point game implementation (archiving and LAN interconnection)

Source: Internet
Author: User

(For updates, see the source code of this game! Http://download.csdn.net/detail/gshengod/5774531)

LZ has been admitted to beiyou as a graduate student. after entering the lab, LZ received a tricky task and was asked to write a 24-point game, which must be archived and interconnected over a LAN. This is a great challenge for cainiao who just started learning programming. Now, let's get to the point where you can ignore it. You can watch it, and I will share my learning history.

First, we use vs2008 to design the interface, create a form class window, and open the toolbox. In this way, we can drag some buttons to it. Then, you can add some images to the background image to make the program look better. For example.

The following is a complicated part of the code.

Level1 is a 24-point operation that enables automatic machine computing. Using the random function, we can implement four random numbers. What we need to do is to add them with parentheses or the buttons for addition, subtraction, multiplication, and division, and set the result to 24. This is mainly the traversal idea, because we can divide the formula into two types, one is (A * B) + C + D) but in the bracket form. One is in the form of two parentheses (a + B) * (c-d.

For details about the calculation method, see the randomnew. CS class in the code. Levle1


Level2 requires us to input an expression when we know four numbers to see if it is 24. this is because the computer does not read the symbols in the string, so we need to use the regular method to separate the number from the arithmetic operator, because the priority of the parentheses multiplication, division, addition, and Subtraction is different, therefore, we need to separate them into the stack based on different priorities for calculation. For more information, see algorithm. CS in my code. For more information, see http://download.csdn.net/detail/gshengod/5711611. Knowledge about the data stream used for archiving and reading files

Filestreamfs = newfilestream ("d :\\ workplace \ save.txt", filemode. Create, fileaccess. Write );
Streamwriter Sw = new streamwriter (FS, system. Text. encoding. getencoding ("gb2312 "));. There is also the timer control, the main code for countdown

Int time = int. parse (ARR [1]);
Lefttime = time;
This. timer1.start ();

This. label7.text = "Remaining Time" + lefttime. tostring ();
Lefttime --;
If (lefttime = 0)
{
Randomnew b1 = new randomnew ();
String answer = b1.compute (label2.text, label3.text, label4.text, label5.text );
MessageBox. Show ("time out, the correct answer is" + answer );

The level2 image is as follows:


Level3 is about lan interconnection, mainly for socket programming applications. You can download this for reference. This code is well written at http://download.csdn.net/detail/gshengod/5721367.

Well, that's all. I am still modifying some bugs. I will share the full version of the Code in two days.



PS: If you have any questions, please leave a message to discuss them !!!






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.