package back;
public class LevelParam {
public final static Level levels[]=new Level[6]; //对应六个级别
static {
levels[0]=new Level(1, 2, 10, 30, 1);
levels[1]=new Level(2, 3, 9, 26, 2);
levels[2]=new Level(3, 4, 8, 22, 5);
levels[3]=new Level(4, 5, 7, 18, 8);
levels[4]=new Level(5, 6, 6, 15, 10);
levels[5]=new Level(6, 7, 5, 22, 15);
}
}
package back;
import java.util.Scanner;
public class Player {
//玩家类
private int leveINo; //玩家当前级别号
private int currScore; //玩家当前级别积分
private long startTime; //玩家级别开始时间
private int elapsedTime; //当前级别已用时间
public int getLeveINo() {
return leveINo;
}
public void setLeveINo(int leveINo) {
this.leveINo = leveINo;
}
public int getCurrScore() {
return currScore;
}
public void setCurrScore(int currScore) {
this.currScore = currScore;
}
public long getStartTime() {
return startTime;
}
public void setStartTime(long startTime) {
this.startTime = startTime;
}
public int getElapsedTime() {
return elapsedTime;
}
public void setElapsedTime(int elapsedTime) {
this.elapsedTime = elapsedTime;
}
public void pay(){
Game game=new Game(this);
Scanner input=new Scanner(System.in);
for (int i = 0; i < LevelParam.levels.length; i++) {
//晋级
this.leveINo+=1;
//晋级后清零,积分清零
this.startTime=System.currentTimeMillis();
this.currScore=0;
//内层循环,循环一次完成一次字符串的输入,输出
for (int j = 0; j < LevelParam.levels[leveINo-1].getStrTimes(); j++) {
//输出游戏字符串
String outt=game.printStr();
System.out.println(outt);
//接受用户输入
String inr=input.next();
//游戏判断玩家是否输入正确,并输入相应结果信息
game.printResult(outt, inr);
}
}
}
public static long getStrTimes() {
// TODO Auto-generated method stub
return 0;
}
}
package back;
public class Level {
private int leveINo;
private int strLength;
private int strTimes;
private int timeLimit;
private int perScore;
public Level(int leveINo, int strLength, int strTimes, int timeLimit,
int perScore) {
super();
this.leveINo = leveINo;
this.strLength = strLength;
this.strTimes = strTimes;
this.timeLimit = timeLimit;
this.perScore = perScore;
}
public Level() {
super();
// TODO Auto-generated constructor stub
}
public int getLeveINo() {
return leveINo;
}
public void setLeveINo(int leveINo) {
this.leveINo = leveINo;
}
public int getStrLength() {
return strLength;
}
public void setStrLength(int strLength) {
this.strLength = strLength;
}
public int getStrTimes() {
return strTimes;
}
public void setStrTimes(int strTimes) {
this.strTimes = strTimes;
}
public int getTimeLimit() {
return timeLimit;
}
public void setTimeLimit(int timeLimit) {
this.timeLimit = timeLimit;
}
public int getPerScore() {
return perScore;
}
public void setPerScore(int perScore) {
this.perScore = perScore;
}
}
package back;
import java.sql.Time;
import java.util.Random;
public class Game{
public Player player;
public Game(Player player)
{
this.player=player;
}
public String printStr(){
int strlth=LevelParam.levels[player.getLeveINo()-1].getStrLength();
StringBuffer buff=new StringBuffer();
Random re=new Random();
//通过循环生成要输出的字符串
for (int i = 0; i < strlth;i++) {
//产生随机数
int rand=re.nextInt(strlth);
//根据随机数拼接字符串
switch(rand){
case 0:
buff.append(">");
break;
case 1:
buff.append("<");
break;
case 2:
buff.append("*");
break;
case 3:
buff.append("&");
break;
case 4:
buff.append("%");
break;
case 5:
buff.append("#");
break;
}
}
return buff.toString();
}
public void printResult(String out,String in){
if(out.equals(in)){
long time=System.currentTimeMillis();
//如果超时
if((time-player.getStartTime())/1000>LevelParam.levels[player.getLeveINo()-1].getTimeLimit()){
System.out.println("你输入太慢,已经超时,退出");
System.exit(1);
}else{
//计算玩家当前积分
player.setCurrScore(player.getCurrScore()+LevelParam.levels[player.getLeveINo()-1].getPerScore());
player.setElapsedTime((int)(time-player.getStartTime())/1000);
int leveno=player.getLeveINo();
int score=player.getCurrScore();
int Time=player.getElapsedTime();
System.out.println("输入正确,您的级别"+leveno+",您的积分"+score+",已用时间"+Time+"秒");
if(leveno==6){
System.out.println("游戏结束!");
System.exit(1);
}
}
}else{
System.out.println("输入错误,退出!");
System.exit(1);
}
}
}
package back;
public class Text {
/**
* @param args
*/
public static void main(String[] args) {
Player pp=new Player();
pp.pay();
}
}