1. Initialize the map. When drawing, you can first initialize the map, use an array to store the location of the level, and then use a loop to assign the value representing the level to the location of the level in the map.
The key code is as follows
/// <summary> /// Initialize the game map/// </summary> static void InitialMap() { for (int i=0;i<;i++) { Map[i] =0; } // Used to store level locationint[] luckyTurn = { 6, 23, 40, 55, 69, 83,98 };//Lucky Turntable 1int[] landMine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };// Landmines 2int[] pause = { 9, 27, 60, 93 };//Pause 3int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90};//Space-time tunnel 4for (int i=0;i<;i++) { int pos = luckyTurn[i]; Map[pos] = 1; } for (int i=0;i<;i++) { Map[landMine[i]] = 2; } for (int i=0;i<;i++) { int pos = pause[i]; Map[pos] = 3; } for(int i=0;i<;i++) { int pos = timeTunnel[i]; Map[pos] =4; } }
2. Check the value of the coordinates. After initializing the map, you can start drawing the map. Map drawing can be used as distributed drawing mentioned in programming. When drawing the map, you should check the value of the coordinate point. When drawing the map, draw the corresponding pattern according to the value of the point. When checking, return the corresponding pattern according to the value, and draw it using a loop. The value code for checking the coordinates is as follows:
/// <summary> /// Get the coordinates to be drawn/// </summary> /// <param name="i"> Coordinates to be drawn</param>/// <returns></returns> static string GetMapString(int i) { string Result="";// Used to return to a corresponding pattern with coordinatesif (playerPos[0] == i && playerPos[1] == i)//Judge whether it is where both sides of the battle{ = ;//Set the foreground color of the pattern to yellowResult = "<>";//Get both of them in the pattern} else if (playerPos[0] == i) { = ; Result = "A";//All gets A in the pattern} else if (playerPos[1] == i) { = ; Result = "B";//Get B in the pattern} else { switch (Map[i]) { case 0: = ; Result = "□";//Get normal patternbreak; case 1: = ; Result = "○";//Get the turntable patternbreak; case 2: = ; Result = "☆"; break; case 3: = ; Result = "▲"; break; case 4: = ; Result = "swastika"; break; } } return Result; //Return to the pattern}
3. Draw the map. After obtaining the returned pattern, you can draw the map. Here is the code for drawing the first line.
/// <summary> /// Draw a game map/// </summary> static void DrownMap() { ("Legend: Lucky Turntable ○ Landmine ☆ Pause ▲ Time and Space Tunnel swastika"); //Draw the first line and subscribe to the map 0-29for(int i=0;i<30;i++)//Cycling the coordinates to get the pattern of each point in the first row{ (GetMapString(i)); //Calling the function to get the pattern of each coordinate} ("\n"); ();//Reset the foreground color}
The above is the C# flying chess map mini program introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!