当前位置: 首页>>代码示例>>Java>>正文


Java MOVE类代码示例

本文整理汇总了Java中pacman.game.Constants.MOVE的典型用法代码示例。如果您正苦于以下问题:Java MOVE类的具体用法?Java MOVE怎么用?Java MOVE使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MOVE类属于pacman.game.Constants包,在下文中一共展示了MOVE类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: drawPacMan

import pacman.game.Constants.MOVE; //导入依赖的package包/类
/**
 * Draw pac man.
 */
private void drawPacMan()
{
	int pacLoc=game.getPacmanCurrentNodeIndex();
	
	MOVE tmpLastPacManMove=game.getPacmanLastMoveMade();
	
    double halfMag = 0.5*MAG;
	int width = (int) (images.getPacMan(lastPacManMove,time).getWidth() * halfMag);
	int height = (int) (images.getPacMan(lastPacManMove,time).getHeight() * halfMag);
	
	if(tmpLastPacManMove!=MOVE.NEUTRAL)
		lastPacManMove=tmpLastPacManMove;

	bufferGraphics.drawImage(images.getPacMan(lastPacManMove,time), (int)(game.getNodeXCood(pacLoc)*MAG-1*halfMag), (int) (game.getNodeYCood(pacLoc)*MAG+3*halfMag), width, height, null);
}
 
开发者ID:hecoding,项目名称:Pac-Man,代码行数:19,代码来源:GameView.java

示例2: _init

import pacman.game.Constants.MOVE; //导入依赖的package包/类
/**
 * _init.
 *
 * @param initialMaze the initial maze
 */
private void _init(int initialMaze)
{
	mazeIndex=initialMaze;
	score=currentLevelTime=levelCount=totalTime=0;
	ghostEatMultiplier=1;
	gameOver=false;
	timeOfLastGlobalReversal=-1;		
	pacmanWasEaten=false;
	pillWasEaten=false;
	powerPillWasEaten=false;
	
	ghostsEaten=new EnumMap<GHOST,Boolean>(GHOST.class);
	
	for(GHOST ghost : GHOST.values())
		ghostsEaten.put(ghost,false);
	
	_setPills(currentMaze=mazes[mazeIndex]);
	_initGhosts();
	
	pacman=new PacMan(currentMaze.initialPacManNodeIndex,MOVE.LEFT,NUM_LIVES,false);		
}
 
开发者ID:hecoding,项目名称:Pac-Man,代码行数:27,代码来源:Game.java

示例3: _correctPacManDir

import pacman.game.Constants.MOVE; //导入依赖的package包/类
/**
 * _correct pac man dir.
 *
 * @param direction the direction
 * @return the mOVE
 */
private MOVE _correctPacManDir(MOVE direction)
{
	Node node=currentMaze.graph[pacman.currentNodeIndex];
	
	//direction is correct, return it
	if(node.neighbourhood.containsKey(direction))
		return direction;
	else
	{
		//try to use previous direction (i.e., continue in the same direction)
		if(node.neighbourhood.containsKey(pacman.lastMoveMade))
			return pacman.lastMoveMade;
		//else stay put
		else
			return MOVE.NEUTRAL;
	}
}
 
开发者ID:hecoding,项目名称:Pac-Man,代码行数:24,代码来源:Game.java

示例4: _updateGhosts

import pacman.game.Constants.MOVE; //导入依赖的package包/类
/**
 * _update ghosts.
 *
 * @param moves the moves
 */
private void _updateGhosts(EnumMap<GHOST,MOVE> moves)
{
	for(Entry<GHOST,MOVE> entry : moves.entrySet())
	{
		Ghost ghost=ghosts.get(entry.getKey());

		if(ghost.lairTime==0)
		{
			if(ghost.edibleTime==0 || ghost.edibleTime%GHOST_SPEED_REDUCTION!=0)
			{
				ghost.lastMoveMade=_checkGhostDir(ghost,entry.getValue());					
				moves.put(entry.getKey(), ghost.lastMoveMade);					
				ghost.currentNodeIndex=currentMaze.graph[ghost.currentNodeIndex].neighbourhood.get(ghost.lastMoveMade);
			}
		}
	}
}
 
