javaOOP项目 QuickHit

来源:互联网 发布:高中辅导视频软件 编辑:程序博客网 时间:2024/04/26 23:31
package cn.quickhit;import org.junit.Test;public class MyTest {@Testpublic void testInfo(){Game game=new Game();game.compareInputCharAndOutPutChar("", "");}}

package cn.quickhit;import java.util.Random;import org.junit.Test;public class Game {//被人玩90Player player;public Game(Player player){this.player=player;}public Game(){}//生成字符串public String getStr(){StringBuffer buffer=new StringBuffer();Random ran=new Random();//strLength  2int 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("恭喜!完成了所有关卡");System.exit(1);}}}}

package cn.quickhit;public class Level {//等级private int levelNo;//字符出现几次private int strCount;//字符串的长度private int strLength;//分数private int score;//重置时间private int time;public Level() {super();// TODO Auto-generated constructor stub}public int getLevelNo() {return levelNo;}public void setLevelNo(int levelNo) {this.levelNo = levelNo;}public int getStrCount() {return strCount;}public void setStrCount(int strCount) {this.strCount = strCount;}public int getStrLength() {return strLength;}public void setStrLength(int strLength) {this.strLength = strLength;}public int getScore() {return score;}public void setScore(int score) {this.score = score;}public int getTime() {return time;}public void setTime(int time) {this.time = time;}public Level(int levelNo, int strCount, int strLength, int score, int time) {super();this.levelNo = levelNo;this.strCount = strCount;this.strLength = strLength;this.score = score;this.time = time;}}

package cn.quickhit;public class LevelParam {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);}}

package cn.quickhit;import java.util.Scanner;public class Player {//玩家玩的是   第几关?private int levelNo;//第几关   开始的     时间 private long strTime;//当前关卡    目前积分数private int scores;//该关卡已经耗时  多长时间。private int elapsedTime;public void Play(){//this:    Game game=new Game(this);Scanner input = new Scanner(System.in);for(int i=0;i<LevelParam.levels.length;i++){//等级+1this.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);}}}public int getLevelNo() {return levelNo;}public void setLevelNo(int levelNo) {this.levelNo = levelNo;}public long getStrTime() {return strTime;}public void setStrTime(int strTime) {this.strTime = strTime;}public int getScores() {return scores;}public void setScores(int scores) {this.scores = scores;}public int  getElapsedTime() {return elapsedTime;}public void setElapsedTime(int elapsedTime) {this.elapsedTime = elapsedTime;}}

package cn.quickhit;public class TestQK {public static void main(String[] args) {Player player=new Player();player.Play();}}

1 0
原创粉丝点击