import java.util.Scanner; public class caiquan { public static void main(String[] args) { String player_name; String com_name; int player_choice; int com_choice; System.out.println("**********************************"); System.out.println(" 游戏:剪刀石头布"); System.out.println(" 作者:zgd"); System.out.println(" 版本:v1.0"); System.out.println("*********************************"); System.out.println("欢迎进入本游戏,请输出游戏玩家的名字:"); Scanner scanner = new Scanner(System.in); player_name=scanner.nextLine(); System.out.println("********************************"); System.out.println("1-----电坤小子"); System.out.println("2-----电坤老子"); System.out.println("*********************************"); String com_no=scanner.next(); if (com_no.equals("1")){ com_name="电坤小子"; }else if(com_no.equals("2")){ com_name="电坤老子"; }else{ com_name="匿名用户"; } System.out.println("****请玩家选择出拳的代表数字*********"); System.out.println("1------剪刀"); System.out.println("2------石头"); System.out.println("3------布"); System.out.println("*********************************"); player_choice=scanner.nextInt(); com_choice=(int)Math.round(Math.random()*2+1); if(player_choice-com_choice==1 || player_choice-com_choice==-2){ System.out.println("玩家:"+player_name+"赢"); }else if(com_choice-player_choice==1 || com_choice-player_choice==-2){ System.out.println("电脑:"+com_name+"赢"); }else{ System.out.println("平局"); } } }
Java程序设计(3)(猜拳程序)
最新推荐文章于 2024-11-11 21:19:25 发布