In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces in detail "how to achieve simple fist guess Mini Game by Java" with detailed content, clear steps and proper handling of details. I hope this article "how to achieve simple boxing guess Mini Game by Java" can help you solve your doubts.
1 requirement
Guess the fist with the computer and record the score.
2 Computer.java source code (computer automatic random punch) public class Computer {public void Fingers (int index) {String [] fingers = {"rock", "scissors", "paper"}; System.out.println ("computer punch:" + fingers [index]);}} 3 Game.java source code (class for main functions) import java.util.Random;import java.util.Scanner Public class Game {public void initial () {/ / Page Scanner scanner = new Scanner (System.in); System.out.println ("- Welcome to the game interface -"); System.out.println () System.out.println ("* *"); System.out.println ("* guessing fist, go! * "); System.out.println (" * * "); System.out.println (" punch rule: 0. Stone 1. Scissors 2. ); / / enter the name System.out.print ("Please enter your name:"); String name = scanner.next (); System.out.println (name+ "VS Boss Battle"); / / determine whether to start System.out.print ("do you want to start?" (enter yes/no): "); String b = scanner.next (); int count=0; int usercount=0; int computercount=0; while (b.equals (" yes ")) {/ / count the number of fights count++; / / players punch System.out.print (" Please punch 0. Stone 1. Scissors 2. Cloth (enter the corresponding number): "); int a = scanner.nextInt (); String [] fingers = {" rock "," scissors "," paper "}; System.out.println (" you punch: "+ fingers [a]); / / computer random punch Random random = new Random (); int index = random.nextInt (3) Computer computer = new Computer (); computer.Fingers (index); / / decide whether to win or lose if ((a = = 0 & & index = = 1) | | (a = = 1 & & index = = 2) | | (a = = 2 & & index = = 0) {System.out.println ("Congratulations, you won!") ; usercount = usercount+1;} else if ((a = = 0 & & index = = 2) | (a = = 1 & & index = = 0) | | (a = = 2 & & index = = 1) {System.out.println ("I'm sorry, you lost!") ; computercount = computercount+1;} else {System.out.println ("result: tie!") ;} / / whether to proceed to the next round of System.out.print ("whether to proceed to the next round!" (enter yes/no); b = scanner.next ();} / / Summary System.out.println ("--Summary -"); System.out.println (name+ "VS Boss") System.out.println ("number of battles:" + count); System.out.println ("name score"); System.out.println ("Boss Wen" + computercount); System.out.println (name+ "" + usercount); String I = computercount > usercount? " It's a pity that you lost the game! " : computercount
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.