初步建议:学习正确的Java编码约定,学习如何缩进代码,以及命名变量。
对您的代码进行轻微的重写应该可以使可读的修正:
int scoreStartX = 52;int scoreStartY = 40;int scoreBallSize = 40;// scorePosX/Y means the position the score-ball should be drawnscorePosX = scoreStartX; // scoreStartX/Y = starting position of score balls scorePosY = scoreStartY;for (int i = 0; i < score; i++) { ellipse(scorePosX , scorePosY , scoreBallSize , scoreBallSize); // increment the positions, and wrap to next col if over screen width scorePosX += scoreBallSize ; if( scorePosX > screenWidth) { // next score ball position is beyond the screen scorePosX = scoreStartX; scorePosY += scoreBallSize; }}进一步重构代码以使用诸如Point之类的东西来表示坐标
Point scoreStartPos = new Point(52, 40);int scoreBallSize = 40;Point scorePos = new Point(scoreStartPos );for (int i = 0; i < score; i++) { drawCircle(scorePos, scoreBallSize); // a little helper method makes your pre easier to read // increment the positions, and wrap to next col if over screen width scorePos.translate( +scoreBallSize, 0); if( scorePos.getX() > screenWidth) { // next score ball position is beyond the screen scorePos.setLocation(scoreStartPoint.getX(), scorePos.getY() + scoreBallSize); }}


