通过构建玩家类,计算机类,游戏类,三个类,实现了简单的人机猜拳小游戏。
/**
* @author 万星明
* @version 创建时间:2018年10月20日 下午3:01:09
* 计算机类
*/
public class Computer {
public static String name = "计算机";
public static int score = 0;
//出拳方法
public static int finger() {
int data = (int)(Math.random()*3+1);
switch(data) {
case 1:
System.out.println(name+"出拳:剪刀");
break;
case 2:
System.out.println(name+"出拳:石头");
break;
case 3:
System.out.println(name+"出拳:布");
break;
}
return data;
}
}
import java.util.Scanner;
/**
* @author 万星明
* @version 创建时间:2018年10月20日 下午2:46:49
* 用户类
*/
public class User {
static Scanner sc = new Scanner(System.in);
public static String name = "万星明";
public static int score=0;
//出拳方法
public static int finger() {
System.out.println("请出拳:1.剪刀 2.石头 3.布(输入相应数字):");
int data = sc.nextInt();
switch(data) {
case 1:
System.out.println("你出拳:剪刀");
break;
case 2:
System.out.p