import java.util.Scanner; public class game_test1 { public static void main(String[] args) { String player_name; String com_name; int player_choice; int com_choice; String player_choice_name; String com_choice_name; System.out.println("**************************************"); System.out.println("*********欢迎来到石头剪刀布游戏*********"); System.out.println("**************************"); System.out.print("欢迎进入本游戏,请输入玩家游戏名字:"); Scanner scanner = new Scanner(System.in); player_name = scanner.nextLine(); if (player_name.trim().equals("")){ player_name = "匿名用户"; } System.out.println("*************************************"); System.out.println("请选择对战的电脑:"); System.out.println("1------戴拿奥特曼"); System.out.println("2------赛罗奥特曼"); System.out.println("3------zero2"); String com_no = scanner.nextLine(); if (com_no.equals("1")){ com_name = "戴拿奥特曼"; } else if (com_no.equals("2")){ com_name = "赛罗奥特曼"; }else if (com_no.equals("3")){ com_name = "zero2"; } else { com_name = "匿名用户"; } System.out.println("*************************************"); System.out.println("请选择你要出的代号:"); System.out.println("1--------石头"); System.out.println("2--------剪刀"); System.out.println("3--------布"); String temp_choice = scanner.next(); if (temp_choice.equals("1") || temp_choice.equals("2") || temp_choice.equals("3")){ player_choice = Integer.parseInt(temp_choice); } else { player_choice = (int)Math.round(Math.random()*2+1); } if (player_choice == 1){ player_choice_name = "石头"; } else if (player_choice == 1){ player_choice_name = "剪刀"; } else { player_choice_name = "布"; } com_choice = (int)Math.round(Math.random()*2+1); if (com_choice == 1){ com_choice_name = "石头"; } else if (com_choice == 1){ com_choice_name = "剪刀"; } else { com_choice_name = "布"; } if (player_choice - com_choice == 1 || player_choice - com_choice == -2){ System.out.println("玩家"+ player_name+"出:"+player_choice_name+",赢"); System.out.println("电脑"+com_name+"出:"+com_choice_name+",输"); } else if (com_choice - player_choice == 1 || com_choice - player_choice == -2){ System.out.println("电脑"+com_name+"出:"+com_choice_name+",赢"); System.out.println("玩家"+ player_name+"出:"+player_choice_name+",输"); } else { System.out.println("玩家"+ player_name+"出:"+player_choice_name+",平局"); System.out.println("电脑"+com_name+"出:"+com_choice_name+",平局"); } } }