Project case: Quickhit: Demand Analysis Instructor: Wang Shaohua QQ Group No.:483773664Learning Goals
Learning to use object-oriented thinking to carry out demand analysis
First, the demand
Divides players into different levels based on the input rate and the correct rate
The higher the level, the more characters are displayed at one time, and the higher the player's score is to enter it correctly.
To complete the specified number of times within the specified time input, the correct rate to meet the requirements, the upgrade
Player's highest level is 6, initial level is all 1 levels
User error input once, game over
Ii. Object-oriented analysis (i) Discovery class
Players (player) class
Games (game) class
Level class
650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M00/7F/2D/wKiom1cV1UWiYmkxAAAhv8-_ElY290.png " data_ue_src= "E:\My knowledge\temp\86e08ba6-76c6-479e-b5fe-0e4fed95eede.png" >
(ii) Discovery of the properties of the class
1. Properties of Player Class (player)
Player current level number (Levelno)
Player Current level credits (Currscore)
Current level start time (startTime)
Current level used time (ElapsedTime)
650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M02/7F/2B/wKioL1cV1gSzqakMAAAmenxLiCU503.jpg " data_ue_src= "E:\My knowledge\temp\342137ef-207b-486d-981e-b2bc709b08e6.jpg" >
2,Properties for level classes (levels)
Alias at all levels (Levelno)
The length of the output string at each level (Strlength)
Number of output strings at each level (Strtimes)
Time limit for levels (TIMELIMIT)
All levels correctly enter the score once (Perscore)
650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M00/7F/2B/wKioL1cV1gSgASG4AAAnOsIjlFs106.jpg " data_ue_src= "E:\My knowledge\temp\0027f5af-57ca-45d4-bd38-b5ee7b67ed12.jpg" >
3. Game Class
No attributes, only methods
(iii) Discovery of class behavior 1, Player Class (player)
Play games: Play ()
2. Game Class
String Printstr (): Output string, return string for comparison with player input
void Printresult (String out,string in): Compare game output out and player input in, output corresponding information according to comparison results
650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M00/7F/2D/wKiom1cV1UWQpk57AABcgVz5X64239.jpg " data_ue_src= "E:\My knowledge\temp\baf2b9bf-bbec-42b5-b5e9-a527d66e6b8e.jpg" >
(d) Optimization design 1 modifying game classes (games), adding attributes
Player: Player
2 Adding class Levelparam: For storing level constants
Public final static level level[6]
650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M00/7F/2B/wKioL1cV1gWSVW3QAABpudg7OA0798.jpg " data_ue_src= "E:\My knowledge\temp\52b198c8-1a81-412b-a282-008df12a3c35.jpg" >
Three, the game demo demonstration Four, the class writing
(i) Player
12345678910111213 |
public class Player {
private int levelNo;
// 级别号
private int curScore;
// 当前积分
private long startTime =
0
;
// 各级别开始时间
private int elapsedTime;
// 各级别已用时间
/**
* 玩家玩游戏。
*/
public void play() {
}
}
|
(ii) level
12345678910111213141516171819 |
public class Level {
private int levelNo;
// 级别号
private int strLength;
// 各级别一次输出字符串的长度
private int strTime;
// 各级别输出字符串的次数
private int timeLimit;
// 各级别闯关的时间限制
private int perScore;
// 各级别成功输入一次字符串后增加的分值
/**
* 构造方法
*/
public Level(){}
public Level(
int levelNo,
int strLength,
int strTime,
int timeLimit,
int perScore) {
this
.levelNo = levelNo;
this
.strLength = strLength;
this
.strTime = strTime;
this
.timeLimit = timeLimit;
this
.perScore = perScore;
}
}
|
(iii) Game
12345678910111213141516171819202122232425 |
public class Game {
private Player player;
// 玩家
/**
* 构造方法
*/
public Game(){}
public Game(Player player) {
this
.player = player;
}
/**
* 输出指定级别规定长度的字符串。
* @return 输出的字符串,用于和用户输入比较
*/
public String printStr() {
return ""
;
}
/**
* 判断玩家输入是否正确,并输出相应结果信息。
* @param out 游戏输出的字符串
* @param in 玩家输入的字符串
*/
public void printResult(String out, String in) {
}
}
|
(d) Levelparam
1234567891011121314151617 |
/**
*
* @author wangsh
* @createDate:2016年4月18日
* 功能描述: 级别参数类,配置各个级别参数。
*/
public class LevelParam {
public final static Level levels[]=
new Level[
6
];
//对应六个级别
}
|
Five, the initialization of the parameters at all levels (a), difficult tips
1 using static modifier properties and code blocks
belong to this class all
Accessed by the object name. static property name, class name, static property name.
Access by "class name. Static method Name" and "Object name. Static method Name"
The primary function is to initialize the static property
Executes a class when it is loaded and is executed only once
(b), reference code
Learn Java with teacher Wang three major characteristics (a): Case Quickhit: Demand analysis