Case Quickhit: Players play games
Teacher: Wang Shaohua QQ Group: 483773664 Learning Goals
Completing the play method in the player class
I. Description of requirements
Players play games
Second, the Thinking analysis
-
Create a game object and pass in the Player property;
-
Outer loop (number of cycles is 6, one level of player level per cycle)
Promotion
Points clear 0, time clear 0;
Inner Loop (the number of cycles is the strtime of this level, and the interaction is completed once per cycle)
Game output string;
Player input string;
The game judges the player to input and output the corresponding results.
Third, reference code
| 1234567891011121314151617181920212223 |
/** * 玩家玩游戏。 */ public void play() { Game game = new Game(this); Scanner input = new Scanner(System.in); // 外层循环,循环一次级别晋一级 for (int i = 0; i < LevelParam.levels.length; i++) { // 1、 晋级 this.levelNo += 1; // 2、 晋级后计时清零,积分清零 this.startTime = System.currentTimeMillis(); this.curScore = 0; // 3、 内层循环,循环一次完成一次字符串的输出、输入、比较 for (int j = 0; j < LevelParam.levels[levelNo-1].getStrTime(); j++) { // 3.1、游戏输出字符串 String outStr = game.printStr(); // 3.2、接收用户输入 String inStr = input.next(); // 3.3、游戏判断玩家输入是否正确,并输出相应结果信息 game.printResult(outStr, inStr); } } |
From for notes (Wiz)
Learn Java with teacher Wang three major features (iv): Case Quickhit: Players play games