开发者ID:hecoding,项目名称:Pac-Man,代码行数:23,代码来源:Game.java

示例5: _checkGhostDir

import pacman.game.Constants.MOVE; //导入依赖的package包/类
/**
 * _check ghost dir.
 *
 * @param ghost the ghost
 * @param direction the direction
 * @return the mOVE
 */
private MOVE _checkGhostDir(Ghost ghost,MOVE direction)
{
	//Gets the neighbours of the node with the node that would correspond to reverse removed
	Node node=currentMaze.graph[ghost.currentNodeIndex];
	
	//The direction is possible and not opposite to the previous direction of that ghost
	if(node.neighbourhood.containsKey(direction) && direction!=ghost.lastMoveMade.opposite())
		return direction;
	else
	{
		if(node.neighbourhood.containsKey(ghost.lastMoveMade))
			return ghost.lastMoveMade;
		else
		{
			MOVE[] moves=node.allPossibleMoves.get(ghost.lastMoveMade);
			return moves[rnd.nextInt(moves.length)];				
		}
	}
}
 
开发者ID:hecoding,项目名称:Pac-Man,代码行数:27,代码来源:Game.java

示例6: _reverseGhosts

import pacman.game.Constants.MOVE; //导入依赖的package包/类
private boolean _reverseGhosts(EnumMap<GHOST,MOVE> moves,boolean force)
{
	boolean reversed=false;		
	boolean globalReverse=false;
		
	if(Math.random()<GHOST_REVERSAL)
		globalReverse=true;
	
	for(Entry<GHOST,MOVE> entry : moves.entrySet())
	{
		Ghost ghost=ghosts.get(entry.getKey());
	
		if(currentLevelTime>1 && ghost.lairTime==0 && ghost.lastMoveMade!=MOVE.NEUTRAL)
		{
			if(force || (powerPillWasEaten || globalReverse))
			{
				ghost.lastMoveMade=ghost.lastMoveMade.opposite();
				ghost.currentNodeIndex=currentMaze.graph[ghost.currentNodeIndex].neighbourhood.get(ghost.lastMoveMade);
				reversed=true;
				timeOfLastGlobalReversal = totalTime;
			}
		}
	}
	
	return reversed;
}
 
开发者ID:hecoding,项目名称:Pac-Man,代码行数:27,代码来源:Game.java

示例7: getDistanceToClosestNonEdibleGhost

import pacman.game.Constants.MOVE; //导入依赖的package包/类
/**
 * Returns the distance to the nearest non-edible ghost not considering distances from directions opposing the last move made.
 * 
 * @param fromIndex current pacman location
 * @return Ghost or null if the ghosts are still in the lair
 */
public int getDistanceToClosestNonEdibleGhost(int fromIndex, MOVE lastMoveMade) {
	int minDistance = Integer.MAX_VALUE;

	for (Ghost ghost : this.ghosts.values()) {
		if (!ghost.isEdible() && !ghost.isInLair()) {
			int distance = this.getShortestPathDistance(fromIndex, ghost.currentNodeIndex, lastMoveMade);

			if (distance < minDistance) {
				minDistance = distance;
			}
		}
	}

	return minDistance;
}
 
开发者ID:hecoding,项目名称:Pac-Man,代码行数:22,代码来源:Game.java

示例8: getNextMoveTowardsTarget

import pacman.game.Constants.MOVE; //导入依赖的package包/类
/**
 * Gets the next move towards target.
 *
 * @param fromNodeIndex the from node index
 * @param toNodeIndex the to node index
 * @param distanceMeasure the distance measure
 * @return the next move towards target
 */
