Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement simple Flying Chess Mini Game with C #

Shulou Source: shulou.com Published: 2022-06-02 11:50:27 09月30日 Update

This article mainly introduces how to achieve a simple flying chess Mini Game with C#. It has a certain reference value. Interested friends can refer to it. I hope you can learn a lot after reading this article. Let the editor take you to know it.

The details are as follows

1. Input of player's name

two。 Clear the screen

3. Initialize the map

4. Player An and player B play games.

Using System;namespace homework {class data {/ / static field to simulate the global variable static int [] Maps = new int [100]; / / declare a static array to store the coordinates of player An and player B static int [] PlayerPos = new int [2]; static string [] PlayerNames = new string [2] / / two players' tags static bool [] Flags = new bool [2]; / / flags [0] defaults to false public static void Main (String [] args) {GameShow (); / / input of player name # region Console.WriteLine ("Please enter player A's name:"); PlayerNames [0] = Console.ReadLine () While (PlayerNames [0] = "") {Console.WriteLine ("player A's name cannot be empty, please re-enter"); PlayerNames [0] = Console.ReadLine ();} Console.WriteLine ("Please enter player B's name:"); PlayerNames [1] = Console.ReadLine () While (PlayerNames [1] = = "" | | PlayerNames [1] = = PlayerNames [0]) {if (PlayerNames [0] = "") {Console.WriteLine ("player A's name cannot be empty, please re-enter"); PlayerNames [1] = Console.ReadLine () } else {Console.WriteLine ("the name of player B cannot be the same as player A"); PlayerNames [1] = Console.ReadLine () } # endregion / / clear the screen # region Console.Clear (); / / clear the screen GameShow (); Console.WriteLine ("soldiers of {0} are represented by A, PlayerNames [0]); Console.WriteLine (" soldiers of {0} are represented by B ", PlayerNames [1]) # endregion / / initialize the map before drawing the map # region InitailMap (); DrawMap (); # endregion / / when player An and player B have no one at the finish line, two players keep playing the game # region while (PlayerPos [0])

< 99 && PlayerPos[0] < 99) { if (Flags[0] == false) { PlayGame(0); } else { Flags[0] = false; } if (PlayerPos[0] >

99) {Console.WriteLine ("player {0} beat player {1}", PlayerNames [0], PlayerNames [1]); break;} if (Flags [1] = = false) {PlayGame (1) } else {Flags [1] = false;} if (PlayerPos [0] > 99) {Console.WriteLine ("player {0} beat player {1}", PlayerNames [0], PlayerNames [1]); break }} / / while # endregion Console.WriteLine ("Game over!") ; Console.ReadLine ();} / / Map header # region public static void GameShow () {Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine ("* *") Console.WriteLine ("*"); Console.WriteLine ("* Flying Chess *") Console.WriteLine ("* *"); Console.WriteLine ("* *") } # endregion / / initialization map # region public static void InitailMap () {int [] luckyturn = {6, 23, 40, 55, 69, 83}; / / lucky roulette for (int I = 0; I

< luckyturn.Length; i++) { Maps[luckyturn[i]] = 1; } int[] landMine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };//地雷 for (int i = 0; i < landMine.Length; i++) { Maps[landMine[i]] = 2; } int[] pause = { 2,3,4,9, 27, 60, 93 };//暂停 for (int i = 0; i < pause.Length; i++) { Maps[pause[i]] = 3; } int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90 };//时空隧道 for (int i = 0; i < timeTunnel.Length; i++) { Maps[timeTunnel[i]] = 4; } } #endregion //画地图 #region public static void DrawMap() { Console.WriteLine("图例:幸运圆圈:○ 地雷:☆ 暂停:▽ 时空隧道:◎"); //第一横行 for (int i = 0; i < 30; i++) { //如果玩家A跟玩家B的坐标相同,画一个尖括号 Console.Write(DrawStringMap(i)); }//for Console.WriteLine(); // 第一竖行 for (int i = 30; i < 35; i++) { for (int j = 0; j = 35; i--) { Console.Write(DrawStringMap(i)); } //画第二行 需要进行换行 Console.WriteLine(); //第二竖行 for (int i = 65; i = 99) { PlayerPos[0] = 99; } if (PlayerPos[1] < 0) { PlayerPos[1] = 0; } if (PlayerPos[1] >

99) {PlayerPos [1] = 99;}} # endregion}} Thank you for reading this article carefully. I hope the article "how to implement simple Flying Chess Mini Game" shared by the editor will be helpful to you. At the same time, I hope you will support me and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Players maps names input luck mines coordinates time and space articles tunnels flight chess flight location dice bombing selection Mini Game Cruise same two Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Microsoft Apple Huawei MariaDB