一、项目分析

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

二、掌握的技能点

①面向对象设计的思想

②使用类图理解类的关系

③类的封装

④构造方法的使用

⑤this和static关键字的使用

类的属性:

①玩家(Player)类的属性:当前级别号levelNo、当前级别积分currScore、当前级别开始时间startTime和当前级别已用时间elapsedTime

②级别(Level)类的属性:各级别编号levelNo、各级别一次输出字符串的长度strLength、各级别输出字符串的次数strTime、各级别闯关的时间限制timeLimit和各级别正确输入一次得分

类的方法:

游戏Game类的主要方法有2个:输出字符串、返回字符串用于和玩家的输入进行比较[String printStr]确认玩家输入是否正确[void printResult(String out,String in)],比较游戏输出out和玩家输入in

玩家Player类的方法:玩游戏play()

LevelParam类:定义一个长度为6的Level数组,用来存放各级别的具体参数信息

关键代码:

Player类:

package cn.happy;import java.util.Scanner;public class Player {public int levelNo;  //级别号public int curScore;  //积分public long startTime; //开始时间public int elapsedTime; //已用时间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 getElapsedTime() {return elapsedTime;}public void setElapsedTime(int elapsedTime) {this.elapsedTime = elapsedTime;}public Player(){}public Player(int levelNo,int curScore,long startTime,int elapsedTime){this.levelNo=levelNo;this.curScore=curScore;this.startTime=startTime;this.elapsedTime=elapsedTime;}//玩游戏的方法public  void play(){Game game=new Game(this);Scanner input=new Scanner(System.in);//外层循环,循环一次级别晋一级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();//接收用户输入String instr=input.next();//游戏判断玩家输入的是否正确
                game.printResult(outstr,instr);}}}}

Level类:

