Chess Game (implemented in C language)

Source: Internet
Author: User

This is an interesting interview question, so it took several hours to complete it.

Question:

Apply any language you are most familiar with. The design is as follows:Program

Draw a 8x8 checkerboard on the screen (the width of the entire checkerboard is 100 meters). There are 64 grids in total, and 64 pieces are generated. Assume the number is 1, 2, 3, until 64, each piece is written with its own number. You can enter three commands:

1. layout: enter a number less than 65 and greater than 10. For the description, we use N instead (for example, n = 15 ), then you randomly select n pieces from 64 pieces, randomly decide their positions on the board, and display them on the screen.

2. take a pawn: enter a number less than 65 and greater than 0. This number represents the pawn you want, for example, I. There are two cases, one case is that I represents the piece in the Board, and the other case is not in the board.

3. throwing a pawn: This command moves the selected pawn from a certain height to the acceleration of gravity, the height is determined by the number selected, and the formula is

Height = I * (I-1): Here I is the number of the pawn, the height unit is meters

The falling speed of a piece at this height is 0, and we have a level of wind blowing, we define three kinds of wind speed: 0.1 meters per second, 0.5 meters per second, 1 meter per second. When using this command, you can select a specific wind speed, and define four wind directions for the user to choose.

If you touch the chessboard, the falling chess piece will hit 0 to 4 chess pieces, and the chess piece you encounter will be removed. At the same time, you will replace one of the chess pieces on the chessboard.

The goal of this boring game is to allow users to remove all the pawns on the board.

 

Note: You can use JavaScript + HTML pages or C/C ++, C #, Java, Perl, and Lua, but you must be able to run the program. Do not force you to finish the game completely, but your degree of implementation and specific encoding will affect your performance.

In addition to using programs to implement this little game, if you are interested, describe how to make the game more attractive with this basic idea.

 

CodeImplementation:

/Files/henrylgz/work.rar

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.