Skip to content

Commit

Permalink
🔧 chore(index.css): remove unnecessary styles from body element to im…
Browse files Browse the repository at this point in the history
…prove code readability and maintainability

🔧 chore(index.css): refactor control section styles to improve code readability and maintainability
🔧 chore(index.html): restructure HTML markup to improve semantics and readability
🔧 chore(background.js): fix import statement to match the correct file name
✨ feat(dom-manager.js): add DomManager class to manage DOM elements for easy access and manipulation
✨ feat(event-handler.js): update event listeners to use DomManager for better code organization and readability
✨ feat(game.js): update import statement to match the correct file name
✨ feat(index.js): update import statement to match the correct file name
✨ feat(mario.js): update import statement to match the correct file name
✨ feat(obstacle.js): update import statement to match the correct file name
  • Loading branch information
romantech committed Jan 21, 2024
1 parent 909be84 commit a399499
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 20 deletions.
8 changes: 2 additions & 6 deletions index.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
body {
margin: 0;
padding: 2rem;
}

.game {
width: 100%;
min-height: 440px;
Expand Down Expand Up @@ -38,9 +33,10 @@ body {
}

.control {
background-color: #6990f6;
display: flex;
align-items: center;
padding: 0px 20px;
padding: 0 1rem;
}

.score-heading {
Expand Down
15 changes: 8 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@
<title>Super Mario</title>
</head>
<body>
<h2>Super Mario</h2>
<main class="game">
<main>
<h2>Super Mario</h2>
<section class="control">
<div class="button-group">
<nav class="button-group">
<button class="start-button" type="button">Start</button>
<button class="stop-button" type="button">Stop</button>
</div>
</nav>
<h3 class="score-heading">Score <span class="score">0</span></h3>
</section>
<section class="game"></section>
<aside class="guide">
<p>Press <kbd>space</kbd> or <kbd>touch</kbd> to jump</p>
</aside>
</main>
<span class="guide"
>Press <kbd>space</kbd> or <kbd>touch</kbd> to jump</span
>
<script src="./main.js" type="module"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion src/background.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import DomManager from './domManager.js';
import DomManager from './dom-manager.js';

class Background {
constructor({ speed }) {
Expand Down
File renamed without changes.
8 changes: 6 additions & 2 deletions src/event-handler.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import DomManager from './dom-manager.js';

export default class EventHandler {
constructor(action) {
this.action = action;
Expand All @@ -8,12 +10,14 @@ export default class EventHandler {

setupEventListeners() {
document.addEventListener('keydown', this.handleKeyDown);
document.addEventListener('touchstart', this.handleTouch);
DomManager.gameArea.addEventListener('touchstart', this.handleTouch, {
passive: false, // event.preventDefault() 호출할 것이라고 브라우저에게 알림
});
}

removeEventListeners() {
document.removeEventListener('keydown', this.handleKeyDown);
document.removeEventListener('touchstart', this.handleTouch);
DomManager.gameArea.removeEventListener('touchstart', this.handleTouch);
}

handleKeyDown(e) {
Expand Down
2 changes: 1 addition & 1 deletion src/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Mario from './mario.js';
import Background from './background.js';
import ObstacleManager from './obstacle.js';
import EventHandler from './event-handler.js';
import DomManager from './domManager.js';
import DomManager from './dom-manager.js';

const generateRandomNumber = (min, max) => {
return Math.floor(Math.random() * (max - min + 1)) + min;
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export { default as Mario } from './mario.js';
export { default as Game } from './game.js';
export { default as Background } from './background.js';
export { default as ObstacleManager } from './obstacle.js';
export { default as DomManager } from './domManager.js';
export { default as DomManager } from './dom-manager.js';
2 changes: 1 addition & 1 deletion src/mario.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import DomManager from './domManager.js';
import DomManager from './dom-manager.js';

class Mario {
static jumpHeight = 18;
Expand Down
2 changes: 1 addition & 1 deletion src/obstacle.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import DomManager from './domManager.js';
import DomManager from './dom-manager.js';

class ObstacleManager {
constructor() {
Expand Down

0 comments on commit a399499

Please sign in to comment.