package cn.happy;public class Level {public int levelNo; //各级别编号public int strLength;// 各级别一次输出字符串的长度public int strTimes;// 各级别输出字符串的次数public int timeLimit;// 各级别闯关的时间限制public 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(){}public Level(int levelNo,int strLength,int strTimes,int timeLimit,int perScore){this.levelNo=levelNo;this.strLength = strLength;this.strTimes = strTimes;this.timeLimit = timeLimit;this.perScore = perScore;}}

LevelParam类

package cn.happy;public class LevelParam {//级别参数类,配置各个级别参数//对应6个级别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);}}

Game类:

package cn.happy;import java.util.Random;public class Game {//玩家private Player player;public Game(){}public Game(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;}}// 输出字符串
        System.out.println(buffer);// 返回该字符串的值,用于和用户输入字符串的值作比较return buffer.toString();}//判断玩家输入的是否正确,并输出相应的结果public String printResult(String outstr,String instr){boolean flag=false;if(outstr.equals(instr)){flag=true;}else{System.out.println("输入错误!哈哈");System.exit(0);}if(flag){long currentTime=System.currentTimeMillis();//如果超时if((currentTime-player.getStartTime())/100>LevelParam.levels[player.getLevelNo()-1].getTimeLimit()){System.out.println("你输入的太慢了,已经超时,退出!");System.exit(1);}//计算玩家当前积分player.setCurScore(player.getCurScore()+LevelParam.levels[player.getLevelNo()-1].getPerScore());//计算玩家已用时间player.setElapsedTime((int)(currentTime-player.getStartTime())/1000);//输出玩家当前级别,当前积分,当前时间System.out.println("输入正确,您的级别是"+player.levelNo+",您的积分是"+player.curScore+",已用时间"+player.elapsedTime+"");}        return "hh";}}

测试Test类:

package cn.happy;public class Test {/*** @param args*/public static void main(String[] args) {Player player=new Player();player.play();}}

转载于:https://www.cnblogs.com/WJ-163/p/5539790.html

05章项目: QuickHit快速击键相关推荐

  1. Quickhit快速击键

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

  2. 战争迷雾效果 第05章 项目源码下载

    笨木头花心贡献,啥?花心?不呢,是用心~ 转载请注明,原文地址:http://www.benmutou.com/blog/archives/502 正文: 关于战争迷雾效果的项目源码一直没有放出来,原 ...

  3. 05章项目:我的租房网

    阶段一:分页显示查询出租房屋信息 使用top关键字实现查询数据分页显示: 查询输出第6条~第10条出租房屋信息: 执行结果: 阶段二:查询指定客户发布的出租房屋信息 查询张三发布的所有出租房屋信息,并 ...

  4. 计算机论文word版,计算机应用基础第05章Word高级应用-毕业论文排版

    计算机应用基础第05章Word高级应用-毕业论文排版 (31页) 本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦! 14.90 积分 5.1.1 任务描述 刘海是 ...

  5. 信息系统项目管理师---第五章 项目范围管理

    信息系统项目管理师-第五章 项目范围管理 范围管理 一.范围管理概述 1.项目范围管理需要做以下三方面工作: (1)明确项目边界,明确那些再范围内,那些再范围外. (2)确保所有该做的工作都做了,而且 ...

  6. 信息系统项目管理师---第九章 项目人力资源管理历年考题

    信息系统项目管理师-第九章 项目人力资源管理历年考题 1.2005 年 5 月第 43 题:项目人力资源管理就是有效地发挥每一个项目参与人作用的过程.关于项目人力资源管理说法错误的是( D). A.项 ...

  7. 计算机一级设置项目符号,重推计算机等级考试题库:一级MS Office第三章“项目符号和段落编号”...

    小编所收集到的相关计算机等级考试题库:一级MS Office第三章"项目符号和段落编号"的资料 大家要认真阅读哦! 编排文档时,在某些段落前加上编号或某种特定的符号(称项目符号), ...

  8. 《Python自然语言处理(第二版)-Steven Bird等》学习笔记:第05章 分类和标注词汇

    第05章 分类和标注词汇 5.1 使用词性标注器 5.2 标注语料库 表示已标注的标识 读取已标注的语料库 简化的词性标记集 名词 动词 形容词和副词 未简化的标记 探索已标注的语料库 5.3 使用P ...

  9. 第二章:Django快速上手

    The Django Book 第2章:Django快速上手 revised by xin_wang 谢天谢地,安装Django非常容易.因为Django可以运行在任何可以运行Python的环境中,所 ...

最新文章

  1. Debug常用命令 精简版本
  2. 玩转VSCode插件之Remote-SSH
  3. Flex3双向绑定完善版
  4. 使用Hazelcast发布和订阅
  5. think in java - 第一章 学习笔记
  6. MySQL 查询速度慢与性能差的原因与解决方法
  7. mvc:annotation-driven 注解的作用
  8. 互联生活:业务模式聚焦
  9. 双向链表示意图_java双向链表示意图
  10. 自定义地图开发(一)
  11. 从趣味游戏到排序算法(2)
  12. yii2 html编辑器,浅析Yii2集成富文本编辑器redactor实例教程
  13. SQL语言入坑—1.数据的检索、排序、过滤、分组
  14. Python星号表达式
  15. 190422每日一句
  16. java编写蠕虫病毒_教大家编写蠕虫病毒
  17. C++STL容器的比较
  18. KVM虚拟化平台搭建、工作模式与原理
  19. 从零开始学IDA逆向(百度云)
  20. slim的train

热门文章

  1. 有20万3年不用,怎样理财呢?
  2. 让餐饮店生意火爆的三套方案
  3. 真正好的东西,就会脱颖而出
  4. 越有钱越小气,这话说的一点儿都不错
  5. 这5条职场心机,句句真实,引发深思
  6. 搭建属于自己的私有链,部署简单的智能合约
  7. CSS--CSS清除浮动的4种方式
  8. 复制vmware的ubuntu虚拟机启动进入紧急模式问题
  9. azure云数据库_配置Azure SQL数据库防火墙
  10. azure 使用_使用Azure的低成本灾难恢复解决方案