• 示例:人机猜拳(请各位大佬看下)


      请各位大佬帮我看下,怎样缩短语句。

      在这谢谢啦!

    这是管理类:

    import java.util.Scanner;
    
    public class startGame {
    	Scanner input=new Scanner(System.in);
    	int count=0;
    	int computerCount=0;
    	int personCount=0;
    	String computer;
    	 public void startbefore(){
    		 System.out.println("		******************");
    		 System.out.println("		**  猜拳,开始 **");
    		 System.out.println("		******************
    
    ");
    		 System.out.println("出拳规则:1.剪刀 2.石头 3.布");
    		 System.out.println("请选择对方角色 (刘备1 孙权2 曹操3):");
    		 computer=input.next();
    		   
    		 System.out.println("您选择了 "+computer+"对战");
    		 	do{
               System.out.println("要开始吗? (y/n)");
           String answer=input.next();
    String nide="null"; System.out.println("请选择出拳:1.剪刀 2.石头 3.布 (输入相应数字):"); int num=input.nextInt(); switch(num){ case 1: nide="剪刀"; break; case 2: nide="石头"; break; case 3: nide="布"; break; } System.out.println("你的出拳:"+nide); String chuquan="null"; int num2=(int)(Math.random()*3); while(num2<=0){ num2=(int)(Math.random()*3); } switch(num2){ case 1: chuquan="剪刀"; break; case 2: chuquan="石头"; break; case 3: chuquan="布"; break; } System.out.println("刘备出拳:"+chuquan); if(nide.compareToIgnoreCase(chuquan)>0){ System.out.println("您赢了!真棒!"); personCount++; }else if(nide.compareToIgnoreCase(chuquan)<0){ System.out.println("您输了,下次加油!"); computerCount++; }else{ System.out.println("平手,不错哟!"); } count++; } System.out.println("是否开始下一轮 (y/n):"); String answer1=input.next(); while("y".equals(answer1)){ String ni="null"; System.out.println("请选择出拳:1.剪刀 2.石头 3.布 (输入相应数字):"); int num1=input.nextInt(); switch(num1){ case 1: ni="剪刀"; break; case 2: ni="石头"; break; case 3: ni="布"; break; } System.out.println("你的出拳:"+ni); String chuquan="null"; int num2=(int)(Math.random()*3); while(num2<=0){ num2=(int)(Math.random()*3); } switch(num2){ case 1: chuquan="剪刀"; break; case 2: chuquan="石头"; break; case 3: chuquan="布"; break; } System.out.println("刘备出拳:"+chuquan); if(ni.compareToIgnoreCase(chuquan)>0){ System.out.println("您赢了!真棒!"); personCount++; }else if(ni.compareToIgnoreCase(chuquan)<0){ System.out.println("您输了,下次加油!"); computerCount++; }else{ System.out.println("平手,不错哟!"); } System.out.println("是否开始下一轮 (y/n):"); answer1=input.next(); count++;                        
    }           System.out.println("要开始下一轮吗? (y/n)");
           String answer=input.next();
    } while("y".equals(answer1); public void showResult(){ String person="王潇璐"; System.out.println("-----------------------------------------"); System.out.println(computer+"vs"+person); System.out.println("对战次数:"+count); if(computerCount>personCount){ System.out.println("结果:您输了,下次加油哟!"); }else if(computerCount==personCount){ System.out.println("结果:平手,下次干掉它!"); }else{ System.out.println("您赢了,真棒!不要骄傲哟!"); } } }

      这是调试类:

    public class Test {
    
    	public static void main(String[] args) {
    		startGame center=new startGame();
    		center.startbefore();
    		center.showResult();
    		
    	}
    
    }
    

      

  • 相关阅读:
    使用C语言实现面相对对象三大特性
    ResNet王者归来:ImageNet上刷新到80.7!
    VAE生成模型
    DeeplabV3++语义分割训练自制数据集
    CUDA编程入门极简教程
    加载预训练模型修改类别数与不修改类别数
    python使用opencv将Labelme生成的分割图转化成二值化分割图
    pytorch 单卡加载多卡模型module
    【pytorch】常用图像处理与数据增强方法合集(torchvision.transforms)(详细)
    C++11:原子交换函数compare_exchange_weak和compare_exchange_strong
  • 原文地址:https://www.cnblogs.com/huanghui-1243/p/7357377.html
Copyright © 2020-2023  润新知