Man-Machine Scissors

Source: Internet
Author: User

 Packagecom.homework.lhh;ImportJava.util.Scanner; Public classMoragame {PrivateString PlayerName;//player Name    PrivateString ComputerName;//Computer player name     Public Static intPlayerscore;//Player Score     Public Static intComputerscore;//Computer Score     Public Static intPlaynumber;//PvP Times//Select Opponent vs .@SuppressWarnings ("Resource")     Public voidfight () {//TODO auto-generated Method StubSystem.out.print ("Please select the opposing role (1. Liu Bei 2. Sun Quan 3. Cao):"); Scanner SC=NewScanner (system.in); ComputerName=Sc.next (); Switch(computerName) { Case"1":             This. ComputerName = "Liu Bei";  Break;  Case"2":             This. ComputerName = "Sun Quan";  Break;  Case"3":             This. ComputerName = "Caocao";  Break; default: System.out.println ("Your input is wrong!" ");  Break; } System.out.print ("Please enter your name:"); PlayerName=Sc.next (); System.out.println (PlayerName+ "VS" + This. ComputerName); }    //Start playing games@SuppressWarnings ("Resource")     Public voidStartplay () {//TODO auto-generated Method StubSystem.out.println (); System.out.print ("Do you want to start?" (y/n): "); Scanner SC=NewScanner (system.in); String Start=Sc.next (); System.out.println ("********************************");  while(Start.tolowercase (). Equals ("Y") {System.out.print ("Please punch: 1. Scissors 2. Stone 3. Cloth (Enter the corresponding number):"); intPlayernumber =Sc.nextint ();            System.out.println (); Switch(playernumber) { Case1: System.out.println ("You punch: Scissors.");  Break;  Case2: System.out.println ("You Punch: Stone");  Break;  Case3: System.out.println ("You punch: Cloth");  Break; default: System.out.println ("Your input is wrong");  Break;            } System.out.println (); intComputernumber = (int) ((Math.random () * 10)% 3 + 1);//the computer generates a random number value between 1-3            Switch(computernumber) { Case1: System.out.print ( This. ComputerName + "Punch: Scissors");  Break;  Case2: System.out.print ( This. ComputerName + "Punch: Stone");  Break;  Case3: System.out.print ( This. ComputerName + "Punch: Cloth");  Break;            } System.out.println (); //Judging the results of the game            if(Playernumber = =Computernumber) {System.out.println ("Ah, a draw!" "); Playnumber++; } Else if((Playernumber = = 1) && (computernumber! = 2)) | | ((Playernumber = = 2) && (Computernumber! = 3))                    || ((Playernumber = = 3) && (Computernumber! = 1)) {System.out.println ("Wow, you won, that's great!" "); Playerscore++; Playnumber++; } Else{System.out.println ("^_^!!! You're a loser, stupid! "); Computerscore++; Playnumber++;            } System.out.println (); System.out.print ("Whether to start the next inning (y/n):"); Start=Sc.next ();            System.out.println (); System.out.println ("********************************"); }         This. Gameend (); }    //Game Over     Public voidGameend () {//TODO auto-generated Method StubSystem.out.println (); System.out.println ("********************************"); System.out.println (PlayerName+ "VS" + This. ComputerName); System.out.println ("PvP Times:" +playnumber); System.out.println ("Name \t\t score"); System.out.println ( This. ComputerName + "\t\t" +Computerscore); System.out.println (PlayerName+ "\t\t" +Playerscore); if(Playerscore <Computerscore) {System.out.println ("Oh, stupid, next refueling!" "); }Else if(Playerscore = =Computerscore) {System.out.println ("Wow, even a draw, our next showdown!" "); }Else{System.out.println ("Wow, you're great!" "); }    }}classUi { Public voidtheme () {//TODO auto-generated Method StubSystem.out.println ("\t\t********************************"); System.out.println ("\t\t********** scissors, start *************"); System.out.println ("\t\t********************************");        System.out.println (); System.out.println ("Punching rule: 1. Scissors 2. Stone 3. Cloth"); }}
 Package com.homework.lhh;  Public class moragametest {    publicstaticvoid  main (string[] args) {          New  moragame ();         New Ui ();        Ui.theme ();        Game.fight ();        Game.startplay ();    }}

Man-Machine Scissors

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.