-2
Есть ли способ сделать условное утверждение ниже короче? Существует много повторений, как вы можете увидеть:js - сокращать условное заявление
var searchArea = function() {
// Search the area around the current position for hidden doors
if(detectWall('left') == 2) {
status.innerHTML = "Hidden Door to the left";
} else if (detectWall('right') == 2) {
status.innerHTML = "Hidden door to the right";
} else if (detectWall('up') == 2) {
status.innerHTML = "Hidden door above you";
} else if (detectWall('down') == 2) {
status.innerHTML = "Hidden door below you";
} else if (detectWall('right') == 3 || detectWall('left') == 3 || detectWall('up') == 3 || detectWall('down') == 3) {
status.innerHTML = "You are close to the fountain";
}
}
И функция detectWall для справки:
var detectWall = function(dir) {
// Detect walls from the array
switch(dir) {
case 'right':
return mapArray[parseInt(player.y/20)][parseInt((player.x+20)/20)]
case 'left':
return mapArray[parseInt(player.y/20)][parseInt((player.x-20)/20)]
case 'up':
return mapArray[parseInt((player.y-20)/20)][parseInt(player.x/20)]
case 'down':
return mapArray[parseInt((player.y+20)/20)][parseInt(player.x/20)]
default:
return false
}
}
Спасибо вам
Да, есть люди, в [Обзор кода] (http://codereview.stackexchange.com/), или даже на [сайте для гольфа] (http://codegolf.stackexchange.com/) для фанки решения, несомненно, помогут вам. – adeneo
Перед публикацией обязательно проверьте их [руководство по отправке] (http://codereview.stackexchange.com/help/how-to-ask). –
ОК. Спасибо - не знал раздел обзора кода. – Wasteland