刻意编程D9

练习内容

  • 打字游戏默写1遍
  • 打字游戏代码片段练习4遍

感想

  • 50分钟内完整默写1遍
  • 限时完成可运行版本,查看运行结果对比标准
  • 抄写不会的代码片段
  • 默写该代码片段

问题

  • 存疑:

public类不能用固定值初始化变量

  • 无动画效果

在run()中加repaint();

代码示例

    public void keyPressed(KeyEvent arg0) {
        char keyC = arg0.getKeyChar() ;
        int nowY = -1 ;
        int nowIndex = -1 ;
        for(int i = 0 ; i < 10 ; i ++)  //先遍历查找
                {
            if(keyC==c[i]){
                if(y[i]>nowY){
                    nowY = y[i] ;
                    nowIndex = i ;
                }
            }
        }
        
        if(nowIndex!=-1) //遍历完成后根据标志进行检测
                {
            y[nowIndex] = 0 ;
            x[nowIndex] = (int)(Math.random()*300) ;
            c[nowIndex] = (char)(Math.random()*26+97) ;
            score += 10 ;
        }else {
            score -= 100 ;
        }
        
    }

你可能感兴趣的:(刻意编程D9)