-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
js game solution #1013
base: master
Are you sure you want to change the base?
js game solution #1013
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.
src/scripts/main.js
Outdated
case 'ArrowUp': | ||
e.preventDefault(); | ||
game.moveUp(); | ||
break; | ||
case 'ArrowRight': | ||
e.preventDefault(); | ||
game.moveRight(); | ||
break; | ||
case 'ArrowDown': | ||
e.preventDefault(); | ||
game.moveDown(); | ||
break; | ||
case 'ArrowLeft': |
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.
Create a variables for event key words and use it here
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.
good job in general
document.addEventListener('keydown', (e) => { | ||
switch (e.key) { | ||
case KEY_UP: | ||
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.
you can write it only one time before the switch/case
DEMO LINK