BOARD :
package centipede;
//import java.awt.event.KeyEvent;
//import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.WindowConstants;
public class Board extends JFrame{
private JTextArea Board;
private int height = 50;
private int width = 50;
public Board(int height, int width) {
Board = new JTextArea();
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Board.setColumns(width + 1);
Board.setRows(height);
Board.setEditable(false);
Board.setFont(new java.awt.Font("Monospaced", 0, 12));
Board.setLineWrap(true);
Board.setAutoscrolls(false);
// Board.addKeyListener(this);
setTitle("Centipede Game");
add(Board);
pack();
setResizable(false);
}
public JTextArea getBoard() {
return Board;
}
}
CENTIPEDE :
package centipede;
public class Centipede {
private char segment = '@';
private int length = 5;
private int speed;
private Board board;
public Centipede (Board board) {
this.board = board;
}
public void move () {
int edge = board.getWidth();
}
public int getLength () {
return length;
}
public void setLength (int val) {
this.length = val;
}
public char getSegment () {
return segment;
}
public void setSegment (char val) {
this.segment = val;
char[] centipede = new char[length];
for (int i = 1; i <= length; i++) {
centipede[i] = segment;
}
}
public void hit () {
}
public int getSpeed () {
return speed;
}
public void setSpeed (int val) {
this.speed = val;
}
}
MAIN:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package centipede;
import javax.swing.JTextArea;
/**
*
* @author student
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//nothing here yet
}
}
No comments:
Post a Comment