-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
111 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { UiText } from "../Ui/UiText"; | ||
import * as Constants from '../Constants'; | ||
|
||
export class UiManager { | ||
|
||
centerMessageFont = '50px Sans-Serif'; | ||
sideFont = '20px Sans-Serif'; | ||
|
||
constructor(canvas) { | ||
this.canvas = canvas; | ||
this.gameOverText = new UiText('GAME OVER', this.centerMessageFont, '#567567', Constants.TEXT_POSITION.CENTER); | ||
} | ||
|
||
drawGameOver(){ | ||
this.drawText(this.gameOverText); | ||
} | ||
|
||
drawText(textObject) { | ||
this.canvas.drawText(textObject.text, textObject.font, textObject.color, textObject.position); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { UiManager } from "../Core/UiManager"; | ||
import * as Constants from '../Constants'; | ||
import { UiText } from "../Ui/UiText"; | ||
|
||
let uiManager; | ||
|
||
describe('ui manager tests', () => { | ||
let initializeTests = () => { | ||
uiManager = new UiManager({}); | ||
}; | ||
|
||
beforeEach(() => { | ||
initializeTests(); | ||
}); | ||
|
||
test('should be initialized', () => { | ||
expect(uiManager).toBeDefined(); | ||
}); | ||
|
||
test('should draw game over', () => { | ||
|
||
uiManager.drawText = jest.fn(); | ||
|
||
uiManager.drawGameOver(); | ||
|
||
expect(uiManager.drawText).toBeCalled(); | ||
}); | ||
|
||
test('should draw text', () => { | ||
let testText = new UiText('testing', '50px Sans-Serif', '#567567', Constants.TEXT_POSITION.CENTER); | ||
|
||
uiManager.canvas.drawText = jest.fn(); | ||
|
||
uiManager.drawText(testText); | ||
|
||
expect(uiManager.canvas.drawText).toBeCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export class UiText { | ||
constructor(text, font, color, position) { | ||
this.text = text; | ||
this.font = font; | ||
this.color = color; | ||
this.position = position; | ||
} | ||
} |