📄 pong.java
字号:
import objectdraw.*;import java.awt.*;// plays a classic version of single player pongpublic class Pong extends WindowController{ private static final int // Dimensions of the court courtLeft = 50, courtTop = 50, courtHeight = 300, courtWidth = 250, // Dimensions of the paddle paddleWidth = 50, paddleHeight = 20; private FilledRect paddle; // the paddle private FramedRect boundary; // the boundary of the playing area. public void begin() { // make the playing area boundary = new FramedRect(courtLeft,courtTop, courtWidth, courtHeight, canvas); // make the paddle paddle = new FilledRect(courtLeft + (courtWidth-paddleWidth)/2, courtTop + courtHeight - paddleHeight -1, paddleWidth, paddleHeight, canvas); } public void onMouseClick(Location point) { // make a new ball when the player clicks new MovingBall(canvas, paddle, boundary); } public void onMouseMove(Location point) { if ( point.getX() < courtLeft ) { // place paddle at left edge of the court paddle.moveTo( courtLeft, courtTop + courtHeight - paddleHeight -1); } else if ( point.getX() > courtLeft + courtWidth - paddleWidth) { // place paddle at right edge of the court paddle.moveTo( courtLeft + courtWidth - paddleWidth, courtTop + courtHeight - paddleHeight -1); } else { // keep the edge of the paddle lined up with the mouse paddle.moveTo( point.getX(), courtTop + courtHeight - paddleHeight -1); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -