package com.kotei.java.renjicaiquan;
import java.util.Scanner;
public class Game {
int times;
public void initial(){
System.out.println(" -------------------------------------------------欢迎进入游戏世界---------------------------------------");
System.out.println(" ************************");
System.out.println(" ******** 人机猜拳 ******");
System.out.println(" ************************");
System.out.println("出拳规则:1.剪刀 2.石头 3.布");
}
public void startGame(){
boolean flag=false;
boolean flag2=false;
Scanner sc=new Scanner(System.in);
Users u=new Users();
Computer c=new Computer();
do{
int count=1;
System.out.print("请选择对方角色(1.刘备 2.孙权 3.曹操)");
int num=sc.nextInt();
System.out.print("请输入你的姓名:");
u.uName=sc.next();
switch(num){
case 1:
c.cName="刘备";
break;
case 2:
c.cName="孙权";
break;
case 3:
c.cName="曹操";
break;
}
System.out.println(" "+u.uName+" VS "+ c.cName);
System.out.print("要开始吗?(y/n)");
if(sc.next().equalsIgnoreCase("y")){
do{
int a=u.chuQuan(); //用户出拳
int b=c.chuQuan();//电脑出拳
if(a==b){
System.out.println("平局!");
}else if(a==1){
if(b==2){
System.out.println("你输了!");
c.cScore++;//电脑得分
}else if(b==3){
System.out.println("你赢了!");
u.uScore++;//用户得分
}
}else if (a==2){
if(b==1){
System.out.println("你赢了!");
u.uScore++;
}else if(b==3){
System.out.println("你输了!");
c.cScore++;
}
}else{
if(b==1){
System.out.println("你输了!");
c.cScore++;
}else if(b==2){
System.out.println("你赢了!");
u.uScore++;
}
}
System.out.println("--------------------------------------------");
System.out.print("是否进入下一轮?(y/n)");
if(sc.next().equalsIgnoreCase("y")){
flag=true;
}else{
System.out.println(" "+u.uName+" VS "+ c.cName);
System.out.println("对战次数:"+count);
System.out.println("姓名\t得分");
System.out.println(u.uName+"\t"+u.uScore);
System.out.println(c.cName+"\t"+c.cScore);
if(u.uScore<c.cScore){
System.out.println("呵呵,你太笨了,下次加油!");
}else if(u.uScore==c.cScore){
System.out.println("打个平手,小样!");
}else{
System.out.println("运气不错,可以去买彩票了!");
}
System.out.println("----------------------------------------------");
System.out.print("是否重新选人?(y/n)");
if(sc.next().equalsIgnoreCase("y")){
u.uScore=0;//得分清零
c.cScore=0;//得分清零
flag2=true;
flag=false;
}else{
System.out.println("你已退出游戏!");
System.exit(0);
}
}
count++;//对战次数
}while(flag);
}else{
System.out.println("你已退出游戏!");
System.exit(0);
}
}while(flag2);
}
}