-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
solution #542
base: master
Are you sure you want to change the base?
solution #542
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great start! Keep doing: arrows don't work, a user can just start or restart the game. Feel free to ask for help in the chat
It`s work with 'a' ,'d', 'w', 's'. please try |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/scripts/main.js
Outdated
document.addEventListener('keydown', e => { | ||
switch (e.key) { | ||
case 'a': { | ||
moveHorizontally(left); | ||
break; | ||
} | ||
|
||
case 'd': { | ||
moveHorizontally(right); | ||
break; | ||
} | ||
|
||
case 'w': { | ||
moveVertically(up); | ||
break; | ||
} | ||
|
||
case 's': { | ||
moveVertically(down); | ||
break; | ||
} | ||
} | ||
loseCheck(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add also ability to use arrows, will be really good improvement
src/scripts/main.js
Outdated
// const gameTable = document.querySelector('.game-field'); | ||
|
||
// let touchStartX = 0; | ||
// let touchStartY = 0; | ||
|
||
// document.addEventListener('touchmove', (e) => { | ||
// e.preventDefault(); | ||
// }); | ||
|
||
// gameTable.addEventListener('touchmove', (e) => { | ||
// e.preventDefault(); | ||
// }); | ||
|
||
// gameTable.addEventListener('touchstart', (e) => { | ||
// touchStartX = e.touches[0].clientX; | ||
// touchStartY = e.touches[0].clientY; | ||
// }); | ||
|
||
// gameTable.addEventListener('touchend', (e) => { | ||
// const touchEndX = e.changedTouches[0].clientX; | ||
// const touchEndY = e.changedTouches[0].clientY; | ||
// const touchDiffX = touchEndX - touchStartX; | ||
// const touchDiffY = touchEndY - touchStartY; | ||
// const breakPoint = 50; | ||
|
||
// if (Math.abs(touchDiffX) > Math.abs(touchDiffY)) { | ||
// if (touchDiffX > breakPoint) { | ||
// moveHorizontally(right); | ||
// loseCheck(); | ||
// } else if (touchDiffX < -1 * breakPoint) { | ||
// moveHorizontally(left); | ||
// loseCheck(); | ||
// } else if (touchDiffY > breakPoint) { | ||
// moveVertically(down); | ||
// loseCheck(); | ||
// } else if (touchDiffY < -1 * breakPoint) { | ||
// moveVertically(up); | ||
// loseCheck(); | ||
// } | ||
|
||
// switch (true) { | ||
// case (touchDiffX > breakPoint): | ||
// moveHorizontally(right); | ||
// break; | ||
// case (touchDiffX < -1 * breakPoint): | ||
// moveHorizontally(left); | ||
// break; | ||
// case (touchDiffY > breakPoint): | ||
// moveVertically(down); | ||
// break; | ||
// case (touchDiffY < -1 * breakPoint): | ||
// moveVertically(up); | ||
// break; | ||
// default: return 0; | ||
// } | ||
// loseCheck(); | ||
// } | ||
// }); | ||
|
||
// document.addEventListener('touchmove', (e) => { | ||
// e.preventDefault(); | ||
// }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove commented code
case 'a': { | ||
moveHorizontally(left); | ||
break; | ||
} | ||
|
||
case 'ArrowLeft': { | ||
moveHorizontally(left); | ||
break; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can combine these cases
case 'a': { | |
moveHorizontally(left); | |
break; | |
} | |
case 'ArrowLeft': { | |
moveHorizontally(left); | |
break; | |
} | |
case 'a': | |
case 'ArrowLeft': { | |
moveHorizontally(left); | |
break; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, the linter requires a 'break' after each 'case'. I asked this question in the chat, In this case it is impossible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
No description provided.