?? 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 + -