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