C # flying Chess Small programming Code _c# tutorial

Source: Internet
Author: User
Tags readline

Flying Chess Games Everyone should have played it, how to use the C # language to write, this article for you to share the example of the Flying Chess C # implementation code for your reference, the specific content as follows

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;

Using System.Threading.Tasks;
    Namespace Pachee {class Program {#region static field//Checkpoint quantity public static int[] Maps = new int[100];
    Player coordinates public static int[] Playerpos = new int[2];
    Player name public static string[] Playernames = new string[2];
    Judge whether the player suspends public static bool[] Flags = new bool[2]; #endregion///<summary>///Output Game header///</summary> public static void Showgame () {C Onsole.
      Foregroundcolor = Consolecolor.green;
      Console.WriteLine ("****************************");
      Console.foregroundcolor = Consolecolor.blue;
      Console.WriteLine ("****************************");
      Console.foregroundcolor = Consolecolor.white;
      Console.WriteLine ("***c# basic exercise: Flying Chess Project * * *");
      Console.foregroundcolor = Consolecolor.yellow;
      Console.WriteLine ("****************************"); Console.foregroundcolor = Consolecolor.red;
    Console.WriteLine ("****************************");
    ///<summary>///Accept the name of the game entered by the user, determine whether it is legal///</summary>///<returns> Game Name </returns>
      public static string[] Inputplayernames () {playernames[0] = "";
      PLAYERNAMES[1] = "";
      Console.foregroundcolor = Consolecolor.white;
        while (playernames[0] = = "") {Console.Write ("Please enter the name of game A Player:"); Playernames[0] = Console.ReadLine ().
        Trim ();
          if (playernames[0] = = "") {Console.WriteLine ("A player name cannot is empty, please enter again.");
        Continue
      } break; while (playernames[1] = = "" | |
        Playernames[0] = = Playernames[1]) {console.write ("Please enter the name of game B Player:"); PLAYERNAMES[1] = Console.ReadLine ().
        Trim (); if (playernames[1] = = "") {Console.WriteLine ("B player name cannot be empty, Please enter again. ");
        Continue else if (playernames[1] = = Playernames[0]) {Console.WriteLine ("The player name cannot be the
          Same as the player A B, please enter again. ");
        Continue
      } break;
    return playernames; ///<summary>///Initialize map, change the default map coordinate type///0: Square///1: Roulette///2: Mine///3: Pause///4: Tunnel/  </summary> public static void Initailmap () {#region Roulette int[] Lucktrun = {6, 23, 40, 55, 69,
      83};
      for (int i = 0; i < lucktrun.length i++) {Maps[lucktrun[i]] = 1;
      #endregion #region Mine int[] Landmine = {5, 13, 17, 33, 38, 50, 64, 80, 94};
      for (int i = 0; i < landmine.length i++) {Maps[landmine[i]] = 2;
      #endregion #region paused int[] Pause = {9, 27, 60, 93}; for (int i = 0; i < pause. Length; i++) {Maps[pause[i]] = 3;
      #endregion #region Tunnel int[] Timetunnel = {20, 25, 45, 63, 72, 88, 90};
      for (int i = 0; i < timetunnel.length i++) {Maps[timetunnel[i]] = 4; #endregion}///<summary>///set the type of current coordinates///</summary>///<param name= "I" > Coordinates </param>///<returns> coordinate types </returns> public static string drawstringmap (int i) {str
      ing str = null;
      if (playerpos[0] = = Playerpos[1] && playerpos[0] = = i) {str = "<>";
      else if (playerpos[0] = = i) {str = "a";
      else if (playerpos[1] = = i) {str = "B"; else {switch (Maps[i]) {Case 0:console.foregroundcolor = Consolecol Or.
            Yellow;
            str = "-";
          Break
            Case 1:console.foregroundcolor = Consolecolor.blue;
            str = ""; BrEak
            Case 2:console.foregroundcolor = Consolecolor.green;
            str = "☆";
          Break
            Case 3:console.foregroundcolor = consolecolor.red;
            str = "▲";
          Break
            Case 4:console.foregroundcolor = Consolecolor.cyan;
            str = "卐";
        Break
    } return str; ///<summary>///generates all coordinates///</summary> public static void Drawmap () {Console.wri

      Teline ("legend:lucktrun< > Landmine<☆> pause<▲> timetunnel< 卐 >");
      #region the first horizontal row for (int i = 0; i < i++) {Console.Write (Drawstringmap (i));
      } Console.WriteLine ();
        #endregion #region The first vertical for (int i = < i++) {for (int j = 0; J <=; J +)
        {Console.Write ("");
        } console.write (Drawstringmap (i));
     Console.WriteLine (); #endregion #region Second horizontal row for (int i = >= i i--) {Console.Write (drawstringma
      P (i));
      } Console.WriteLine (); 
      #endregion #region The second vertical for (int i = i < i++) {Console.WriteLine (Drawstringmap (i)); #endregion #region Third horizontal row for (int i = i++ i <=) {Console.Write (Drawst
      Ringmap (i));
      } Console.WriteLine ();
    #endregion}///<summary>///determine if coordinates are out of range///</summary> public static void Changepos ()
      {#region Player A if (Playerpos[0] < 0) {playerpos[0] = 0;
      } if (Playerpos[0] >) {playerpos[0] = 99;
      #endregion #region Player B if (Playerpos[1] < 0) {playerpos[1] = 0;
      } if (Playerpos[1] >) {playerpos[1] = 99; } #endregion}///<summary>
    When stepping on the wheel, select function///</summary>///<param name= "Input" > Player's Choice </param>///<param name=
      "Player" > Player logo </param> public static void Playerselect (string input, int player) {while (true) {if (input = = "1") {Console.WriteLine ("Player {0} Select and {1} swap places.", playernames[
          Player], Playernames[1-player]);
          int temp = Playerpos[player];
          Playerpos[player] = Playerpos[1-player];
          Playerpos[1-player] = temp;
          Console.WriteLine ("Swap complete, press any key continue.");
          Console.readkey (TRUE);
        Break else if (input = = "2") {Console.WriteLine ("Player {0} Select bombing {1}", player {2} back to
          6. ", Playernames[player], Playernames[1-player], Playernames[1-player]);
          Playerpos[1-player]-= 6;
          Console.readkey (TRUE);
        Break } else {Console.
          WriteLine ("Can only Select:1--swap places 2--bombing:");
        input = Console.ReadLine (); }}///<summary>///for games///</summary>///<param name= "Player" > player logo bit <
      /param> public static void PlayGame (int player) {Random r = new Random ();
      int next = R.next (1, 7);
      Console.WriteLine ("{0} Press any key to start rolling the dice.", Playernames[player]);
      Console.readkey (TRUE);
      Console.WriteLine ("{0} Throw out of {1}", Playernames[player], next);
      Playerpos[player] + = next;
      Changepos ();
      Console.readkey (TRUE);
      Console.WriteLine ("{0} Press any key to start action.", Playernames[player]);
      Console.readkey (TRUE);
      Console.WriteLine ("{0} action complete.", Playernames[player]);
      Console.readkey (TRUE); Player A is likely to step on: Player B, Square, Roulette, mine, pause, tunnel if (playerpos[player] = = Playerpos[1-player]) {CONSOLE.W Riteline ("Player {0} step"{1}, {2} back to 6. ", Playernames[player], Playernames[1-player], Playernames[1-player]);
        Playerpos[1-player]-= 6;
      Console.readkey (TRUE); else {switch (Maps[playerpos[player]]) {case 0:console.writeline ("P
            Layer {0} step on Square, safe. ", Playernames[player]);
            Console.readkey (TRUE);
          Break Case 1:console.writeline (' Player {0} step ' a lucktrun, please select:1--swap places 2--bombing: ", Playern
            Ames[player]); string input = Console.ReadLine ().
            Trim ();
            Playerselect (input, player);
            Console.readkey (TRUE);
          Break
            Case 2:console.writeline ("Player {0} step on a landmine, back to 6", Playernames[player]);
            Playerpos[player]-= 6;
            Console.readkey (TRUE);
          Break Case 3:console.writeline ("Player {0} step on a Pause, to suspend a round.", PlAyernames[player]);
            Console.readkey (TRUE);
            Flags[player] = true;
          Break
            Case 4:console.writeline ("Player {0} step on a timetunnel, forward", Playernames[player]);
            Playerpos[player] + + 10;
            Console.readkey ();
        Break
      } changepos ();
      Console.clear ();
    Drawmap ();
      } static void Main (string[] args) {showgame ();
      Inputplayernames ();
      Console.WriteLine ("Player {0} is A.", Playernames[0]);
      Console.WriteLine ("Player {0} is B.", Playernames[1]);
      Initailmap ();

      Drawmap ();
        while (Playerpos[0] < && playerpos[1] <) {#region A if (flags[0] = = False)
        {PlayGame (0);
        else {Flags[0] = false;
        #endregion #region B if (flags[1] = = False) {PlayGame (1);
      } else  {Flags[1] = false;
        #endregion} #region Determine if the player wins if (playerpos[0] = = () {console.clear);
      Console.WriteLine ("Player {0} Win.", Playernames[0]);
        } if (playerpos[1] = =) {console.clear ();
      Console.WriteLine ("Player {0} Win.", Playernames[1]);
    } #endregion Console.readkey ();
 }
  }
}

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.