function moveTo(i, j) {
	// var currPos = gGamerPos;


	// 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 (i === -1) {
			i = 9;
		}
	
		if (i === 10) {
			i = 0;
		}
		if (j === -1) {
			j = 11;
		}
	
		if (j === 12) {
			j = 0;
		}

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

		if (targetCell.gameElement === BALL) {
			gCollectedBallsCnt++
			// playSound()
			gPopSound.play();
			gameOver()
		}

		// 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 iAbsDiff = Math.abs(i - gGamerPos.i);
	var jAbsDiff = Math.abs(j - gGamerPos.j);
	if ((iAbsDiff === 1 && jAbsDiff === 0) || (jAbsDiff === 1 && iAbsDiff === 0)) {
		if (i === -1) {
			i = 9;
		}
		if (i === 10) {
			i = 0;
		}
		if (j === -1) {
			j = 11;
		}
		if (j === 12) {
			j = 0;
		}
		var targetCell = gBoard[i][j];
		if (targetCell.type === WALL) return;
		if (targetCell.gameElement === BALL) {
			gCollectedBallsCnt++
			gPopSound.play();
			gameOver()
		}
		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 iAbsDiff = Math . abs ( i - gGamerPos . i ) ; var jAbsDiff = Math . abs ( j - gGamerPos . j ) ; if ( ( iAbsDiff === 1 && jAbsDiff === 0 ) || ( jAbsDiff === 1 && iAbsDiff === 0 ) ) { if ( i === - 1 ) { i = 9 ; } if ( i === 10 ) { i = 0 ; } if ( j === - 1 ) { j = 11 ; } if ( j === 12 ) { j = 0 ; } var targetCell = gBoard [ i ] [ j ] ; if ( targetCell . type === WALL ) return ; if ( targetCell . gameElement === BALL ) { gCollectedBallsCnt ++ gPopSound . play ( ) ; gameOver ( ) } 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
// var currPos = gGamerPos; // Calculate distance to make sure we are moving to a neighbor cell // If the clicked Cell is one of the four allowed // playSound() // MOVING from current position // Model: // Dom: // MOVING to selected position // Model: // DOM: // else console.log('TOO FAR', iAbsDiff, jAbsDiff);