こんにちは、これはおそらくあなたのほとんどの人にとっては簡単ですが、今日のクラスでこのコードを分析していました。誰かが私が実際に理解していないコード手段の残りの部分を私に記入することができます。しかし、私は//マークを付けた部分を理解しています。このコードはどういう意味ですか、安心してほしいのですか?Javaの基礎
**I have no clue about this following statement**
public class PONG extends JComponent implements ActionListener, MouseMotionListener, KeyListener {
**are these the initial values?**
private static final long serialVersionUID = 1L;
private int scorefinal;
private int ballx = 150;
private int bally = 30;
private int ballx1 = 100;
private int bally1 = 10;
private int paddlex = 0;
private int ballySpeed = 7;
private int ballxSpeed = 5;
private int bally1Speed = 14;
private int ballx1Speed = 10;
public int score = 0;
public int score1 = 0;
public int bestscore;
public int bestscore1;
public boolean gameOver, started;
**Is this saying how fast the ball moves?**
Timer tt = new Timer(10, g);
tt.start();
}
**I do not know the following block of code**
public void newball(int ballx, int bally, int ballxspeed, int ballyspeed) {
ballx = 150;
bally = 30;
ballxspeed = 5;
ballyspeed = 7;
return;
}
**So how is the scoring calculated?**
if (score >= 5) {
g.setColor(Color.red);
g.setFont(new Font("Arial", 8, 50));
g.drawString(String.valueOf(score + score1), 30/1 - 15, 80);
} else {
g.setColor(Color.white);
g.setFont(new Font("Arial", 8, 50));
g.drawString(String.valueOf(score), 30/1 - 15, 80);
}
// start && gameOver
g.setColor(Color.white);
g.setFont(new Font("Arial", 8, 50));
if (gameOver) {
**I do not understand the 50/ 1-15, 200**
g.drawString(String.valueOf(" Best Score :" + scorefinal), 50/1 - 15, 200);
}
}
public void actionPerformed(ActionEvent e) {
ballx = ballx + ballxSpeed;
bally = bally + ballySpeed;
**I think these are the boundaries but i am not entirely sure
// Window Down
if (ballx >= paddlex && ballx <= paddlex + 100 && bally >= 475) {
ballySpeed = -7;
score++;
}
if (bally >= 700) {
score = 0;
bally = 30;
gameOver = true;
}
// Window up
if (bally <= 0) {
ballySpeed = 7;
}
// Window right
if (ballx >= 775) {
ballxSpeed = -5;
}
// Window left
if (ballx <= 0) {
ballxSpeed = 5;
}
//i do not know what this means
ballx1 = ballx1 + ballx1Speed;
bally1 = bally1 + bally1Speed;
// Window down
if (ballx1 >= paddlex && ballx1 <= paddlex + 100 && bally1 >= 475) {
bally1Speed = -14;
score1++;
}
if (bally1 >= 700) {
score1 = 0;
bally1 = 10;
}
// Window up
if (bally1 <= 0) {
bally1Speed = 14;
}
// Window right
if (ballx1 >= 775) {
ballx1Speed = -10;
}
// Window left
if (ballx1 <= 0) {
ballx1Speed = 10;
}
**/i understand this has something to do with mouse events but i dont get the -50 part, and what is the overrides mean**
public void mouseMoved(MouseEvent e) {
paddlex = e.getX() - 50;
repaint();
}
@Override
public void mouseDragged(MouseEvent e) {
}
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
理解しにくいコードが少ない場合は、200行の無関係なコードを投稿しないでください。あなたのタイトルは、あなたが理解していないものとあなたが理解していないものを反映するように変更してください。あなたの質問の本文で同じことをしてください。今のところ不明のまま投票を終える。 – Savior
あなたが理解していない部分は何ですか? –
具体的な回答とヘルプが必要な場合は、**特定の質問をしてください**。 –