blindserpent.java

来自「Position.java :辅助类 SerpentGameCanvas.jav」· Java 代码 · 共 55 行

JAVA
55
字号
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;

class BlindSerpent extends GreedySerpent
{
	private static int count=0;
	
	BlindSerpent(SerpentGameCanvas canv, Maze m, Position initPos, int len) {
		super(canv, m, initPos, len);
		direction=MOVE_UP;
		type=BLIND;
	}

	protected boolean moveAhead()
	{
		synchronized(gameCanvas.npc) {
			if( !bLive ) return false;
			count++;
			if( count>=10 ) {
				count=0;
				setRandomDirection();
			}
			
			Position posDiff=new Position();
			switch(direction) {
				case MOVE_UP: 
					posDiff.setValue(0,-1);
					break;			
				case MOVE_DOWN:
					posDiff.setValue(0,1);
					break;			
				case MOVE_LEFT:
					posDiff.setValue(-1,0);
					break;			
				case MOVE_RIGHT:
					posDiff.setValue(1,0);
					break;			
				default:
			}
			if( conflictWithWall(posDiff)) {
				setRandomDirection();
				return false;
			}
			
			for( int i=body.size()-1;i>=1;i-- ) {
				((Position)body.elementAt(i)).setValue( (Position)body.elementAt(i-1) );
			}
			((Position)body.elementAt(0)).setValue(head);
			head.add(posDiff);
		}
		return true;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?