Typing games on java of QuickHit small projects

class Player {public 
Scanner the INPUT = new new Scanner (System.in);
// player property
private int level = 0; // level of
private int curScore = 0; // integral
private long stratTime = 0; // start time
private int elapsdTime = 0; // used time

@ package
public int getLevel () {
return Level;
}

public void setLevel (Level int) {
this.level Level =;
}

public int getCurScore () {
return curScore;
}

public void setCurScore (int curScore) {
this.curScore = curScore;
}

public Long getStartTime () {
return stratTime;
}

void setStartTime public (int strTime) {
this.stratTime = strTime;
}

public int getElapsdTime () {
return elapsdTime;
}

public void setElapsdTime (int elapsdTime) {
this.elapsdTime = elapsdTime;
}

// package
Game game = new Game (this ); // Create game objects, and charged player
public void play () throws Exception // play
{
for (int I = 0; I <LevelParam.levels.length; I ++) {// play times
// a clearance
LevelParam.levels Level = Level [this.level];
this.stratTime = System.currentTimeMillis ();
for (int. 1 = J; J <= level.getStrTime (); J ++) {
System.out.println ( "first" + j + "views");
String game.pringStr OUT = (); // received string
String in = input.next (); // receiving a character string input by the player
game. printResult (out, in); // print the results and comparing
}
this.curScore level.getPerSore + = ();
System.out.println ( "by the second" + (this.level + 1) + " off, Points:" curScore +);
this.level ++; // increased level
// a clearance
}
}
}
public class Game {
private Player player;//玩家
public Game(){}//构造
public Game(Player player){this.player=player;}//构造
String pringStr()//输出字符串方法
{
Level level = LevelParam.levels[this.player.getLevel()];
Random random = new Random();
StringBuffer sb=new StringBuffer();
for (int i = 0; i < level.getStrLength(); i++) {
int rand = random.nextInt(6);
switch(rand)
{
case 0:
sb.append("a");
break;
case 1:
sb.append("b");
break;
case 2:
sb.append("c");
break;
case 3:
sb.append("d");
break;
case 4:
sb.append("e");
break;
case 5:
sb.append("f");
break;
}
}
System.out.println(sb.toString());
return sb.toString();
}

public void printResult(String out,String in)//比较结果
{
if(out.equals(in))
{
System.out.println("Input success ");
the endtime = System.currentTimeMillis Long ();
Double timecha = (the endtime-this.player.getStartTime ()) * 1.0 / 1000;
. IF (timecha> (LevelParam.levels [this.player.getLevel ()] getTimeLimit ()) )
{
System.out.println ( "gAME OVER input timeout");
System.exit (0);
}
}
the else {
System.out.println ( "input fails, quit the game");
System.exit (0);
}
}
}
public class Level {
public int getLevelON() {
return levelON;
}

public void setLevelON(int levelON) {
this.levelON = levelON;
}

public int getStrLength() {
return strLength;
}

public void setStrLength(int strLength) {
this.strLength = strLength;
}

public int getStrTime() {
return strTime;
}

public void setStrTime(int strTime) {
this.strTime = strTime;
}

public int getTimeLimit() {
return timeLimit;
}

public void setTimeLimit(int timeLimit) {
= timeLimit is this.timeLimit;
}

public int getPerSore () {
return perSore;
}

public void setPerSore (int perSore) {
this.perSore = perSore;
}

Private Levelon int = 0; // Level
private int strLength = 0; // character string length
private int strTime = 0; // number of inputs
private int timeLimit = 0; // time limit
private int perSore = 0; // score the level
// configured
public level () {}
public level (Levelon int, int strLength , int strTime, timeLimit is int, int perSore) {
this.levelON = Levelon;
this.strLength = strLength;
this.strTime = strTime;
this.timeLimit = timeLimit is;
= perSore this.perSore;
}
// constructor
}
{class LevelParam public 
public static Final Level Levels [] = new new Level [. 6]; // attribute constant array
static {// set the difficulty level and initializes
// level, the input of words, number of inputs, the time limit, rating
levels [0] new new Level = (1,2,2,30,1);
Levels [. 1] = new new Level (1,3,2,30,2);
Levels [2] = new new Level (1,4,2,30, . 3);
Levels [. 3] = new new Level (1,5,2,30,4);
Levels [. 4] = new new Level (1,6,2,30,5);
Levels [. 5] = new new Level (. 1 , 7,2,30,6);
}
}
object-oriented design of the project, the practical experience of the project and the importance of programming ideas.
Where construction and static to initialization parameters and mass participation for the beginner for me
is indeed a very clever use of the method,
I tried to use C ++ to write the procedures, but also truly appreciate the real differences in programming language,
a lot of things use c ++ realize it is not easy to java, of course, is my understanding, and not enough
for the C ++ programming ideas and skills to master is not in place, so I'm not finished yet. I will try to
finish it in order to improve their understanding.

Guess you like

Origin www.cnblogs.com/deemohans/p/11706938.html