C #------Scissors Games

Source: Internet
Author: User

namespacePunch Game 05{//Player Class    classPlayer {//The contents of the punch are stored and displayed in the form         Public stringFistname {Get;Set; } //the way to punch out         Public intPlay (stringname) {              This. Fistname =name; Switch(name) { Case "Stone":return 1;  Case"Scissors":return 2;  Case"cloth":return 3; }            return 0; }    }}

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespacePunch Game 05{//Computer class    classComputer {//Store the contents of the punch         Public stringFistname {Get;Set; }  Public intPlay () {Random R=NewRandom (); intnum = R.next (1,4); Switch(num) { Case 1: This. Fistname ="Stone"; Break;  Case 2: This. Fistname ="Scissors"; Break;  Case 3: This. Fistname ="cloth"; Break; }            returnnum; }    }}
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespacePunch Game 05{//Referee Class    classCaipan { Public stringWhowin (intPnum,intcNum) {             //1-1 = 0 Tie//1-2 =-1 player wins//1-3 =-2 pc wins//2-1 = 1 the computer won//2-2 = 0 Tie//2-3 = 1 player wins//3-1 = 2 Player wins//3-2 = 1 the computer won//3-3 = 0 Tie            if(Pnum-cnum = =-1|| Pnum-cnum = =2)            {                return "the player wins."; }            Else if(Pnum-cnum = =-2|| Pnum-cnum = =1)            {                return "the computer won."; }            Else            {                return "it's a tie."; }        }    }}
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespacePunch Game 05{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); }        Private voidBtnshitou_click (Objectsender, EventArgs e) {PlayGame (Btnshitou).        Text); }        Private voidPlayGame (stringname) {Player P=NewPlayer (); intPnum =P.play (name); //Show the contents of the punch to the formLabplay.text =P.fistname; //ComputerComputer C =Newcomputer (); intCNum =C.play (); Labcomputer.text=C.fistname; //RefereeCaipan CP =NewCaipan (); Labres. Text=CP.        Whowin (Pnum, CNum); }        Private voidBtnjiandao_click (Objectsender, EventArgs e) {PlayGame (Btnjiandao).        Text); }        Private voidBtnbu_click (Objectsender, EventArgs e) {PlayGame (Btnbu).        Text); }    }}

C #------Scissors Games

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.