📄 snake.java
字号:
/**
* @(#)Snake.java
* @A snake with all points of the snake.
*
* @Link Scholes
* @version 1.00 2008/7/21
*/
package Data;
//Java core packages
import java.util.*;
public class Snake
{
private int length;
private int tail;
private int points[];
private ArrayList<Integer> snake;
//construct a snake with only one head in the specified position
public Snake(int a)
{
length = 1;
snake = new ArrayList<Integer>(1);
snake.add(new Integer(a));
}
//get the length of the snake
public int getLength()
{
return length;
}
//add a new head to the snake
public void addHead(int n)
{
snake.add(0,new Integer(n));
}
//cut the tail of the snake
public int cutTail()
{
tail = ((Integer)snake.get(length - 1)).intValue();
snake.remove(length - 1);
return tail;
}
//increase the length of the snake
public void increase()
{
length ++;
snake.ensureCapacity(length);
}
//decrease the length of the snake
public void decrease()
{
length --;
snake.trimToSize();
}
//clear all the points of the snake
public int[] clear()
{
points = new int[length - 1];
for (int i = 0;i < length - 1;i ++)
{
points[i] = ((Integer)snake.get(i)).intValue();
}
return points;
}
} //end class Snake
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -