this.morraType = morraType;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public Player(String name, int morraType, int score) {
super();
this.name = name;
this.morraType = morraType;
this.score = score;
}
public Player() {
super();
}
}
7package game;
import java.util.Scanner;
public class Morra {
public static void printType(int g) {
switch(g) {
case 1:
System.out.println("铰剪");
break;
case 2:
System.out.println("石头");
break;
case 3:
System.out.println("布");
break;
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Player player=new Player();
Player computer=new Player();
System.out.println("出拳法则:1.铰剪,2.石头,3.布");
System.out.println("请选择用户脚色:1.张飞,2.曹操,3徐庶");
Scanner s=new Scanner(System.in);
int a=s.nextInt();
switch(a) {
case 1:
computer.setName("张飞");
break;
case 2:
computer.setName("曹操");
break;
case 3:
computer.setName("徐庶");
break;
default:
System.out.println("用户不决义名称,此刻界说机械名称为电脑");
computer.setName("电脑");
break;
}
System.out.println("请输入你的姓名:");
Scanner sc=new Scanner(System.in);
player.setName(sc.nextLine());
System.out.println(""+player.getName()+" VS "+computer.getName());
boolean flag=false;
do {
System.out.println("请出拳,出拳法则:1.铰剪,2.石头,3.布");
Scanner ssc=new Scanner(System.in);
int play=ssc.nextInt();
int compute=(int)(Math.random()*3+1);
switch(play){
case 1:
switch(compute)
{
case 1:
break;
case 2:
computer.score++;
break;
case 3:
player.score++;
break;
}
break;
case 2:
switch(compute)
{
case 1:
player.score++;
break;
case 2:
break;
case 3:
computer.score++;
break;
}
break;
case 3:
switch(compute)
{
case 1:
computer.score++;
break;
case 2:
player.score++;
break;
case 3:
break;
}
break;
default:
System.out.println("未知数据,本场不积分");
break;
}
System.out.print("玩家出拳:");
printType(play);
System.out.print("电脑出拳:");
printType(compute);
System.out.println(player.getName()+":"+player.getScore());
System.out.println(computer.getName()+":"+computer.getScore());
System.out.println("是否继续?(Y/N)");
Scanner sss=new Scanner(System.in);
String check=sss.nextLine();
if(check.equals("Y")||check.equals("y"))
{
flag=true;
}
else if(check.equals("N")||check.equals("n"))
{
flag=false;
}
else
{
System.out.println("异常输入,法式退出");
break;
}
System.out.println("-------------------------------------");
}while(flag);
}
}
推荐阅读
- 第一次获得诺贝尔奖的科学家是哪个国家的人 第一个获得诺贝尔奖的科学家是哪个国家的
- 称重图标设计
- 如何做糯米粽子
- 发面葱花饼的做法
- 黄金荔枝酒的做法
- 地球要开始自我免疫了吗?
- 抖音怎么实名认证
- 清明踏青手抄报怎么画简单
- 怎么做碱粽好吃
- 端午肉粽怎么做