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 = ; i < LevelParam.levels.length; i++) {
this.levelNo+=;
//晋级后,记时清零,积分清零
this.startTime=System.currentTimeMillis();
this.curScore=;
//内层循环,循环一次完成一次字符串的输出,输入,比较。它的限制参数是输出字符串的次数
for (int j = ; j <LevelParam.levels[levelNo-].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()-].getStrLength();
StringBuffer buffer=new StringBuffer();
Random random=new Random();
for (int i = ; i < strLength; i++) {
int rand=random.nextInt(strLength);
switch (rand) {
case :
buffer.append(">");
break;
case :
buffer.append("<");
break;
case :
buffer.append("*");
break;
case :
buffer.append("&");
break;
case :
buffer.append("*");
break;
case :
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()-].getTimeLimit();
if ((currentTime-player.getStartTime())/>closeTime) {
System.out.println("你输入的太慢了,已经超时,退出!");
System.exit();
}
else
{
//计算当前玩家积分
//所有的积分相加
player.setCurScore(player.getCurScore()+LevelParam.levels[player.getLevelNo()-].getPerScore());
int score=player.getCurScore();//获取数组内的开始积分
int time=(int)(currentTime-player.getStartTime())/;//获取时间差
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();
} }
}
public class LevelParam {
public final static Level levels[]=new Level[];
static{
levels[]=new Level(,,,,);
levels[]=new Level(,,,,);
levels[]=new Level(,,,,);
levels[]=new Level(,,,,);
levels[]=new Level(,,,,);
levels[]=new Level(,,,,);
}
}
public class Test {

    public static void main(String[] args) {

        Player player=new Player();
player.play();
}
}

快速击键(MyEclipse编写的QuickHit项目)的更多相关文章

  1. QuickHit快速击键小程序 --S2.4.5

    我们现在要做一个项目 一个小小的程序 叫做快速击键 很明了的目的 就是在规定时间内,每次出现一组字母的组合,这个字母只能在DFJK中生成 然后输入相应的文字,按回车 自动判断输入的是否正确 在规定时间 ...

  2. 05章项目: QuickHit快速击键

    一.项目分析 根据输入速率和正确率将玩家分为不同等级,级别越高,一次显示的字符数越多,玩家正确输入一次的得分也越高.如果玩家在规定时间内完成规定次数的输入,正确率达到规定要求,则玩家升级.玩家最高级别 ...

  3. Quickhit快速击键

    一.项目分析 根据输入速率和正确率将玩家分为不同等级,级别越高,一次显示的字符数越多,玩家正确输入一次的得分也越高.如果玩家在规定时间内完成规定次数的输入,正确率达到规定要求,则玩家升级.玩家最高级别 ...

  4. JAVA WEB快速入门之从编写一个基于SpringBoot+Mybatis快速创建的REST API项目了解SpringBoot、SpringMVC REST API、Mybatis等相关知识

    JAVA WEB快速入门系列之前的相关文章如下:(文章全部本人[梦在旅途原创],文中内容可能部份图片.代码参照网上资源) 第一篇:JAVA WEB快速入门之环境搭建 第二篇:JAVA WEB快速入门之 ...

  5. 快速上手php:使用PhpStrom部署项目

    闲话 上学的时候一直以为可以专注自己的领域,以为与php无缘的,但是这种想法是错误,在完成任务的时候,你不得不使用你不熟悉的语言或者框架.正所谓业务驱动开发,这次接手已经离职的前辈的留下来的项目,最蛋 ...

  6. JAVA WEB快速入门之从编写一个JSP WEB网站了解JSP WEB网站的基本结构、调试、部署

    接上篇<JAVA WEB快速入门之环境搭建>,在完成了环境搭建后(JDK.Tomcat.IDE),现在是万事具备,就差写代码了,今天就来从编写一个JSP WEB网站了解JSP WEB网站的 ...

  7. eclipse导入myeclipse中的web项目

    场景:在myeclipse编写的一个简单的电信计费系统项目,后面公用到eclipse,想把它给导入到eclipse中 操作:eclipse中在packag explorer空白处右键>impor ...

  8. 使用MyEclipse编写Java程序

    MyEclipse是非常实用的一款Java程序开发工具,主要用于Java.Java EE以及移动应用的开发.MyEclipse的功能非常强大,支持也十分广泛,尤其是对各种开源产品的支持相当不错. My ...

  9. Myeclipse中导入新项目报叹号

    Myeclipse中导入新项目报红色叹号 原因是导入项目中,有的jar路径不对, 在上图中,先把报错的jar移除,之后将JRE开头的那个library移除,最后点击add Library,选择jre. ...