public MOVE getNextMoveTowardsTarget(int fromNodeIndex,int toNodeIndex,DM distanceMeasure)
{
	MOVE move=null;

	double minDistance=Integer.MAX_VALUE;

	for(Entry<MOVE,Integer> entry : currentMaze.graph[fromNodeIndex].neighbourhood.entrySet())
	{
		double distance=getDistance(entry.getValue(),toNodeIndex,distanceMeasure);
							
		if(distance<minDistance)
		{
			minDistance=distance;
			move=entry.getKey();	
		}
	}
	
	return move;
}
 
开发者ID:hecoding,项目名称:Pac-Man,代码行数:28,代码来源:Game.java

示例9: getNextMoveAwayFromTarget

import pacman.game.Constants.MOVE; //导入依赖的package包/类
/**
 * Gets the next move away from target.
 *
 * @param fromNodeIndex the from node index
 * @param toNodeIndex the to node index
 * @param distanceMeasure the distance measure
 * @return the next move away from target
 */
public MOVE getNextMoveAwayFromTarget(int fromNodeIndex,int toNodeIndex,DM distanceMeasure)
{
	MOVE move=null;

	double maxDistance=Integer.MIN_VALUE;

	for(Entry<MOVE,Integer> entry : currentMaze.graph[fromNodeIndex].neighbourhood.entrySet())
	{
		double distance=getDistance(entry.getValue(),toNodeIndex,distanceMeasure);
							
		if(distance>maxDistance)
		{
			maxDistance=distance;
			move=entry.getKey();	
		}
	}
	
	return move;
}
 
开发者ID:hecoding,项目名称:Pac-Man,代码行数:28,代码来源:Game.java

示例10: getApproximateNextMoveTowardsTarget

import pacman.game.Constants.MOVE; //导入依赖的package包/类
/**
 * Gets the approximate next move towards target not considering directions opposing the last move made.
 *
 * @param fromNodeIndex The node index from which to move (i.e., current position)
 * @param toNodeIndex The target node index
 * @param lastMoveMade The last move made
 * @param distanceMeasure The distance measure required (Manhattan, Euclidean or Straight line)
 * @return The approximate next move towards target (chosen greedily)
 */
public MOVE getApproximateNextMoveTowardsTarget(int fromNodeIndex,int toNodeIndex,MOVE lastMoveMade, DM distanceMeasure)
{
	MOVE move=null;

	double minDistance=Integer.MAX_VALUE;

	for(Entry<MOVE,Integer> entry : currentMaze.graph[fromNodeIndex].allNeighbourhoods.get(lastMoveMade).entrySet())
	{
		double distance=getDistance(entry.getValue(),toNodeIndex,distanceMeasure);
							
		if(distance<minDistance)
		{
			minDistance=distance;
			move=entry.getKey();	
		}
	}
	
	return move;
}
 
开发者ID:hecoding,项目名称:Pac-Man,代码行数:29,代码来源:Game.java

示例11: getApproximateNextMoveAwayFromTarget

import pacman.game.Constants.MOVE; //导入依赖的package包/类
/**
 * Gets the approximate next move away from a target not considering directions opposing the last move made.
 *
 * @param fromNodeIndex The node index from which to move (i.e., current position)
 * @param toNodeIndex The target node index
 * @param lastMoveMade The last move made
 * @param distanceMeasure The distance measure required (Manhattan, Euclidean or Straight line)
 * @return The approximate next move towards target (chosen greedily)
 */
public MOVE getApproximateNextMoveAwayFromTarget(int fromNodeIndex,int toNodeIndex,MOVE lastMoveMade, DM distanceMeasure)
{
	MOVE move=null;

	double maxDistance=Integer.MIN_VALUE;

	for(Entry<MOVE,Integer> entry : currentMaze.graph[fromNodeIndex].allNeighbourhoods.get(lastMoveMade).entrySet())
	{
		double distance=getDistance(entry.getValue(),toNodeIndex,distanceMeasure);
							
		if(distance>maxDistance)
		{
			maxDistance=distance;
			move=entry.getKey();	
		}
	}
	
	return move;
}
 
开发者ID:hecoding,项目名称:Pac-Man,代码行数:29,代码来源:Game.java

