A scissors game is implemented through console commands, which the user enters (1. Scissors, 2. Stone, 3. Cloth) and computer PK, finally through the number of points to determine the outcome
Scissors Game Implementation Ideas:
1, in the console output gameplay tips
2, whether to start the game (receive 1 to start, 0 for exit)
3. Number of games received
4, the loop receives the user's fist (1. Scissors 2 stone 3. Cloth)
5, the system random punch
6. Record the number of winners in comparison
7. Announcement of results
PackageCom.study.second;ImportJava.util.Random;ImportJava.util.Scanner;/*job: Implement a Scissors game through console command, the user through input (1. Scissors, 2. Stone, 3. Cloth) and computer PK, finally through the number of points to determine the outcome*/ Public classNinetysix_ninetyseven { Public Static voidMain (string[] args) {Game g=NewGame (); G.begin (); } }//Scissors Game Classclassgame{ Public voidbegin () {SYSTEM.OUT.PRINTLN ("**********************"); System.out.println ("******* Scissors Game ***********"); System.out.println ("Rules of the game: (1. Scissors 2 stone 3. Cloth)"); System.out.println ("Game Start (1/0):"); Scanner input=NewScanner (system.in); intresult =Input.nextint (); if(Result = = 1) {System.out.println ("Please enter the number of scissors:"); intnum =Input.nextint (); Play (num); }Else{System.out.println (Bye "); } } //the core method of the game Public voidPlayintnum) { intUserCount = 0;//number of users winning the game intPccount = 0;//the number of computers winning the gameRandom r =NewRandom (); Scanner input=NewScanner (system.in); while(num>0){ intx = r.nextint (100)%3+1;//Computer Punch (100%3 1 3 range is a plus)System.out.println ("Please enter your choice (1. Scissors 2 stone 3. Cloth)"); ints =Input.nextint (); if(s==1){ Switch(x) { Case1: System.out.println ("Draw, you out scissors, computer out scissors"); Break; Case2: System.out.println ("You lose, the computer wins, you pull the scissors, the computer rocks."); Pccount++; Break; Case3: System.out.println ("You win, the computer loses, you pull out the scissors, the computer is out of the cloth."); UserCount++; Break; } } if(s==2){ Switch(x) { Case1: System.out.println ("You win, computer loses, you rock, computer scissors."); UserCount++; Break; Case2: System.out.println ("Draw, you out of stone, computer out of stone"); Break; Case3: System.out.println ("You lose, the computer wins, you rock, the computer out of the cloth."); Pccount++; Break; } } if(s==3){ Switch(x) { Case1: System.out.println ("You lost, the computer won, you out cloth, computer scissors"); Pccount++; Break; Case2: System.out.println ("You win, the computer loses, you out of the cloth, the computer out of the stone."); UserCount++; Break; Case3: System.out.println ("Draw, you out of cloth, computer out of cloth"); Break; }} num--; } //Announcement ResultsSystem.out.println ("*****************"); System.out.println ("You win:" +UserCount); System.out.println ("Computer wins:" +pccount); if(UserCount = =Pccount) {System.out.println (Draw); }Else if(UserCount >Pccount) {System.out.println ("You win, the computer loses."); }Else{System.out.println ("You lose, the computer wins."); } } }
Object-oriented _ Scissors game