-
Notifications
You must be signed in to change notification settings - Fork 39
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
1 parent
0940484
commit e8eec12
Showing
7 changed files
with
156 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!DOCTYPE html> | ||
<html class="no-bg" lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="description" content="A video card game for the web" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, viewport-fit=cover" /> | ||
<title>Slay the Web</title> | ||
<meta name="mobile-web-app-capable" content="yes"> | ||
<meta name="theme-color" content="#116f54" /> | ||
<meta name="msapplication-TileColor" content="#116f54"> | ||
<link rel="icon" type="image/png" href="/images/favicons/favicon-512.png" sizes="512x512" /> | ||
<link rel="shortcut icon" href="/images/favicons/favicon.ico"> | ||
<link rel="apple-touch-icon" href="/images/favicon-512.png" /> | ||
</head> | ||
<body> | ||
|
||
<h1>Test</h1> | ||
|
||
<script async src="/src/ui/pages/main.js" type="module"></script> | ||
|
||
<noscript> | ||
<p> | ||
You need JavaScript enabled to play Slay The Web. | ||
See <a href="https://github.com/oskarrough/slaytheweb/">github.com/oskarrough/slaytheweb/</a>. | ||
</p> | ||
</noscript> | ||
|
||
</body> | ||
</html> |
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
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,2 @@ | ||
// import '../styles/index.css' | ||
import './slay-the-web.js' |
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,65 @@ | ||
import {html, render, Component} from '../lib.js' | ||
import SplashScreen from '../components/splash-screen.js' | ||
import GameScreen from '../components/game-screen.js' | ||
import WinScreen from '../components/win-screen.js' | ||
import {init as initSounds} from '../sounds.js' | ||
|
||
/** @enum {string} */ | ||
const GameModes = { | ||
splash: 'splash', | ||
gameplay: 'gameplay', | ||
win: 'win', | ||
} | ||
|
||
/** | ||
* Our root component for the game. | ||
* Controls what to render. | ||
*/ | ||
export default class SlayTheWeb extends Component { | ||
constructor() { | ||
super() | ||
const urlParams = new URLSearchParams(window.location.search) | ||
const initialGameMode = urlParams.has('debug') ? GameModes.gameplay : GameModes.splash | ||
this.state = {gameMode: initialGameMode} | ||
|
||
this.handleWin = this.handleWin.bind(this) | ||
this.handleNewGame = this.handleNewGame.bind(this) | ||
this.handleLoose = this.handleLoose.bind(this) | ||
} | ||
|
||
async handleNewGame() { | ||
await initSounds() | ||
this.setState({gameMode: GameModes.gameplay}) | ||
// Clear any previous saved game. | ||
window.history.pushState('', document.title, window.location.pathname) | ||
} | ||
|
||
handleContinue() { | ||
this.setState({gameMode: GameModes.gameplay}) | ||
} | ||
|
||
handleWin() { | ||
this.setState({gameMode: GameModes.win}) | ||
} | ||
|
||
handleLoose() { | ||
this.setState({gameMode: GameModes.splash}) | ||
} | ||
|
||
render(props, {gameMode}) { | ||
if (gameMode === GameModes.splash) | ||
return html`<${SplashScreen} onNewGame=${this.handleNewGame} onContinue=${this.handleContinue} />` | ||
if (gameMode === GameModes.gameplay) | ||
return html` <${GameScreen} onWin=${this.handleWin} onLoose=${this.handleLoose} /> ` | ||
if (gameMode === GameModes.win) return html` <${WinScreen} onNewGame=${this.handleNewGame} /> ` | ||
} | ||
} | ||
|
||
customElements.define( | ||
'slay-the-web', | ||
class SlayTheWebElement extends HTMLElement { | ||
connectedCallback() { | ||
render(html` <${SlayTheWeb} /> `, this) | ||
} | ||
}, | ||
) |