From 50d37a444e732cb27e38311e42e7f79c4f1c7754 Mon Sep 17 00:00:00 2001 From: "ayoub.bouhmadi@usmba.ac.ma" Date: Mon, 26 Oct 2026 16:37:13 +0100 Subject: [PATCH 01/11] add game rules to index.html --- index.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index bdaf182..dd68134 100644 --- a/index.html +++ b/index.html @@ -69,7 +69,11 @@

2048

- +

+ How to play: + Use your arrow keys to move the tiles. When two tiles with + the same number touch, they merge into one! first commit +

From ee9f9e39b5c4b0b7f410f9c0151f4536990e905f Mon Sep 17 00:00:00 2001 From: "ayoub.bouhmadi@usmba.ac.ma" Date: Mon, 26 Oct 2026 18:04:34 +0100 Subject: [PATCH 02/11] fix tests --- __tests__/keyboard_input_manager.test.ts | 117 ++++++++++++++++++++++- 1 file changed, 114 insertions(+), 3 deletions(-) diff --git a/__tests__/keyboard_input_manager.test.ts b/__tests__/keyboard_input_manager.test.ts index 15a53d2..68a066a 100644 --- a/__tests__/keyboard_input_manager.test.ts +++ b/__tests__/keyboard_input_manager.test.ts @@ -1,13 +1,124 @@ import { jest } from '@jest/globals' +const { KeyboardInputManager } = await import( + '../src/keyboard_input_manager.js' +) + describe('KeyboardInputManager', () => { afterEach(() => { jest.resetAllMocks() }) - describe('todo', () => { - it('Create some unit tests', async () => { - expect(true).toBe(true) + describe('on()', () => { + it('Registers an event listener', async () => { + KeyboardInputManager.events['test'] = [] + + KeyboardInputManager.on('test', () => {}) + + expect(KeyboardInputManager.events['test'].length).toBe(1) + }) + + it('Creates an listener array if it does not exist', async () => { + KeyboardInputManager.events = {} + + KeyboardInputManager.on('test', () => {}) + + expect(KeyboardInputManager.events['test'].length).toBe(1) + }) + }) + + describe('emit()', () => { + let callback1: any + let callback2: any + + beforeEach(() => { + callback1 = jest.fn() + callback2 = jest.fn() + }) + + it('Emits an event to all listeners', async () => { + KeyboardInputManager.events['test'] = [callback1, callback2] + KeyboardInputManager.emit('test') + + expect(callback1).toHaveBeenCalledTimes(1) + expect(callback2).toHaveBeenCalledTimes(1) + }) + + it('Passes data to listeners', async () => { + KeyboardInputManager.events['test'] = [callback1, callback2] + KeyboardInputManager.emit('test', 'data') + + expect(callback1).toHaveBeenCalledWith('data') + expect(callback2).toHaveBeenCalledWith('data') + }) + + it('Does nothing if the event does not exist', async () => { + KeyboardInputManager.events = {} + KeyboardInputManager.emit('test') + + expect(callback1).not.toHaveBeenCalled() + expect(callback2).not.toHaveBeenCalled() + }) + }) + + describe('restart()', () => { + it('Emits a restart event', async () => { + const preventDefault = jest.fn() + const event = { + preventDefault + } + const emit = jest + .spyOn(KeyboardInputManager, 'emit') + .mockImplementation(() => {}) + + KeyboardInputManager.restart(event as unknown as Event) + + expect(emit).toHaveBeenCalledTimes(1) + expect(preventDefault).toHaveBeenCalledTimes(1) + }) + }) + + describe('constructor', () => { + it('Sets events and listens', async () => { + // Lab 3: Git Bisect + const listen = jest + .spyOn(KeyboardInputManager, 'listen') + .mockImplementation(() => {}) + + new KeyboardInputManager() + + expect(KeyboardInputManager.events).toMatchObject({}) + expect(listen).toHaveBeenCalledTimes(1) + }) + }) + + describe('keepPlaying()', () => { + it('Emits a keepPlaying event', async () => { + const preventDefault = jest.fn() + const event = { + preventDefault + } + const emit = jest + .spyOn(KeyboardInputManager, 'emit') + .mockImplementation(() => {}) + + KeyboardInputManager.keepPlaying(event as unknown as Event) + + expect(emit).toHaveBeenCalledTimes(1) + expect(preventDefault).toHaveBeenCalledTimes(1) + }) + }) + + describe('bindButtonPress()', () => { + it('Binds a button press', async () => { + const addEventListener = jest.fn() + document.querySelector = jest.fn().mockReturnValue({ + addEventListener + }) + + KeyboardInputManager.bindButtonPress('.test', () => {}) + + expect(addEventListener).toHaveBeenCalledTimes(1) }) }) }) From d12619c142c2adb650bf34c7739a1b1557fd0785 Mon Sep 17 00:00:00 2001 From: "ayoub.bouhmadi@usmba.ac.ma" Date: Mon, 26 Oct 2026 18:43:14 +0100 Subject: [PATCH 03/11] test git diff --- index.html | 2 -- 1 file changed, 2 deletions(-) diff --git a/index.html b/index.html index dd68134..8233a2b 100644 --- a/index.html +++ b/index.html @@ -75,8 +75,6 @@

2048

the same number touch, they merge into one! first commit

- - From 4e283dc76d9da5dd1eb1152730906dcdadac49ab Mon Sep 17 00:00:00 2001 From: "ayoub.bouhmadi@usmba.ac.ma" Date: Tue, 27 Oct 2026 10:17:50 +0100 Subject: [PATCH 04/11] revDeOOODrt the rules of tOhe game --- index.html | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/index.html b/index.html index 8233a2b..29a3cf8 100644 --- a/index.html +++ b/index.html @@ -69,11 +69,7 @@

2048

-

- How to play: - Use your arrow keys to move the tiles. When two tiles with - the same number touch, they merge into one! first commit -

+ From ea980fbbfed89771667cd5fe76b940b1109f22c0 Mon Sep 17 00:00:00 2001 From: "ayoub.bouhmadi@usmba.ac.ma" Date: Tue, 27 Oct 2026 10:17:50 +0100 Subject: [PATCH 05/11] get back to original fixation --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 8233a2b..ed2edb1 100644 --- a/index.html +++ b/index.html @@ -72,7 +72,7 @@

2048

How to play: Use your arrow keys to move the tiles. When two tiles with - the same number touch, they merge into one! first commit + the same number touch, they merge into one!

From 3d316489fae27e69921ea8cfa00eb98ff34f407e Mon Sep 17 00:00:00 2001 From: "ayoub.bouhmadi@usmba.ac.ma" Date: Tue, 27 Oct 2026 12:35:49 +0100 Subject: [PATCH 06/11] Add new game button listener --- src/keyboard_input_manager.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/keyboard_input_manager.ts b/src/keyboard_input_manager.ts index 308dee2..e1a688f 100644 --- a/src/keyboard_input_manager.ts +++ b/src/keyboard_input_manager.ts @@ -82,6 +82,11 @@ export class KeyboardInputManager { ) // Lab 5: New Game Button + // Lab 5: New Game Button +KeyboardInputManager.bindButtonPress( + '.restart-button', + KeyboardInputManager.restart +) } /** From 44f49cd852a4155f34ade5c685b80308bf3f9b98 Mon Sep 17 00:00:00 2001 From: "ayoub.bouhmadi@usmba.ac.ma" Date: Tue, 27 Oct 2026 12:37:35 +0100 Subject: [PATCH 07/11] Revert "Add new game button listener" This reverts commit 3d316489fae27e69921ea8cfa00eb98ff34f407e. --- src/keyboard_input_manager.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/keyboard_input_manager.ts b/src/keyboard_input_manager.ts index e1a688f..308dee2 100644 --- a/src/keyboard_input_manager.ts +++ b/src/keyboard_input_manager.ts @@ -82,11 +82,6 @@ export class KeyboardInputManager { ) // Lab 5: New Game Button - // Lab 5: New Game Button -KeyboardInputManager.bindButtonPress( - '.restart-button', - KeyboardInputManager.restart -) } /** From f1e3862063702370bb542ebe07372364a21c083c Mon Sep 17 00:00:00 2001 From: "ayoub.bouhmadi@usmba.ac.ma" Date: Tue, 27 Oct 2026 12:38:51 +0100 Subject: [PATCH 08/11] Add new game button listener --- src/keyboard_input_manager.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/keyboard_input_manager.ts b/src/keyboard_input_manager.ts index 308dee2..725813b 100644 --- a/src/keyboard_input_manager.ts +++ b/src/keyboard_input_manager.ts @@ -81,7 +81,12 @@ export class KeyboardInputManager { KeyboardInputManager.keepPlaying ) - // Lab 5: New Game Button + // Lab 5: New Game Button +KeyboardInputManager.bindButtonPress( + '.restart-button', + KeyboardInputManager.restart +) + } /** From 6bed71d64c33f133fe049d384768a011104d2503 Mon Sep 17 00:00:00 2001 From: "ayoub.bouhmadi@usmba.ac.ma" Date: Tue, 27 Oct 2026 13:28:06 +0100 Subject: [PATCH 09/11] Add CODEOWNERS file --- .github/CODEOWNERS | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..768e705 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,3 @@ +# Game Project Code Owners + +* @ayoub0071997 \ No newline at end of file From 0427577696c7141ca613a914640e643395a7bda3 Mon Sep 17 00:00:00 2001 From: "ayoub.bouhmadi@usmba.ac.ma" Date: Tue, 27 Oct 2026 13:36:57 +0100 Subject: [PATCH 10/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 138c03e..d043fb5 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # GitHub Intermediate - Project Repository - +This is an update to the README.md file! ![Continuous Integration](https://github.com/githubschool/gh-github-intermediate-template/actions/workflows/continuous-integration.yml/badge.svg) ![Continuous Delivery](https://github.com/githubschool/gh-github-intermediate-template/actions/workflows/continuous-delivery.yml/badge.svg) ![CodeQL](https://github.com/githubschool/gh-github-intermediate-template/actions/workflows/codeql.yml/badge.svg) From 3f55681857ff5fd2c787eb78a14f9b5403aef09f Mon Sep 17 00:00:00 2001 From: "ayoub.bouhmadi@usmba.ac.ma" Date: Tue, 27 Oct 2026 13:41:28 +0100 Subject: [PATCH 11/11] Update README.md2 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d043fb5..98b19bd 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # GitHub Intermediate - Project Repository This is an update to the README.md file! +This is an update to the README.md file2! ![Continuous Integration](https://github.com/githubschool/gh-github-intermediate-template/actions/workflows/continuous-integration.yml/badge.svg) ![Continuous Delivery](https://github.com/githubschool/gh-github-intermediate-template/actions/workflows/continuous-delivery.yml/badge.svg) ![CodeQL](https://github.com/githubschool/gh-github-intermediate-template/actions/workflows/codeql.yml/badge.svg)