今天做了一个很有意思的项目,叫快速击键,这个项目他主要考察的就是:面向对象设计的思想, 类的封装, 构造方法的使用, this、static关键字的使用 一.项目需求: 根据输入的速率和正确率将玩家分为不同级别,级别越高,一次显示的字符数越多,玩家正确输入一次的得 ...
今天做了一个很有意思的项目,叫快速击键,这个项目他主要考察的就是:面向对象设计的思想, 类的封装, 构造方法的使用, this、static关键字的使用
一.项目需求:
根据输入的速率和正确率将玩家分为不同级别,级别越高,一次显示的字符数越多,玩家正确输入一次的得分也越高。如果玩家在规定的时间内完成规定次数的输入,正确率达到规定标准,则玩家升级(在这里规定只要错误输入一次,则游戏结束)。玩家最高级为6级,初始级别一律为一级。
运行效果图:
二.分析需求:
01.发现类:
玩家类(Player),游戏类(Game),级别类(Level),LevelParam(保存每一个级别的参数信息)
02.发现类中的属性:
玩家类(Player)的属性:
levelNo:玩家当前级别号,currScore:玩家当前级别积分,startTime:玩家当前级别开始时间,elapsedTime 当前级别已用时间
级别类(Level)的属性:
levelNo:各级别编号,strLength各级别一次输入字符串的长度,strTime各级别输出字符串的次数,timeLimit各级别闯关的时间限制,perScore各级别正确输入一次的得分。
游戏类(Game):既然是玩游戏,肯定有玩家,所以在游戏类中要添加一个玩家的属性player;
03.发现类的方法
玩家类(Player)的方法:play();
游戏类(Game)的方法:
String printStr(),输出字符串,返回字符串用于和玩家的输入进行比较。
void printResult(String out,String in)比较输出out和玩家输入in
三.实现功能:
第一步我们要形成这个项目的一个整体框架。
Level类:
package cn.hyj.quickhit;/** * 级别类 * * @author HYJ * */public class Level { private int levelNo;// 各级别编号 private int strLength;// 各级别一次输出字符串的长度 private int strTimes;// 各级别输出字符串的次数 private int timeLimit;// 各级别闯关的时间限制 private int perScore;// 各级别正确输入一次的得分 public Level() { super(); // TODO Auto-generated constructor stub } 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; } 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; }}
原标题:好玩的快速击键项目
关键词:
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。