- /** 猜拳游戏 */
- import java.util.Random;
- import java.util.Scanner;
- enum Ruel{
- 赢,输,平,
- }
- public class Test{
- public static void main(String args[]){
- System.out.println("\n\n\n\n\n-----------猜拳游戏-----------");
- System.out.println(" 1.石头 2.剪刀 3.布 4.退出\n");
- while(true){
- System.out.print(" ------请出拳: ");
- Scanner get = new Scanner(System.in);
- int person = get.nextInt();
- if(person==4){
- System.out.println("\n Game Over! \n");
- break;
- }else if((person>=1)&&(person<=3)){
- int computer = (int)(Math.random()*3)+1;
- Ruel gameResult;
- if(person==computer){
- System.out.println("\n ***** 平局! *****\n");
- }else if((person==(computer-1))||(person==(computer+2))){
- System.out.println("\n ***** 玩家获胜! *****\n");
- }else{
- System.out.println("\n ***** 电脑获胜! *****\n");
- }
- }else{
- System.out.println("\n ***** 出拳违规! *****\n");
- }
- }
- }
- }
复制代码
|