• 什么也不会系列之人机猜拳


    import java.util.Scanner;
    
    public class caiquan_1 {
    	yonghulie person;
    	jisuanjilie computer;
    	int count;
    
    	public void initial() {
    		person = new yonghulie();
    		computer = new jisuanjilie();
    		count = 0;
    	}
    
    	public void show() {
    		System.out
    				.println("---------------------欢迎进入游戏世界-------------------------------
    ");
    		System.out.println("		******************");
    		System.out.println("		**  猜拳,开始  **");
    		System.out.println("		******************
    
    ");
    		count = 0;
    	}
    
    	public void Game() {
    		initial();
    		Scanner input = new Scanner(System.in);
    		System.out.println("出拳规则:1.剪刀2.石头3.布");
    		System.out.println("请选择对方角色(1.刘备2.孙权3.曹操):");
    		int js = input.nextInt();
    		switch (js) {
    		case 1:
    			computer.namej = "刘备";
    			break;
    		case 2:
    			computer.namej = "孙权";
    
    			break;
    		case 3:
    			computer.namej = "曹操";
    
    			break;
    
    		}
    		System.out.print("请输入你的姓名:");
    		person.name = input.next();
    		System.out.println(person.name + "  VS  " + computer.namej + "  对战
    ");
    		System.out.println("要开始吗?(y/n)");
    		String kai = input.next();
    		int PerFist ;//你出拳
    		int compFist ;//人机出拳
    		while (kai.equals("y")) {
    			PerFist = person.showy();
    			compFist = computer.showj();
    			if ((PerFist == 1 && compFist == 1)
    					|| (PerFist == 2 && compFist == 2)
    					|| (PerFist == 3 && compFist == 3)) {
    				System.out.println("结果:和局,真衰!
    ");
    			} else if ((PerFist == 1 && compFist == 3)
    					|| (PerFist == 2 && compFist == 1)
    					|| (PerFist == 3 && compFist == 2)) {
    				System.out.println("结果: 恭喜, 你赢了!");
    				person.score++;
    			} else {
    				System.out.println("结果说:^_^,你输了
    ");
    				computer.score++;
    			}
    			count++;
    			System.out.print("
    是否开始下一轮(y/n):  ");
    			kai = input.next();
    		}
    		jieguo();
    		fang();
    
    	}
    	public void jieguo(){
    		System.out.println("---------------------------------------------------");
    		System.out.println(computer.namej + "  VS  " + person.name);
    		System.out.println("对战次数:"+ count);
    		System.out.println("
    姓名	得分");		
    		System.out.println(person.name+"	"+person.score);
    		System.out.println(computer.namej+"	"+computer.score+"
    ");
    		int result = fang();
    		if(result == 1){
    			System.out.println("结果:打成平手,下次再和你一分高下!");
    		}else if(result == 2){
    			System.out.println("结果:恭喜恭喜!"); 
    		}else{ 
    			Syst
    import java.util.Scanner;
    
    
    public class jisuanjilie {
    	String namej="电脑";
    	 int score = 0;
    	public int showj(){
    			int cq=(int)(Math.random()*3);
    			
    			switch (cq){
    			case 1:
    				System.out.println(namej+"出拳:剪刀");
    				break;
    			case 2:
    				System.out.println(namej+"电脑出拳:石头");
    				break;
    			case 3:
    				System.out.println(namej+"电脑出拳:布");
    				break;
    			}
    			
    			return cq;
    	}
    }
    

      

    import java.util.Scanner;
    
    public class yonghulie {
    	String name = "匿名"; 
        int score = 0; 
    
    	public int showy() {
    		Scanner A=new Scanner(System.in);
    		System.out.println("请出拳:1.剪刀2.石头3.布(输入相应数字):");
    		int cq=A.nextInt();
    		switch (cq){
    		case 1:
    			System.out.println("你出拳:剪刀");
    			break;
    		case 2:
    			System.out.println("你出拳:石头");
    			break;
    		case 3:
    			System.out.println("你出拳:布");
    			break;
    		}
    		return cq;
    		
    	}
    }
    

      

    public class caiquan {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		caiquan_1 N= new caiquan_1();
    		N.Game();
    		
    	}
    
    }
    

      

    em.out.println("结果:呵呵,笨笨,下次加油啊!"); } System.out.println("---------------------------------------------------"); } public int fang(){ if(person.score == computer.score){ return 1; }else if(person.score > computer.score){ return 2; }else{ return 3; } } }

      

  • 相关阅读:
    Adobe Illustrator CS6 界面文字按钮太小,高分屏win10PS/AI等软件界面字太小解决方法
    暗网,又称深网。据估计,暗网比表面网站大几个数量级。
    HexDump.java解析,android 16进制转换
    excel第一次打开报错 向程序发送命令时出错 多种解决办法含终极解决方法
    小黄人IP营销的四种玩法思维导图
    Window下PHP三种运行方式图文详解,window下的php是不是单进程的?
    全球海底光缆分布图
    redis删除单个key和多个key,ssdb会落地导致重启redis无法清除缓存
    图解人工智能机器学习深度学习的关系和区别
    B轮公司技术问题列表
  • 原文地址:https://www.cnblogs.com/n6666/p/7359066.html
Copyright © 2020-2023  润新知