//生成字符串
public String getStr(){
StringBuffer buffer=new StringBuffer();
Random ran=new Random();
//strLength 2
int strLength=LevelParam.levels[player.getLevelNo()-1].getStrLength();
for (int i = 0; i < strLength; i++) {
//(0,1)
int rand=ran.nextInt(strLength);
//根据输入的拼接的符号
switch (rand) {
case 0:
buffer.append(">");
break;
case 1:
buffer.append("<");
break;
case 2:
buffer.append("*");
break;
case 3:
buffer.append("&");
break;
case 4:
buffer.append("%");
break;
case 5:
buffer.append("#");
break;
}
}
System.out.println(buffer);
return buffer.toString();
}
public void compareInputCharAndOutPutChar(String out,String in){
long currentTime = System.currentTimeMillis();
if(!out.equals(in)){
//系统抛出的字符 和 用户录入的不一致
System.out.println("输入错误");
System.exit(1);
}else{
//超时 //系统抛出的字符 和 用户录入的一致
//player.getStrTime() 玩家该关卡 开始的时间
//LevelParam.levels[player.getLevelNo()-1].getTime() 用时间的上限
if((currentTime-player.getStrTime())/1000>LevelParam.levels[player.getLevelNo()-1].getTime()){
System.out.println("超时了你的手速还不够!");
System.exit(1);
}else {
//当前关卡 目前总分数 ========原始累计分数+本次分数
//LevelParam.levels[player.getLevelNo()-1].getScore() 该等级游戏字符 。输入正确一次获得的分数
player.setScores(player.getScores()+LevelParam.levels[player.getLevelNo()-1].getScore());
//耗时
long alreadyusetime=(int)(currentTime-player.getStrTime())/1000;
int result=(int)alreadyusetime;
player.setElapsedTime(result);
//获取到当前玩家的等级编号
int level=player.getLevelNo();
//获取当前玩家该关卡的目前总分数
int scores=player.getScores();
//获取当前玩家该关卡已用时间
int usetime= player.getElapsedTime();
System.out.println("等级为:"+level+"积分为:"+scores+"所用时间:"+usetime);
if (level==6) {
System.out.println("你很牛x,完成了所有关卡!");
System.exit(1);
}
}
}
public final static Level levels[]=new Level[6];
static{
levels[0]=new Level(1,10,2,1,30);
levels[1]=new Level(2,9,3,2,26);
levels[2]=new Level(3,8,4,5,22);
levels[3]=new Level(4,7,5,8,18);
levels[4]=new Level(5,6,6,10,14);
levels[5]=new Level(6,5,7,15,10);
}
public final static Level levels[]=new Level[6]; static{ levels[0]=new Level(1,10,2,1,30); levels[1]=new Level(2,9,3,2,26); levels[2]=new Level(3,8,4,5,22); levels[3]=new Level(4,7,5,8,18); levels[4]=new Level(5,6,6,10,14); levels[5]=new Level(6,5,7,15,10); }
[sql]view plaincopy
print?
public void Play(){
//this:
Game game=new Game(this);
Scanner input = new Scanner(System.in);
for(int i=0;i<LevelParam.levels.length;i++){
//等级+1
this.levelNo+=1;
//积分清零 时间清零
this.strTime=System.currentTimeMillis();
this.scores=0;
//二重循环次数 控制 字符 出现几次??
for(int j=0;j<LevelParam.levels[levelNo-1].getStrCount();j++)
{
//获取系统抛出的字符串内容
String outString=game.getStr();
String inString=input.next();
game.compareInputCharAndOutPutChar(outString, inString);
//接收用户从keyboard中录入的字符串内容
//comparexxxxx