Learn Java with teacher Wang three major features (iv): Case Quickhit: Players play games

Source: Internet
Author: User

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
    1. Create a game object and pass in the Player property;

    2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.