Human-Machine Scissors C # implementation

Source: Internet
Author: User

Program entry: Main () Method: namespace guess{    class program    {        static void Main (Strin G[] args)         {            Game game = new Game ();    &NBSP ;       game. Startgame ();       }   }}1.game class: namespace guess{    class game    {&N Bsp       Computer C = new computer ();        person p = new person ();        int count = 0;         public void Startgame ()          {  &N Bsp         Console.WriteLine ("Start Game");            Console.WriteLine (" Game rules: 1. Scissors 2. Stone 3. Cloth (Please enter the corresponding number is OK!!!) );            Console.WriteLine ("First select your challenge: 1. Liu Bei 2. Sun Quan 3.");      &NB Sp     int i = Convert.ToInt16 ((Console.ReadLine ()));    &nbsP       switch (i)             {             & nbsp   Case 1:                    c.name = "Liu Bei";      &NB Sp             Console.WriteLine ("Counter selected opponent: {0}\n", c.name);          &N Bsp         break;                case 2:      &NBS P             c.name = "Sun Quan";                  &NB Sp Console.WriteLine ("Your opponent selected: {0}\n", c.name);                    break;& nbsp               case 3:                  &NB Sp C.name = "Caocao";                    Console.WriteLine ("The opponent you chose is {0}\n: ", C.name);                    break;                default:                    Console.Write ("Incorrect input, exit department   ");                   //SYSTEM.DIAGNOSTICS.PROCESS.GETCURRENTP Rocess (). Kill ();                    environment.exit (0);      &NBS P             break;           }        &NB Sp   Console.WriteLine ("Please enter your name:");            P.name = convert.tostring ( Console.ReadLine ());            Console.WriteLine ("");          &N Bsp Console.WriteLine (p.name + "vs" + c.name+ "\ n");            Console.WriteLine ("Do you want to start? (y/n) ");      &nbsp     String ans = convert.tostring (Console.ReadLine ());             while ("Y" . Equals (ans))             {                int pID = P . Chuquan ();                int cID = C.chuquan ();        &NBSP ;                       if (PID = = CID)       &NBS P         {                  Console.WriteLine ("Draw") ;                    count++;            & nbsp  }                else if (CID = = 1 && PID = = 3 | | cID = = 2 &&am P PID = = 1 | | CID = = 3 && PID = = 2)                 {                    Console.WriteLine ("{0} win", C.name);            &N Bsp       c.scoer++;               }                ELSE if (pid = = 1 && cid = 3 | | pid = = 2 && CID = 1 | | pid = = 3 && cid = = 2)                 {                    Console.WriteLine ("You Win");                    p.scoer++;  &NB Sp            }                Console.WriteLine ("Continue Games (y/n) ");                ans = convert.tostring (Console.ReadLine ());  &nbsp ;        }                  Console.WriteLine ("Game Over, knot The following \ n ");                Console.WriteLine ("Ping  : {0}", count);        &NB Sp       Console.WriteLine ("{0} wins: {1}", C.name,c.scoer);              &NBSP ; Console.WriteLine ("I   win: {0}", P.scoer);                  }  & nbsp }}2.person class; namespace guess{    class person    {        public string name;        public int scoer;        public person ()          {&nbsp ;       }        public int Chuquan ()         {    & nbsp       Console.WriteLine ("Please Punch:");            int ID = convert.toint16 (Console . ReadLine ());            switch (ID)             {    & nbsp          Case 1:console.writeline ("I Punch for Scissors");              &N Bsp     break;                Case 2:console.writeline ("I Punch for Stone");  &NB Sp                 break;                case 3:console.writeline ("I Punch for cloth");                    break;    &N Bsp           default:                    CONSOLE.W Riteline ("input error");                    environment.exit (0);    & nbsp               break;           }      &NB Sp     return id;       }   }}3. Computer Computer class: namespace guess{     CLASS computer    {        public computer ()          {   &NB Sp    }        public string name;        public int scoer;    & nbsp   public int Chuquan ()          {        random random = new Random () &NB Sp       int ID = random. Next (1, 4);        switch (ID)         {            C ASE 1:console.writeline (name+ "Punch: Scissors");                break;            Case 2:console.writeline (name+ "Punch, stone");                break ;            case 3:console.writeline (name+ "punch: Cloth");          &NBSP ;     break;        }        return ID;       }   }}

Human-Machine Scissors C # implementation

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.