function moveTo(i, j) {

	var targetCell = gBoard[i][j];
	console.log(targetCell.type);
	if (targetCell.type === WALL) return;

	// Calculate distance to make sure we are moving to a neighbor cell
	// var iAbsDiff = Math.abs(i - gGamerPos.i);
	// var jAbsDiff = Math.abs(j - gGamerPos.j);

	// If the clicked Cell is one of the four allowed
	// if ((iAbsDiff === 1 && jAbsDiff === 0) || (jAbsDiff === 1 && iAbsDiff === 0)) {

	if (targetCell.gameElement === BALL) {
		var audioPlay = new Audio('img/pop.wav');
		audioPlay.play();
		gBallsCounter++;
		numOfCurrBallsOnBoard--;
		document.querySelector('h2 span').innerText = gBallsCounter;
		console.log('Collecting!');
		chackIfGameEnd();
	}

	// MOVING from current position
	// Model:
	gBoard[gGamerPos.i][gGamerPos.j].gameElement = null;
	// Dom:
	renderCell(gGamerPos, '');

	// MOVING to selected position
	// Model:
	gGamerPos.i = i;
	gGamerPos.j = j;
	gBoard[gGamerPos.i][gGamerPos.j].gameElement = GAMER;
	// DOM:
	renderCell(gGamerPos, GAMER_IMG);

} //else console.log('TOO FAR', iAbsDiff, jAbsDiff);
// Move the player to a specific location
Move the player to a specific location
Move the player to a specific location
function moveTo(i, j) {
	var targetCell = gBoard[i][j];
	console.log(targetCell.type);
	if (targetCell.type === WALL) return;
	if (targetCell.gameElement === BALL) {
		var audioPlay = new Audio('img/pop.wav');
		audioPlay.play();
		gBallsCounter++;
		numOfCurrBallsOnBoard--;
		document.querySelector('h2 span').innerText = gBallsCounter;
		console.log('Collecting!');
		chackIfGameEnd();
	}
	gBoard[gGamerPos.i][gGamerPos.j].gameElement = null;
	renderCell(gGamerPos, '');
	gGamerPos.i = i;
	gGamerPos.j = j;
	gBoard[gGamerPos.i][gGamerPos.j].gameElement = GAMER;
	renderCell(gGamerPos, GAMER_IMG);
} 
function moveTo ( i , j ) { var targetCell = gBoard [ i ] [ j ] ; console . log ( targetCell . type ) ; if ( targetCell . type === WALL ) return ; if ( targetCell . gameElement === BALL ) { var audioPlay = new Audio ( 'img/pop.wav' ) ; audioPlay . play ( ) ; gBallsCounter ++ ; numOfCurrBallsOnBoard -- ; document . querySelector ( 'h2 span' ) . innerText = gBallsCounter ; console . log ( 'Collecting!' ) ; chackIfGameEnd ( ) ; } gBoard [ gGamerPos . i ] [ gGamerPos . j ] . gameElement = null ; renderCell ( gGamerPos , '' ) ; gGamerPos . i = i ; gGamerPos . j = j ; gBoard [ gGamerPos . i ] [ gGamerPos . j ] . gameElement = GAMER ; renderCell ( gGamerPos , GAMER_IMG ) ; }
Move the player to a specific location
Move the player to a specific location
// Calculate distance to make sure we are moving to a neighbor cell // var iAbsDiff = Math.abs(i - gGamerPos.i); // var jAbsDiff = Math.abs(j - gGamerPos.j); // If the clicked Cell is one of the four allowed // if ((iAbsDiff === 1 && jAbsDiff === 0) || (jAbsDiff === 1 && iAbsDiff === 0)) { // MOVING from current position // Model: // Dom: // MOVING to selected position // Model: // DOM: //else console.log('TOO FAR', iAbsDiff, jAbsDiff);