練習(xí)內(nèi)容
- 打字游戲默寫1遍
- 打字游戲代碼片段練習(xí)4遍
感想
- 50分鐘內(nèi)完整默寫1遍
- 限時(shí)完成可運(yùn)行版本轨蛤,查看運(yùn)行結(jié)果對(duì)比標(biāo)準(zhǔn)
- 抄寫不會(huì)的代碼片段
- 默寫該代碼片段
問題
- 存疑:
public類不能用固定值初始化變量
- 無動(dòng)畫效果
在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) //遍歷完成后根據(jù)標(biāo)志進(jìn)行檢測
{
y[nowIndex] = 0 ;
x[nowIndex] = (int)(Math.random()*300) ;
c[nowIndex] = (char)(Math.random()*26+97) ;
score += 10 ;
}else {
score -= 100 ;
}
}