package nl.noscope.emeraldextraction.objects;_x000D_
_x000D_
import android.util.Log;_x000D_
import nl.saxion.act.playground.model.GameBoard;_x000D_
import nl.saxion.act.playground.model.GameObject;_x000D_
_x000D_
/**_x000D_
 * De miner is ons speler object, deze verplaatst zich dan ook steeds_x000D_
 * _x000D_
 * @author Boyd_x000D_
 */_x000D_
public class Miner extends GameObject {_x000D_
	public static final String MINER_IMAGE = "miner";_x000D_
	public static final String MINER_UP = "up";_x000D_
	public static final String MINER_DOWN = "down";_x000D_
	public static final String MINER_LEFT = "links";_x000D_
	public static final String MINER_RIGHT = "rechts";_x000D_
	_x000D_
	int position = 0;_x000D_
	_x000D_
_x000D_
	/** Returns the ImageId of the image to show. */_x000D_
	@Override_x000D_
	public String getImageId() {_x000D_
		if (position == 1) {_x000D_
			return MINER_LEFT;	_x000D_
		}  else if (position == 2) {_x000D_
			return MINER_RIGHT;	_x000D_
		}  else if (position == 3) {_x000D_
			return MINER_UP;	_x000D_
		} else if (position == 4) {_x000D_
			return MINER_DOWN;	_x000D_
		} else {_x000D_
			return MINER_IMAGE;_x000D_
		}_x000D_
	}_x000D_
	_x000D_
	_x000D_
_x000D_
	public void walkLeft(GameBoard gameBoard) {_x000D_
		_x000D_
		position = 1;_x000D_
_x000D_
		int newPosX = getPositionX() - 1;_x000D_
		int newPosY = getPositionY();_x000D_
_x000D_
		StateCheck(newPosX, newPosY, gameBoard, position);_x000D_
		_x000D_
	}_x000D_
_x000D_
	public void walkRight(GameBoard gameBoard) {_x000D_
_x000D_
		position = 2;_x000D_
		_x000D_
		int newPosX = getPositionX() + 1;_x000D_
		int newPosY = getPositionY();_x000D_
		StateCheck(newPosX, newPosY, gameBoard, position);_x000D_
	}_x000D_
_x000D_
	public void walkUp(GameBoard gameBoard) {_x000D_
_x000D_
		position = 3;_x000D_
		_x000D_
		int newPosX = getPositionX();_x000D_
		int newPosY = getPositionY() - 1;_x000D_
_x000D_
		StateCheck(newPosX, newPosY, gameBoard, position);_x000D_
	}_x000D_
_x000D_
	public void walkDown(GameBoard gameBoard) {_x000D_
_x000D_
		position = 4;_x000D_
		_x000D_
		int newPosX = getPositionX();_x000D_
		int newPosY = getPositionY() + 1;_x000D_
		_x000D_
		StateCheck(newPosX, newPosY, gameBoard, position);_x000D_
	_x000D_
	}_x000D_
_x000D_
	private void StateCheck(int newPosX, int newPosY, GameBoard gameBoard, int direction) {_x000D_
		// Als de nieuwe positie naast het bord is doet hij niks_x000D_
		if (newPosX >= gameBoard.getWidth() - 1 || newPosX == 0) {_x000D_
			return;_x000D_
		} else if (newPosY >= gameBoard.getHeight() - 1 || newPosY == 0){_x000D_
			return;_x000D_
		}_x000D_
		_x000D_
		// Kijk of er een object is op het nieuwe punt_x000D_
		GameObject objectAtNewPos = gameBoard.getObject(newPosX, newPosY);_x000D_
		if (objectAtNewPos != null) {_x000D_
_x000D_
			// Miner kan niet door een aantal objecten heen_x000D_
			if (objectAtNewPos instanceof Stone) {_x000D_
				return;_x000D_
			}_x000D_
			if (objectAtNewPos instanceof Iron) {_x000D_
				return;_x000D_
			}_x000D_
			if (objectAtNewPos instanceof Minecart) {_x000D_
				return;_x000D_
			}_x000D_
_x000D_
			if (objectAtNewPos instanceof Emerald) {_x000D_
				// Je kan een emerald niet naar beneden drukken_x000D_
				if (direction == 4) { return; }_x000D_
				// Duw de emerald omhoog als er vrije ruimte boven is_x000D_
				if (direction == 3) {_x000D_
					if (gameBoard.getObject(newPosX, newPosY - 1) == null) {_x000D_
						gameBoard.moveObject(objectAtNewPos, newPosX, newPosY - 1);_x000D_
					}_x000D_
					else { return; }_x000D_
				}_x000D_
				// Duw de emerald naar links als er vrije ruimte links van de emerald is_x000D_
				if (direction == 1) {_x000D_
					if (gameBoard.getObject(newPosX - 1, newPosY) == null) {_x000D_
						gameBoard.moveObject(objectAtNewPos, newPosX -1, newPosY);_x000D_
					}_x000D_
					else { return; }_x000D_
				}_x000D_
				// Duw de emerald naar rechts als er vrije ruimte rechts van de emerald is_x000D_
				if (direction == 2) {_x000D_
					if (gameBoard.getObject(newPosX + 1, newPosY) == null) {_x000D_
						gameBoard.moveObject(objectAtNewPos, newPosX + 1, newPosY);_x000D_
					}_x000D_
					else { return ; }_x000D_
				}_x000D_
			}_x000D_
			if (objectAtNewPos instanceof StoneMove) {_x000D_
				// Je kan een emerald niet naar beneden drukken_x000D_
				if (direction == 4) { return; }_x000D_
				// Duw de emerald omhoog als er vrije ruimte boven is_x000D_
				if (direction == 3) {_x000D_
					if (gameBoard.getObject(newPosX, newPosY - 1) == null) {_x000D_
						gameBoard.moveObject(objectAtNewPos, newPosX, newPosY - 1);_x000D_
					}_x000D_
					else { return; }_x000D_
				}_x000D_
				// Duw de emerald naar links als er vrije ruimte links van de emerald is_x000D_
				if (direction == 1) {_x000D_
					if (gameBoard.getObject(newPosX - 1, newPosY) == null) {_x000D_
						gameBoard.moveObject(objectAtNewPos, newPosX -1, newPosY);_x000D_
					}_x000D_
					else { return; }_x000D_
				}_x000D_
				// Duw de emerald naar rechts als er vrije ruimte rechts van de emerald is_x000D_
				if (direction == 2) {_x000D_
					if (gameBoard.getObject(newPosX + 1, newPosY) == null) {_x000D_
						gameBoard.moveObject(objectAtNewPos, newPosX + 1, newPosY);_x000D_
					}_x000D_
					else { return ; }_x000D_
				}_x000D_
			}_x000D_
			_x000D_
			if (objectAtNewPos instanceof Sand) {_x000D_
				gameBoard.removeObject(objectAtNewPos);_x000D_
_x000D_
			}_x000D_
		}_x000D_
_x000D_
		// Verplaats de miner naar zijn nieuwe positie_x000D_
		//Log.d("Miner", "Ik verplaats nu de miner");_x000D_
		gameBoard.moveObject(this, newPosX, newPosY);_x000D_
		//gameBoard.updateView();_x000D_
		Log.d("Miner", "Miner verplaatst");_x000D_
		_x000D_
	}_x000D_
_x000D_
	@Override_x000D_
	public void onTouched(GameBoard gameBoard) {_x000D_
		// TODO Auto-generated method stub_x000D_
_x000D_
	}_x000D_
}_x000D_

