The Glorious Years of wisdom-c# basic six flying chess

Source: Internet
Author: User
Tags clear screen map class

Flying Chess Business:
We need to be able to have 2 players play on the map according to the rules of the game

Player class
Variables: Player position, player name, player ID, whether the player is in a trap
Method: Throw Dice, move

Map class
Variables: Map data arrays
Method: Initialize map data, draw map, display logo

Game Rules Class
Variable:
Method: The first game description, determine whether the player position has obstacles, according to different obstacles to perform different operations, to determine whether the game is over

Using system;using system.collections.generic;using system.linq;using system.text;namespace P03FlyQi{class Program        {#region----------------1. Global variable Mapdata/playermark/palyernames/playerposition/playerisintrap------------------- 1. Global variables-----------------------------//--------1.1 map data-----------------//<summary>//        /map data array//</summary> static string[] MapData = new string[100]; --------1.2 player Data-----------------//<summary>//Player ID//////</summary> St        atic string[] Playermark = new string[2];        <summary>///Player name///</summary> static string[] Playernames = new string[2];        <summary>///Player location///</summary> static int[] playerposition = new int[2];       <summary>///Whether the player is in a trap///</summary> static bool[] Playerisintrap = new bool[2];  #endregion static void Main (string[] args) {startgame ();        Console.ReadLine ();        } #region 0.0 games start void startgame ()///<summary>//0.0 games start//</summary>            static void Startgame () {//0.1 initialization data initdata ();            0.2 display Logo Showlogo ();        0.3 games for Playing (); } #endregion #region 1.0 Initialize data method void InitData ()///<summary>//1.0 Initialize data method/            </summary> static void InitData () {//1. Initialize map data initmapdata ();        2. Initialization of player data initplayerdata ();        #endregion #region 1.1 Initialize map data void Initmapdata ()//<summary>//1.1 Initialize map data </summary> static void Initmapdata () {//a. The default assignment for all cells in the map is "normal" for (in t i = 0; i < mapdata.length;   i++)         {Mapdata[i] = "normal";            }//b. Set the barrier mapdata[5] = "Mine";            MAPDATA[25] = "Mines";            MAPDATA[45] = "Mines";            MAPDATA[85] = "Mines";            MAPDATA[15] = "trap";            MAPDATA[33] = "trap";            MAPDATA[65] = "trap";            MAPDATA[95] = "trap";            MAPDATA[12] = "Time-space tunnel";            MAPDATA[28] = "Time-space tunnel";            MAPDATA[54] = "Time-space tunnel";            MAPDATA[79] = "Time-space tunnel";            MAPDATA[7] = "lucky Wheel";            MAPDATA[37] = "lucky Wheel";            MAPDATA[47] = "lucky Wheel";        MAPDATA[69] = "lucky Wheel";        } #endregion #region 1.2 initialize player data void initplayerdata ()///<summary>//1.2 Initialize player data            </summary> static void Initplayerdata () {playermark[0] = "a";            PLAYERMARK[1] = "B";            Playernames[0] = ReadString ("Please enter the name of Player A:");            Console.WriteLine ("Player {0} 's name is set successfully ~ ~ ~:) \ n", playermark[0]);         Do   {Playernames[1] = ReadString ("Please enter player B's name:");                if (playernames[1] = = Playernames[0]) {Console.WriteLine ("Two names cannot be the same as ~ ~ ~");                    } else {Console.WriteLine ("Player {0} 's name was set successfully ~ ~ ~:) \ n", playermark[1]);                Break        }} while (true);        } #endregion #region 2.0 show Game logo void Showlogo ()///<summary>//2.0 Show Game logo </summary> static void Showlogo () {Console.WriteLine ("********************************            ************");            Console.WriteLine ("* *");            Console.WriteLine ("* Knight Flight Chess of the Bull B");            Console.WriteLine ("* *");        Console.WriteLine ("********************************************"); } #endregion #regioN 3.0 games in the Middle void Playing ()///<summary>//3.0 games in//</summary> static void            Playing () {//3.1 clear screen console.clear ();            3.2 Display logo Showlogo ();            3.3 Show the description message for the first time the game was run showfirstroundmsg ();        3.4 Games take turns playrounds ();  #endregion #region 3.1 shows a description of the first run of the game message void showfirstroundmsg ()//<summary>//3.1 Displays a description message for the first time the game was run//</summary> static void Showfirstroundmsg () {Console.WriteLine ( "{0} and {1} Two good friends will be showdown in this game ~~!            ", Playernames[0], playernames[1]);            Console.WriteLine ("Player" {0} "with" A "denotes ~ ~", playernames[0]);            Console.WriteLine ("Player" {0} "with" B "denotes ~ ~", playernames[1]); Console.WriteLine ("If the two players are in the same position, use <>!")            ");        Console.WriteLine ("Game Start ~ ~ ~");    } #endregion///<summary>///Games End logo///</summary>    static bool Isgameover = FALSE; #region 3.2 games take turns void Playround ()///<summary>//3.2 Games Rotate///</summary> St            atic void Playrounds () {//3.2.1 draw map showmap ();            while (!isgameover) {//3.2.2 player starts playing ~ ~ playanround ();        }} #endregion draw map #region 3.2.1 void Showmap ()///<summary>//3.2.1 Map  </summary> static void Showmap () {//1. Draw the first part: the 1th horizontal bar (left to right) for (int i = 0; I < 30;                i++) {String Uniticon = Getmapuniticonbytype (i);            Console.Write (Uniticon);            } Console.WriteLine (); 2. Draw Part Two: 1th vertical bar (right vertical bar) for (int i =; i <; i++) {String Uniticon = Getmapuni                Ticonbytype (i);           for (int j = 0; J <; J + +) {         Console.Write ("");            } Console.WriteLine (Uniticon); //3. Draw the third part: 2nd Bar (right-to-left) for (int i = i>=35;; i--) {string Unitico                n = getmapuniticonbytype (i);            Console.Write (Uniticon);            } Console.WriteLine (); 4. Draw Part IV: 2nd vertical bar (left vertical bar) for (int i = n; i < i++) {string Uniticon = Getmapuni                Ticonbytype (i);            Console.WriteLine (Uniticon); }//5. Plot Part V: 3rd horizontal bar (from left to right) for (int i = i++; I <) {string UnitI                con = Getmapuniticonbytype (i);            Console.Write (Uniticon);            } Console.WriteLine ();        After drawing the map, restore the original font color Console.resetcolor (); } #endregion #region 3.2.1.1 the map icon or player ID string getmapuniticonbytype (int mapindex)///&L according to the map subscript T;summary>///3.2.1.1 Returns the Map element type (normal, mine, trap ...) and returns the corresponding symbol according to the map subscript, or Player ID///To get the map unit (common, mines, traps). </summary>//<param name= "Mapindex" > Map unit subscript </param> static string Getmapuniticonbytyp            E (int mapindex) {string struniticon = ""; 1. Determine if the location of the map has the player if (Mapindex = = playerposition[0])//Player A's position {//If the two players are in the same position, you need to return to the & lt;> if (playerposition[0] = = Playerposition[1]) {CONSOLE.FOREGROUNDC                    Olor = Consolecolor.gray;                Struniticon = "<>";                    } else {console.foregroundcolor = Consolecolor.white;                Struniticon = playermark[0]; }} else if (Mapindex = = playerposition[1])//Player B's position {Console.foregroundco                Lor = Consolecolor.white;            Struniticon = playermark[1]; } else//map Symbol {switch (Mapdata[mapindex]) {case "normal":                        Console.foregroundcolor = Consolecolor.white;                        Struniticon = "-";                    Break                        Case "Mine": Console.foregroundcolor = consolecolor.red;                        Struniticon = "";                    Break                        Case "Lucky Roulette": Console.foregroundcolor = Consolecolor.yellow;                        Struniticon = "卐";                    Break                        Case "space-Time Tunnel": Console.foregroundcolor = Consolecolor.magenta;                        Struniticon = "0";                    Break                        Case "trap": Console.foregroundcolor = Consolecolor.green;                        Struniticon = "Well";                Break }} return Struniticon;       } #endregion #region 3.2.22 players each throw a dice void playanround ()///<summary>//3.2.2            Two players each throw a dice///</summary> static void Playanround () {int playnum = 0;            1. Player A throws the dice--------------------------//0. Determine if Player A is in the trap if (playerisintrap[0] = = true)//If in the trap, stop round                {Console.WriteLine ("Player" A "is struggling to climb outside the trap ~ ~ ~ ~ Press ENTER to continue");            Playerisintrap[0] = false;//changes player B's trap identifier to False (has stopped for a round) console.readline ();                } else//Otherwise, the dice are cast {playnum = Getanrandomnum ();                1.1 Modify player A's position playerposition[0] + = Playnum;                Console.WriteLine ("Player" a "throws a number: {0}, press ENTER to continue ...", playnum);                Console.ReadLine ();                1.2 Redraw map console.clear ();                Showlogo ();                Showmap (); 1.3 Determine if Player A is at the end of a new position or has an obstruction!            , if there is one, handle it accordingly    Judgeposition (TRUE); }//2. Player B throws the dice-----------------------------//0. Determine if Player A is in the trap if (playerisintrap[1] = = true)/                /If in the trap, stop round {Console.WriteLine ("Player" B "is struggling to climb outside the trap ~ ~ ~ ~ Press ENTER to continue");            PLAYERISINTRAP[1] = false;//changes player B's trap identifier to False (has stopped for a round) console.readline ();                } else {playnum = Getanrandomnum ();                2.1 Modify Player B's position playerposition[1] + = Playnum;                Console.WriteLine ("Player" B "cast a number: {0}, press ENTER to continue ...", playnum);                Console.ReadLine ();                2.2 Redraw Map console.clear ();                Showlogo ();                Showmap (); 2.3 Determine if Player B is at the end of a new position or has an obstruction!            , if any, then handle judgeposition (false) accordingly; }} #endregion #region 3.2.2.1 get a dice number (1-6)///<summary>//3.2.2.1 Get a dice Number (1-6)///</summary> Static int Getanrandomnum () {Random ran = new Random (); Return ran.        Next (1, 7); } #endregion #region 3.2.2.2 to determine if the player has obstructions on the map, and if so, perform the corresponding operation void Judgeposition (bool Isplayera)///<s Ummary>//3.2.2.2 Determine if the player has obstructions on the map, if any, do the corresponding action///</summary>//<param name= "index" >&            lt;/param> static void Judgeposition (bool isplayera) {//0. Determine if the new position of two players has exceeded the map, and if it exceeds, the game ends                if (Playerposition[0] >=) {Console.WriteLine ("Game ends ~ ~ Player {0} won ~ ~", playermark[0]);            Isgameover = true; } else if (Playerposition[1] >=) {Console.WriteLine ("Game ends ~ ~ Player {0} won ~ ~", player                MARK[1]);            Isgameover = true; } else {//1. player's position int playerindex = Isplayera? Playerposition[0]: P                LAYERPOSITION[1]; 2. According to the player location map of the obstacles to executeDifferent operation switch (Mapdata[playerindex]) {case "mine": {                            Meetbomb (Isplayera);                        Break                            } case "Lucky Roulette": {meetluckycircle (Isplayera);                        Break                            } case "Space-time Tunnel": {Meettimetunnuel (Isplayera);                        Break                            } Case "Trap": {meettrap (Isplayera);                        Break        }}}} #endregion #region 3.2.2.2.1 encounter mine void Meetbomb (bool Isplayera) <summary>//3.2.2.2.1 Encounter landmines///</summary>/<param name= "Isplayera" > is Player A, or player b</param>       static void Meetbomb (bool isplayera) {//1. If it is a mine, you are prompted to step back 6 Console.WriteLine ("Bad luck ~ ~" {0} "stepped on a mine ~~! Back 6 ~~!            Press ENTER to continue ... ", (Isplayera playermark[0]: playermark[1]));            2. Players back 6 if (Isplayera) {playerposition[0]-= 6;            } else {Playerposition[1]-= 6;            } checkposition ();            Console.ReadLine ();            Console.clear ();            Showlogo ();        Showmap ();        } #endregion #region 3.2.2.2.2 encounter space-time tunnel void Meettimetunnuel (bool isplayera)//<summary>        3.2.2.2.2 encounters a time-space tunnel//</summary>//<param name= "Isplayera" > is player A, or player b</param> static void Meettimetunnuel (bool isplayera) {//1. If it is a mine, you are prompted to step back 6 Console.WriteLine ("Lucky Shipping ~ ~ "{0}" into the space-time Tunnel ~ ~! Forward 6 lattice ~~!            Press ENTER to continue ... ", (Isplayera playermark[0]: playermark[1])); 2.Player back 6 if (Isplayera) {playerposition[0] + = 6;            } else {playerposition[1] + = 6;            } checkposition ();            Console.ReadLine ();            Console.clear ();            Showlogo ();        Showmap (); } #endregion #region 3.3.2.2.3 encountered a trap void Meettrap (bool Isplayera)///<summary>//3.3. 2.2.3 Encounters traps///</summary>//<param name= "Isplayera" ></param> static void Meettrap        (bool Isplayera) {//1. If it is a mine, you are prompted to back up 6 Console.WriteLine ("Ah ~ ~" {0} "fell into the trap ~ ~! Stop a game!            Press ENTER to continue ... ", (Isplayera playermark[0]: playermark[1]));            2. The player enters the trap if (Isplayera) {playerisintrap[0] = true;            } else {playerisintrap[1] = true;        } console.readline (); } #endregion #regIon 3.3.2.4 encounters lucky Roulette void meetluckycircle ()//<summary>//3.3.2.4 encounters lucky Roulette//</summary> static void Meetluckycircle (bool isplayera) {//1. If it is a mine, you are prompted to rewind the 6-cell string strpalyerm Ark = Isplayera?            PLAYERMARK[0]: playermark[1];            int num = Readanum ("Ah ~ ~" + Strpalyermark + "" was smashed by the lucky God ~ ~, please choose a wish: 1. Bombing each other, the other side back 6 grid; 2. The big move, and the other Exchange position: "); Switch (num) {case 1://bombing each other, the other side backs up 6 grid {//If it is player A, then player B's                            Position back 6 if (Isplayera) {playerposition[1]-= 6; Console.WriteLine ("You choose to bomb each other, player" B "will back 6 grid!)                        "); } else//if player B, then player A's position back 6 grid {Playerposition[0]                            -= 6; Console.WriteLine ("You choose to bomb each other, player" A "will back 6 grid ~!)                        "); } BreaK } Case 2://the universe, and the other Exchange position {//playerposition[0] = playerposition[0                        ] + playerposition[1];                        PLAYERPOSITION[1] = playerposition[0]-playerposition[1];                        Playerposition[0] = playerposition[0]-playerposition[1];                        int temp = playerposition[0];                        Playerposition[0] = playerposition[1];                        PLAYERPOSITION[1] = temp; Console.WriteLine ("You chose the big change of the universe, and the other Exchange position!")                        ");                    Break            }} checkposition ();            Console.ReadLine ();            Console.clear ();            Showlogo ();        Showmap (); } #endregion #region 4. Check the player position and set the threshold void checkposition ()///<summary>//4. Check if there is an out-of-bounds Player position, set the threshold value//</summary> static void Checkposition () {if (Playe) if there is an out-of-boundsRposition[0] < 0) playerposition[0] = 0;            if (Playerposition[1] < 0) playerposition[1] = 0;            if (Playerposition[0] >) playerposition[0] = 99;        if (playerposition[1] >) playerposition[1] = 99; } #endregion//-----------------------Tool method-------------------------------//------------------------ -------------------------------------#region 0.0 reads a non-empty string ReadString (string strMsg)///<summary >//0.0 read a non-empty string///</summary>//<returns></returns> static string            ReadString (String strMsg) {string strmsgback= "";                while (true) {Console.Write (STRMSG); Strmsgback = Console.ReadLine ().                Trim (); if (string.                IsNullOrEmpty (Strmsgback)) {Console.WriteLine ("The string you entered cannot be empty ~ ~");           } else {         Break }} return strmsgback;//returns the received non-empty string//trim method used to remove spaces on both sides of the string, such as: "AAA aaa" = "AAA AAA"//string.  IsNullOrEmpty determines whether the string is empty, returns true if it is empty, or returns false} #endregion #region 0.0 reads a numeric value int readanum (string STRMSG)///<summary>//0.0 read a value///</summary>//<returns></retur            ns> static int Readanum (string strMsg) {int num =-1;                while (true) {string strmsgback = ReadString (STRMSG); if (int.                TryParse (strmsgback, out num) && (num > 0 && num<3)) {break; } else {Console.WriteLine ("Please enter a value between 1-2!")                ");        }} return num; } #endregion}}

  

The Glorious Years of wisdom-c# basic six flying chess

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.