-
Notifications
You must be signed in to change notification settings - Fork 56
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
404 additions
and
318 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,64 @@ | ||
import Controller from "./controller.js"; | ||
import Store from "./store.js"; | ||
import View from "./view.js"; | ||
|
||
const store = new Store("game-state-key"); | ||
const view = new View(); | ||
const controller = new Controller(store, view); | ||
const config = { | ||
/** | ||
* A possible improvement to the game would be to allow for 3+ players | ||
* and a UI to show a leaderboard. This would require a refactor since | ||
* our logic assumes there are only 2 possible players. | ||
*/ | ||
player1: { | ||
id: 1, | ||
name: "Player 1", | ||
iconClass: "fa-x", | ||
colorClass: "turquoise", | ||
}, | ||
player2: { | ||
id: 2, | ||
name: "Player 2", | ||
iconClass: "fa-o", | ||
colorClass: "yellow", | ||
}, | ||
}; | ||
|
||
controller.init(); | ||
// MV* pattern | ||
function init() { | ||
// "Model" | ||
const store = new Store("game-state-key"); | ||
|
||
// "View" | ||
const view = new View(); | ||
|
||
/** | ||
* "Controller" logic (event listeners + handlers) | ||
*/ | ||
view.bindPlayerMoveEvent((squareId) => { | ||
store.playerMove(squareId); | ||
}); | ||
|
||
view.bindGameResetEvent(() => { | ||
view.closeAll(); | ||
store.reset(); | ||
}); | ||
|
||
view.bindNewRoundEvent(() => { | ||
view.closeAll(); | ||
store.newRound(); | ||
}); | ||
|
||
/** | ||
* ----------------------------------------------------------------------- | ||
* IMPORTANT: This is where we listen for state changes. When the state | ||
* changes, we re-render the entire application. | ||
* ----------------------------------------------------------------------- | ||
*/ | ||
store.addEventListener("statechange", (event) => { | ||
view.render(event.target); // event.target is the Store class instance | ||
}); | ||
|
||
// Loads existing state from local storage | ||
store.init(config); | ||
} | ||
|
||
// On window load, initialize app | ||
window.addEventListener("load", () => init()); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.