How to realize Cavaliers' Flying Chess in C #
This article shows you how to achieve Cavalier Flying Chess, the content is concise and easy to understand, it can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Flying Chess Mini Game is the first game project I have come into contact with since I learned C #. According to the guidance of Xiao Yang, my own code has also realized the function. After combing through the train of thought, I try to achieve the function by myself without the help of the code. The feeling is that no matter how clear I think, the practice is completely different. Therefore, we have to practice more to cultivate rigorous logical thinking. Let's take a look at the ideas I sort out.
In-game interface
The flow of Flying Chess
Dice rolling process
Game operation flow
Roll the dice code
Public static void RowShaiZi (int xy) {Random r = new Random (); / / Random number int num = r.Next (1,7); string str = ""; Console.WriteLine ("{0} press any key to start rolling dice", PlayerNames [xy]); Console.ReadKey (true); / / do not show input, start rolling dice Console.WriteLine ("{0} rolled {1}", PlayerNames [xy], num); Console.WriteLine ("{0} press any key to start action …" , PlayerNames [xy]); Console.ReadKey (true); PlayerPos [xy] + = num;// player coordinates accumulate CheckPos (); / / check whether player coordinates are out of range if (PlayerPos [xy] = = PlayerPos [1-xy]) / / pass in player 0Lo 1-0 is player 1 Player 1-0 is player 0 {str = string.Format ("player {0} stepped on player {1}, player {2} 6 squares", PlayerNames [xy], PlayerNames [1-xy], PlayerNames [1-xy]); PlayerPos [1-xy]-= 6; CheckPos ();} else {switch (map [PlayerPosxy]) {case 0: str = "Action over" break; Case 1: str = string.Format ("{0} walked to the lucky roulette, please choose 1 int temp-exchange position, 2 Muhammad-bomb each other", PlayerNames [xy]); int number = ReadInt (str, 1, 2); / / call the method if (number = = 1) to determine the input number in the lucky roulette; enter 1 {int temp = xy; temp = PlayerPos [xy]; PlayerPos [xy] = PlayerPos [1-xy]; PlayerPos [1-xy] = temp Str = string.Format ("player {0} chose to exchange positions with player {1}", PlayerNames [xy], PlayerNames [1-xy]); Console.WriteLine (str);} else// wheel enter 2 {PlayerPos [1-xy] = 0; str = string.Format ("player {0} chose bombing player {1}", PlayerNames [xy], PlayerNames [1-xy]); Console.WriteLine (str);} break Case 2: str = "Congratulations, stepped on a landmine, back 6 squares"; PlayerPos [xy]-= 6; CheckPos (); Console.WriteLine (str); break; case 3: str = "stepped on a pause"; Console.WriteLine (str); flag [xy] = true; break; case 4: str = "Congratulations, lucky turntable let you move forward 10 squares"; Console.WriteLine (str); PlayerPos [xy] + = 10; CheckPos (); break;}} Console.ReadKey (); Console.Clear () DrawMap ()
Run the game code
Static void Main (string [] args) {ShowUI (); / / Game header IntMap (); / / initialize the map do// enter player A name {Console.WriteLine ("Please enter player A name"); PlayerNames [0] = Console.ReadLine (); if (PlayerNames [0] = ") {Console.Write (" player A name cannot be empty ");} while (PlayerNames [0] =") Do// enter player B name {Console.WriteLine ("Please enter player B name"); PlayerNames [1] = Console.ReadLine (); if (PlayerNames [1] = "") {Console.Write ("player B name cannot be empty,");} if (PlayerNames [0] = = PlayerNames [1]) {Console.Write ("player B name cannot be the same as player A name,") }} while (PlayerNames [1] = "" | | PlayerNames [0] = = PlayerNames [1]); Console.Clear (); ShowUI (); / / Game head DrawMap (); / / Map Console.ReadKey (); Console.WriteLine ("War begins …") ; Console.WriteLine ("{0} soldiers are represented by A", PlayerNames [0]); Console.WriteLine ("{0} soldiers are represented by B", PlayerNames [1]); while (PlayerPos [0])