// Verplaats de miner naar zijn nieuwe positie_x000D_
package nl.noscope.emeraldextraction.objects;_x000D_
_x000D_
import android.util.Log;_x000D_
import nl.saxion.act.playground.model.GameBoard;_x000D_
import nl.saxion.act.playground.model.GameObject;_x000D_
_x000D_
/**_x000D_
 * De miner is ons speler object, deze verplaatst zich dan ook steeds_x000D_
 * _x000D_
 * @author Boyd_x000D_
 */_x000D_
public class Miner extends GameObject {_x000D_
	public static final String MINER_IMAGE = "miner";_x000D_
	public static final String MINER_UP = "up";_x000D_
	public static final String MINER_DOWN = "down";_x000D_
	public static final String MINER_LEFT = "links";_x000D_
	public static final String MINER_RIGHT = "rechts";_x000D_
	_x000D_
	int position = 0;_x000D_
	_x000D_
_x000D_
	/** Returns the ImageId of the image to show. */_x000D_
	@Override_x000D_
	public String getImageId() {_x000D_
		if (position == 1) {_x000D_
			return MINER_LEFT;	_x000D_
		}  else if (position == 2) {_x000D_
			return MINER_RIGHT;	_x000D_
		}  else if (position == 3) {_x000D_
			return MINER_UP;	_x000D_
		} else if (position == 4) {_x000D_
			return MINER_DOWN;	_x000D_
		} else {_x000D_
			return MINER_IMAGE;_x000D_
		}_x000D_
	}_x000D_
	_x000D_
	_x000D_
_x000D_
	public void walkLeft(GameBoard gameBoard) {_x000D_
		_x000D_
		position = 1;_x000D_
_x000D_
		int newPosX = getPositionX() - 1;_x000D_
		int newPosY = getPositionY();_x000D_
_x000D_
		StateCheck(newPosX, newPosY, gameBoard, position);_x000D_
		_x000D_
	}_x000D_
_x000D_
	public void walkRight(GameBoard gameBoard) {_x000D_
_x000D_
		position = 2;_x000D_
		_x000D_
		int newPosX = getPositionX() + 1;_x000D_
		int newPosY = getPositionY();_x000D_
		StateCheck(newPosX, newPosY, gameBoard, position);_x000D_
	}_x000D_
_x000D_
	public void walkUp(GameBoard gameBoard) {_x000D_
_x000D_
		position = 3;_x000D_
		_x000D_
		int newPosX = getPositionX();_x000D_
		int newPosY = getPositionY() - 1;_x000D_
_x000D_
		StateCheck(newPosX, newPosY, gameBoard, position);_x000D_
	}_x000D_
_x000D_
	public void walkDown(GameBoard gameBoard) {_x000D_
_x000D_
		position = 4;_x000D_
		_x000D_
		int newPosX = getPositionX();_x000D_
		int newPosY = getPositionY() + 1;_x000D_
		_x000D_
		StateCheck(newPosX, newPosY, gameBoard, position);_x000D_
	_x000D_
	}_x000D_
_x000D_
	private void StateCheck(int newPosX, int newPosY, GameBoard gameBoard, int direction) {_x000D_
		// Als de nieuwe positie naast het bord is doet hij niks_x000D_
		if (newPosX >= gameBoard.getWidth() - 1 || newPosX == 0) {_x000D_
			return;_x000D_
		} else if (newPosY >= gameBoard.getHeight() - 1 || newPosY == 0){_x000D_
			return;_x000D_
		}_x000D_
		_x000D_
		// Kijk of er een object is op het nieuwe punt_x000D_
		GameObject objectAtNewPos = gameBoard.getObject(newPosX, newPosY);_x000D_
		if (objectAtNewPos != null) {_x000D_
_x000D_
			// Miner kan niet door een aantal objecten heen_x000D_
			if (objectAtNewPos instanceof Stone) {_x000D_
				return;_x000D_
			}_x000D_
			if (objectAtNewPos instanceof Iron) {_x000D_
				return;_x000D_
			}_x000D_
			if (objectAtNewPos instanceof Minecart) {_x000D_
				return;_x000D_
			}_x000D_
_x000D_
			if (objectAtNewPos instanceof Emerald) {_x000D_
				// Je kan een emerald niet naar beneden drukken_x000D_
				if (direction == 4) { return; }_x000D_
				// Duw de emerald omhoog als er vrije ruimte boven is_x000D_
				if (direction == 3) {_x000D_
					if (gameBoard.getObject(newPosX, newPosY - 1) == null) {_x000D_
						gameBoard.moveObject(objectAtNewPos, newPosX, newPosY - 1);_x000D_
					}_x000D_
					else { return; }_x000D_
				}_x000D_
				// Duw de emerald naar links als er vrije ruimte links van de emerald is_x000D_
				if (direction == 1) {_x000D_
					if (gameBoard.getObject(newPosX - 1, newPosY) == null) {_x000D_
						gameBoard.moveObject(objectAtNewPos, newPosX -1, newPosY);_x000D_
					}_x000D_
					else { return; }_x000D_
				}_x000D_
				// Duw de emerald naar rechts als er vrije ruimte rechts van de emerald is_x000D_
				if (direction == 2) {_x000D_
					if (gameBoard.getObject(newPosX + 1, newPosY) == null) {_x000D_
						gameBoard.moveObject(objectAtNewPos, newPosX + 1, newPosY);_x000D_
					}_x000D_
					else { return ; }_x000D_
				}_x000D_
			}_x000D_
			if (objectAtNewPos instanceof StoneMove) {_x000D_
				// Je kan een emerald niet naar beneden drukken_x000D_
				if (direction == 4) { return; }_x000D_
				// Duw de emerald omhoog als er vrije ruimte boven is_x000D_
				if (direction == 3) {_x000D_
					if (gameBoard.getObject(newPosX, newPosY - 1) == null) {_x000D_
						gameBoard.moveObject(objectAtNewPos, newPosX, newPosY - 1);_x000D_
					}_x000D_
					else { return; }_x000D_
				}_x000D_
				// Duw de emerald naar links als er vrije ruimte links van de emerald is_x000D_
				if (direction == 1) {_x000D_
					if (gameBoard.getObject(newPosX - 1, newPosY) == null) {_x000D_
						gameBoard.moveObject(objectAtNewPos, newPosX -1, newPosY);_x000D_
					}_x000D_
					else { return; }_x000D_
				}_x000D_
				// Duw de emerald naar rechts als er vrije ruimte rechts van de emerald is_x000D_
				if (direction == 2) {_x000D_
					if (gameBoard.getObject(newPosX + 1, newPosY) == null) {_x000D_
						gameBoard.moveObject(objectAtNewPos, newPosX + 1, newPosY);_x000D_
					}_x000D_
					else { return ; }_x000D_
				}_x000D_
			}_x000D_
			_x000D_
			if (objectAtNewPos instanceof Sand) {_x000D_
				gameBoard.removeObject(objectAtNewPos);_x000D_
_x000D_
			}_x000D_
		}_x000D_
_x000D_
		// Verplaats de<SUF>
		//Log.d("Miner", "Ik verplaats nu de miner");_x000D_
		gameBoard.moveObject(this, newPosX, newPosY);_x000D_
		//gameBoard.updateView();_x000D_
		Log.d("Miner", "Miner verplaatst");_x000D_
		_x000D_
	}_x000D_
_x000D_
	@Override_x000D_
	public void onTouched(GameBoard gameBoard) {_x000D_
		// TODO Auto-generated method stub_x000D_
_x000D_
	}_x000D_
}_x000D_
