第一步,就是先把单个格子的属性创建出来
public class Cell {
int row;
int col;
int color;
static int indexRow = 10000;//这个参数是上下穿墙用的,为了保证不用完,要尽可能的大
static int indexCol = 10000;//这个参数是左右穿墙用的,为了保证不用完,要尽可能的大
public Cell(){//对于父类,无参数构造器不一定用到,应该习惯的写上
}
public Cell(int x, int y, int color) {
super();
this.row = x;
this.col = y;
this.color = color;
}
//各属性的get set方法
public int getColor() {
return color;
}
public void setColor(int color) {
this.color = color;
}
public int getRow() {
return row;
}
public void setRow(int x) {
this.row = x;
}
public int getCol() {
return col;
}
public void setCol(int y) {
this.col = y;
}
/**向X轴负正向走*/
public void left(){
row = (indexRow+(--row))%40;/*这就是穿墙的关键,40是贪吃蛇墙的长,%40就能使蛇走不出墙,注意!!(--row)不能写成(row--) */
}
/**向X轴负方向走*/
public void right(){
row= (indexRow+(++row))%40;
}
/**向Y轴负方向走*/
public void up(){
col = (indexCol+(--col))%40;
}
/**向Y轴正方向走*/
public void down(){
col = (indexCol+(++col))%40;
}
public String toString(){
return row+","+col;
}
}
public class Cell {
int row;
int col;
int color;
static int indexRow = 10000;//这个参数是上下穿墙用的,为了保证不用完,要尽可能的大
static int indexCol = 10000;//这个参数是左右穿墙用的,为了保证不用完,要尽可能的大
public Cell(){//对于父类,无参数构造器不一定用到,应该习惯的写上
}
public Cell(int x, int y, int color) {
super();
this.row = x;
this.col = y;
this.color = color;
}
//各属性的get set方法
public int getColor() {
return color;
}
public void setColor(int color) {
this.color = color;
}
public int getRow() {
return row;
}
public void setRow(int x) {
this.row = x;
}
public int getCol() {
return col;
}
public void setCol(int y) {
this.col = y;
}
/**向X轴负正向走*/
public void left(){
row = (indexRow+(--row))%40;/*这就是穿墙的关键,40是贪吃蛇墙的长,%40就能使蛇走不出墙,注意!!(--row)不能写成(row--) */
}
/**向X轴负方向走*/
public void right(){
row= (indexRow+(++row))%40;
}
/**向Y轴负方向走*/
public void up(){
col = (indexCol+(--col))%40;
}
/**向Y轴正方向走*/
public void down(){
col = (indexCol+(++col))%40;
}
public String toString(){
return row+","+col;
}
}