随机推荐

  1. 【Bugly干货分享】手把手教你逆向分析 Android 程序

    很多人写文章,喜欢把什么行业现状啊,研究现状啊什么的写了一大通,感觉好像在写毕业论文似的,我这不废话,先直接上几个图,感受一下. 第一张图是在把代码注入到地图里面,启动首页的时候弹出个浮窗,下载网络的 ...

  2. 使用XtraReport的CalculatedFiled(计算字段)实现RDLC报表中表达式

    DevExpress报表确实强大,花样繁多,眼花缭乱. 这次使用XtraReport开发报表,很多问题在官方的文档中并没有详细的说明,特此记录. 1.XtraReport中FormattingRule ...

  3. Fix catalyst driver in Ubuntu 13.04 / 13.10

    Fix catalyst driver in Ubuntu 13.04 / 13.10(墙外文章备份) 1. Introduction I found lots of people strugglin ...

  4. IOS 其它语言比较-Objc与JAVA的比较

    1. Objc是一门编译型语言,JAVA是解析型语言 编译型语言:把做好的源程序全部编译成二进制代码的可运行程序.然后,可直接运行这个程序. 编译型语言,执行速度快.效率高:依赖编译器.跨平台性差些. ...

  5. 缓存篇~第六回 Microsoft.Practices.EnterpriseLibrary.Caching实现基于方法签名的数据集缓存

    返回目录 这一讲中主要是说EnterpriseLibrary企业级架构里的caching组件,它主要实现了项目缓存功能,它支持四种持久化方式,内存,文件,数据库和自定义,对于持久化不是今天讨论的重要, ...

  6. Java程序员的日常—— 基于类的策略模式、List<?>与List、泛型编译警告、同比和环比

    早晨起得太早,昨晚睡得太晚,一天都迷迷糊糊的.中午虽然睡了半个小时,可是依然没有缓过来.整个下午都在混沌中....不过今天下载了一款手游--<剑侠情缘>,感觉不错,喜欢这种类型的游戏. 今 ...

  7. Node.js入门:Node.js&NPM的安装与配置

    Node.js安装与配置      Node.js已经诞生两年有余,由于一直处于快速开发中,过去的一些安装配置介绍多数针对0.4.x版本而言的,并非适合最新的0.6.x的版本情况了,对此,我们将在0. ...

  8. 如何实现 Android 应用的持续部署?

    构建一个高质量的 Android 应用 最大的挑战是什么? 在整个开发流程中,也许 Coding 时莫名的 bug,也许是 Android 开发兼容性问题,多版本多渠道自动打包问题,也有开发工具选择等 ...

  9. java连接数据库的模糊查询

    1:模糊查询是比较常见的一种查询方式,例如在订单表中,包含有订单的具体日期.如果要查询某年某月的订单信息,最好的方式就是使用模糊查询.进行模糊查询需要使用关键字LIKE.在使用LIKE关键字进行模糊查 ...

  10. VMware Workstation cannot connect to the virtual machine 解决方案

    今天 打开虚拟机 忽然遇到这个问题: VMware Workstation cannot connect to the virtual machine. Make sure you have righ ...