package com.dasenlin.xunwu;
public class Test {
public static void main(String[] args) {
Player player = new Player();
player.play();
}
}
package com.dasenlin.xunwu;
import java.util.Scanner;
public class Player {
private int levelNo;
private int curScore;
private long startTime;
private int elaasedTime;
public Player() {
this.levelNo = 1;
this.curScore = 0;
this.startTime = 0;
this.elaasedTime = 0;
}
public int getLevelNo() {
return levelNo;
}
public void setLevelNo(int levelNo) {
this.levelNo = levelNo;
}
public int getCurScore() {
return curScore;
}
public void setCurScore(int curScore) {
this.curScore = curScore;
}
public long getStartTime() {
return startTime;
}
public void setStartTime(long startTime) {
this.startTime = startTime;
}
public int getElaasedTime() {
return elaasedTime;
}
public void setElaasedTime(int elaasedTime) {
this.elaasedTime = elaasedTime;
}
public void play(){
Game game = new Game(this);
Scanner scan = new Scanner(System.in);
int levelsLength=LevelParam.levels.length;
for(int i=0;i<levelsLength;i++){
int levelCount=LevelParam.levels[levelNo-1].getLevelCount();
this.setElaasedTime(0);
for(int j=0;j<levelCount;j++){
long currentTime = System.currentTimeMillis();
this.startTime=currentTime;
String autoStr=game.printStr();
System.out.println(autoStr);
String playStr=scan.next();
game.printResult(autoStr, playStr);
}
levelNo++;
}
}
}
package com.dasenlin.xunwu;
public class Game {
Player player;
public Game(Player player) {
this.player = player;
}
public String printStr(){
String str="";
int strLength=LevelParam.levels[player.getLevelNo()-1].getStrlength();
String [] arr={">","<","*","&","%","#","$"};
for(int i=0;i<strLength;i++){
int index = (int)(Math.random()*strLength);
str=str+arr[index];
}
return str;
}
public void printResult(String out,String in){
if(in.equals(out)){
if(player.getElaasedTime()>LevelParam.levels[player.getLevelNo()-1].getLevelTime()){
System.out.println("你输入太慢了,已经超时");
printError();
}else{
player.setCurScore(player.getCurScore()+LevelParam.levels[player.getLevelNo()-1].getLeverScore());
int elapsedTime=(int)(System.currentTimeMillis()-player.getStartTime())/1000;
player.setElaasedTime(player.getElaasedTime()+elapsedTime);
System.out.println("你通过了"+(player.getLevelNo()-1)+"关,玩家对应的积分"+player.getCurScore()+"消耗了"+player.getElaasedTime()+"秒");
/*if(){
}*/
}
}else{
System.out.println("你输入有误");
printError();
}
}
public void printError(){
System.out.println("你通过了"+(player.getLevelNo()-1)+"关,玩家对应的积分"+player.getCurScore());
System.out.println("谢谢使用");
System.exit(0);
}
}
package com.dasenlin.xunwu;
public class Level {
private int levelNo;
private int strlength;
private int levelCount;
private int levelTime;
private int leverScore;
public Level() {
super();
}
public Level(int levelNo, int strlength, int levelCount, int levelTime, int leverScore) {
super();
this.levelNo = levelNo;
this.strlength = strlength;
this.levelCount = levelCount;
this.levelTime = levelTime;
this.leverScore = leverScore;
}
public int getLevelNo() {
return levelNo;
}
public void setLevelNo(int levelNo) {
this.levelNo = levelNo;
}
public int getStrlength() {
return strlength;
}
public void setStrlength(int strlength) {
this.strlength = strlength;
}
public int getLevelCount() {
return levelCount;
}
public void setLevelCount(int levelCount) {
this.levelCount = levelCount;
}
public int getLevelTime() {
return levelTime;
}
public void setLevelTime(int levelTime) {
this.levelTime = levelTime;
}
public int getLeverScore() {
return leverScore;
}
public void setLeverScore(int leverScore) {
this.leverScore = leverScore;
}
}
package com.dasenlin.xunwu;
public class LevelParam {
public 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,12,12);
}
}