快速击键(MyEclipse编写的QuickHit项目)

来源:互联网 发布:音效软件 编辑:程序博客网 时间:2024/05/18 05:48
复制代码
public class Level {    private int levelNo;// 各级别编号    private int strLength;// 各级别一次输出字符串的长度    private int strTimes;// 各级别输出字符串的次数    private int timeLimit;// 各级别闯关的时间限制    private int perScore;// 各级别正确输入一次的得分    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 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;    }    public  Level() {        super();    }    public Level(int levelNo, int strLength, int strTimes, int timeLimit,            int perScore) {        super();        this.levelNo = levelNo;        this.strLength = strLength;        this.strTimes = strTimes;        this.timeLimit = timeLimit;        this.perScore = perScore;    }}
复制代码
复制代码
import java.util.Scanner;/** * 玩家类 * @author accp * */public class Player {    private int levelNo;   //等级    private int curScore;   //积分    private int elapsedTime; //已用时间    private long startTime;  //开始时间            public Player() {            }            public Player(int levelNo, int curScore, int elapsedTime, long startTime) {        this.levelNo = levelNo;        this.curScore = curScore;        this.elapsedTime = elapsedTime;        this.startTime = startTime;    }    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 int getElapsedTime() {        return elapsedTime;    }    public void setElapsedTime(int elapsedTime) {        this.elapsedTime = elapsedTime;    }    public long getStartTime() {        return startTime;    }    public void setStartTime(long startTime) {        this.startTime = startTime;    }        public void play()    {        Game game=new Game(this);//this代表已经创建了的对象引用player        //外层循环,循环一次级别进一级        for (int i = 0; i < LevelParam.levels.length; i++) {            this.levelNo+=1;            //晋级后,记时清零,积分清零            this.startTime=System.currentTimeMillis();            this.curScore=0;            //内层循环,循环一次完成一次字符串的输出,输入,比较。它的限制参数是输出字符串的次数            for (int j = 0; j <LevelParam.levels[levelNo-1].getStrTimes(); j++) {                String outstr=game.printStr();//游戏输出字符串                System.out.println(outstr);                Scanner input=new Scanner(System.in);                String instr=input.next();                game.printResult(outstr, instr);            }                    }    }}
复制代码
复制代码
import java.util.Date;import java.util.Random;/** * 游戏类 * @author accp * */public class Game {    private Player player;    public Game() {            }        public Game(Player player) {        this.player = player;    }    public Player getPlayer() {        return player;    }    public void setPlayer(Player player) {        this.player = player;    }        //输出字符串用于和玩家的输入进行比较    public String printStr()    {        //获取当前玩家级别的字符串长度        int strLength=LevelParam.levels[player.getLevelNo()-1].getStrLength();        StringBuffer buffer=new StringBuffer();        Random random=new Random();        for (int i = 0; i < strLength; i++) {            int rand=random.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;            default:                break;            }                    }        String result=buffer.toString();        return result;    }    //比较结果,输出相应信息    public void printResult(String out,String in)    {        if (out.equals(in)) {            //正确输入            Date date=new Date();            long currentTime=date.getTime();            //如果超时            long closeTime=LevelParam.levels[player.getLevelNo()-1].getTimeLimit();            if ((currentTime-player.getStartTime())/1000>closeTime) {                System.out.println("你输入的太慢了,已经超时,退出!");                System.exit(1);            }            else            {                //计算当前玩家积分                //所有的积分相加            player.setCurScore(player.getCurScore()+LevelParam.levels[player.getLevelNo()-1].getPerScore());            int score=player.getCurScore();//获取数组内的开始积分            int time=(int)(currentTime-player.getStartTime())/1000;//获取时间差            player.setElapsedTime(player.getElapsedTime()+time);            int alltime=player.getElapsedTime();            int no=player.getLevelNo();            System.out.println("输入正确,您的级别"+no+",您的积分"+score+",已用时间"+alltime+"");            }        }else{            System.out.println("输入错误 !!!,退出");            System.exit(1);            }                                }}
复制代码
复制代码
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,12,15);     }}
复制代码
复制代码
public class Test {    public static void main(String[] args) {                Player player=new Player();        player.play();}}
复制代码

 

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 孕牙龈肿痛出血怎么办 孕期牙龈肿痛出血怎么办 牙龈肿痛还出血怎么办 上牙龈肿痛出血怎么办 孕妇牙龈肿痛出血怎么办 牙痛一个月不好怎么办 肛裂一个月没好怎么办 哺乳期便血肛裂怎么办 哺乳期肛裂严重怎么办 哺乳期肛裂出血怎么办 哺乳期痔疮肛裂怎么办 肛裂屁股疼怎么办 哺乳期肛裂了怎么办 肛裂疼起来真要命!怎么办? 肛裂出血疼怎么办 痔疮火辣辣的疼怎么办 学生小腹部突出怎么办 去北海玩下雨怎么办 抓嫖异地传唤怎么办 头顶太尖不好看怎么办 受到家暴离婚怎么办 被电打了身体痛怎么办 被电麻了手臂痛怎么办 被电伤之后很痛怎么办 电旱打眼睛红痛怎么办 从心底厌恶老公怎么办 欠债还不起了怎么办 生孩子先破羊水怎么办 丈夫网贷妻子怎么办 丈夫不能包容妻子怎么办 丈夫卷钱跑了 妻子怎么办 白色鞋子染色了怎么办 真丝衣服起静电怎么办 新买的网鞋太硬怎么办 运动鞋鞋面太硬怎么办 仙人球的刺扎进肉里面怎么办 军人优先被拒绝怎么办 晋江小说防盗章怎么办 小说设置了防盗怎么办 军训帽子太小怎么办 电脑不显示桌面图标怎么办