C # map of CAPTCHA,

Source: Internet
Author: User

C # map of CAPTCHA,

 

1. initialize the map. During the painting, you can initialize the map, store the position of the Level Using arrays, and then use loops to assign the value representing the level to the position of the level in the map.

The key code is as follows:

1 /// <summary> 2 /// initialize game map 3 /// </summary> 4 static void InitialMap () 5 {6 for (int I = 0; I <Map. length; I ++) 7 {8 Map [I] = 0; 9} 10 // used to store the level position 11 int [] luckyTurn = {6, 23, 40, 55, 69, 112}; // lucky turntable int [] landMine = {5, 13, 17, 33, 38, 50, 64, 80, 94 }; // mine 213 int [] pause = {9, 27, 60, 93}; // pause 314 int [] timeTunnel = {20, 25, 45, 63, 72, 88, 90}; // time-space tunnel 415 for (int I = 0; I <luckyTurn. length; I ++) 16 {17 int pos = luckyTurn [I]; 18 Map [pos] = 1; 19} 20 for (int I = 0; I <landMine. length; I ++) 21 {22 Map [landMine [I] = 2; 23} 24 for (int I = 0; I <pause. length; I ++) 25 {26 int pos = pause [I]; 27 Map [pos] = 3; 28} 29 for (int I = 0; I <timeTunnel. length; I ++) 30 {31 int pos = timeTunnel [I]; 32 Map [pos] = 4; 33} 34}View Code

2. Check the coordinate value. After initializing the map, you can start to draw the map. The map can be drawn using the distribution mentioned during programming, when drawing a map, we should check the coordinate point value, draw the corresponding pattern based on the value of the point, return the corresponding pattern based on the value during the check, and draw the pattern in cycles, the code for checking the coordinates is as follows:

1 // <summary> 2 // obtain the coordinates to be drawn 3 // </summary> 4 // <param name = "I"> the coordinates to be drawn </param> 5 // <returns> </returns> 6 static string GetMapString (int I) 7 {8 string Result = ""; // return the pattern 9 for a coordinate. if (playerPos [0] = I & playerPos [1] = I) // determine whether the two sides are in the Console 10 {11. foregroundColor = ConsoleColor. yellow; // set the foreground color of the pattern to Yellow 12 Result = "<>"; // get both sides in the pattern 13} 14 else if (playerPos [0] = I) 15 {16 Console. foregroundColor = ConsoleColor. yellow; 17 Result = "A"; // get A in pattern 18 19} 20 else if (playerPos [1] = I) 21 {22 Console. foregroundColor = ConsoleColor. yellow; 23 Result = "B"; // get B in pattern 24 25} 26 else27 {28 switch (Map [I]) 29 {30 case 0: 31 Console. foregroundColor = ConsoleColor. white; 32 Result = "□"; // The Result is displayed in the pattern 33 34 break; 35 case Console. foregroundColor = ConsoleColor. red; 37 Result = "○"; // turntable pattern 38 39 break; 40 case 2: 41 Console. foregroundColor = ConsoleColor. blue; 42 Result = "☆"; 43 break; 44 case :45 Console. foregroundColor = ConsoleColor. green; 46 Result = "▲"; 47 break; 48 case 4: 49 Console. foregroundColor = ConsoleColor. darkBlue; 50 Result = "success"; 51 break; 52} 53} 54 return Result; // return Pattern 55}

3. Draw a map. After obtaining the returned pattern, you can draw the map. The first line of code is shown here.

1 /// <summary> 2 // draw game map 3 /// </summary> 4 static void DrownMap () 5 {6 Console. writeLine ("Legend: Lucky turntable ○ mine ☆pause ▲spatiotemporal tunnel success"); 7 // draw the map 8 for (int I = 0; I <30; I ++) // obtain the pattern 9 {10 Console for each vertex in the first line by the cyclic coordinates. write (GetMapString (I); // call the function to obtain the pattern for each coordinate. 11} 12 Console. write ("\ n"); 13 Console. resetColor (); // reset the foreground color 14}View Code

Learning self-propagation intelligence podcast tutorial

--- Pole

Related Article

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.