Курсовая работа: Гра Змійка опис програми
public void setSpeed(int x, int y){
xSpeed = x;
ySpeed = y;
}
public void setMoveUp() { xSpeed = 0; ySpeed = -1;}
public void setMoveDown() { xSpeed = 0; ySpeed = 1;}
public void setMoveLeft() { xSpeed = -1; ySpeed = 0;}
public void setMoveRight(){ xSpeed = 1; ySpeed = 0;}
public boolean isMovingUp() { return ySpeed == -1;}
public boolean isMovingDown(){ return ySpeed == 1;}
public boolean isMovingLeft(){ return xSpeed == -1;}
public boolean isMovingRight(){ return xSpeed == 1;}
}
3.1.7. Файл GameSquare.java
import java.awt.*;
import javax.swing.*;
class GameSquare extends JPanel{
int w, h;
boolean used = false;
boolean isBorder = false;
int n;
public void setSize(int w, int h){
super.setSize(w, h);
this.w = w;
this.h = h;
}
public void setBorder(boolean b){isBorder = b;}
public void setUsed(boolean b){used = b;}
public void paintComponent(Graphics g){
if (isBorder && !used){