示例12: getDistToClosestPill4d

import pacman.game.Constants.MOVE; //导入依赖的package包/类
/**
 * Returns the distance to the closest pill in a given direction
 */
public int getDistToClosestPill4d(int pacmanNode, MOVE direction){
	int dist;
	int mindist=Integer.MAX_VALUE;
	
	if(currentMaze.graph[pacmanNode].neighbourhood.size()==0)//lair
		return 0;
	
	int [] PIndices = getPillIndices();
	
	for(int i = 0; i < PIndices.length; i++){
		if(isPillStillAvailable(PIndices[i])){
			dist = getShortestPathDistance(pacmanNode, PIndices[i], direction);
			if (dist < mindist)
				mindist = dist;
		}
	}
	
	return mindist;
}
 
开发者ID:hecoding,项目名称:Pac-Man,代码行数:23,代码来源:Game.java

示例13: getDistToClosestPill

import pacman.game.Constants.MOVE; //导入依赖的package包/类
/**
 * Returns the distance to the closest pill in any direction
 */
public int getDistToClosestPill(int pacmanNode){
	int mindist=Integer.MAX_VALUE;
	
	if(currentMaze.graph[pacmanNode].neighbourhood.size()==0)//lair
		return 0;
	
	int down = getDistToClosestPill4d(pacmanNode, MOVE.DOWN);
	int up = getDistToClosestPill4d(pacmanNode, MOVE.UP);
	int left = getDistToClosestPill4d(pacmanNode, MOVE.LEFT);
	int right = getDistToClosestPill4d(pacmanNode, MOVE.RIGHT);
	
	if(down < mindist)
		mindist = down;
	if(up < mindist)
		mindist = up;
	if(left < mindist)
		mindist = left;
	if(right < mindist)
		mindist = right;
	
	return mindist;
}
 
开发者ID:hecoding,项目名称:Pac-Man,代码行数:26,代码来源:Game.java

示例14: getClosestJunction

import pacman.game.Constants.MOVE; //导入依赖的package包/类
/**
 * Returns the index of the closest junction to the Pacman
 */
@Deprecated
public int getClosestJunction(int pacmanLocation, MOVE lastMoveMade)
{
	int[] junctionIndices = getJunctionIndices();
	
	int minJunctionIndex = junctionIndices[0];
	int minDistance = getShortestPathDistance(pacmanLocation, minJunctionIndex, lastMoveMade);
	for(int i = 1; i < junctionIndices.length; i++)
	{
		int junctionDist = getShortestPathDistance(pacmanLocation, junctionIndices[i], lastMoveMade);
		if(junctionDist < minDistance)
		{
			minJunctionIndex = junctionIndices[i];
			minDistance = junctionDist;
		}
	}
	
	return minJunctionIndex;
}
 
开发者ID:hecoding,项目名称:Pac-Man,代码行数:23,代码来源:Game.java

示例15: getClosestJunctionUpgraded

import pacman.game.Constants.MOVE; //导入依赖的package包/类
/**
 * Returns the index of the closest junction to Pacman following a direction
 * if pacmanLocation is a junction, returns the next junction
 * if the immediate first node is a wall, returns -1
 * the algorithm doesn't get stuck on corners
 */
public int getClosestJunctionUpgraded(int pacmanLocation, MOVE direction) {
	int oldNode = pacmanLocation;
	int currentNode = getNeighbour(pacmanLocation, direction);
	if (currentNode == -1)
		return -1;
	
	
	while(!isJunction(currentNode)) {
		int[] newNodes = getNeighbouringNodes(currentNode);
		if(newNodes[0] == oldNode) {
			oldNode = currentNode;
			currentNode = newNodes[1];
		}
		else {
			oldNode = currentNode;
			currentNode = newNodes[0];
		}
	}
	
	return currentNode;
}
 
开发者ID:hecoding,项目名称:Pac-Man,代码行数:28,代码来源:Game.java


注:本文中的pacman.game.Constants.MOVE类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。