Skip to content

Commit

Permalink
Easy mode is unset when going online
Browse files Browse the repository at this point in the history
  • Loading branch information
mothepro committed Mar 8, 2021
1 parent 76571ce commit 3b1b3c6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 1 addition & 3 deletions demo/astroturf.ts
Expand Up @@ -77,13 +77,11 @@ class AstroPeer implements MockPeer<ArrayBuffer> {
readonly name: string,
/** Positive number to determine the skill, the lower the better */
readonly difficulty = Math.random()) {
addEventListener('p2p-update', this.startGame)
p2pDemoElement.addEventListener('game-restart', this.startGame)
p2pDemoElement.addEventListener('game-start', this.startGame)
}

private startGame = async () => {
this.engine = p2pDemoElement.engine
// this.currentRound = 0 // shouldn't matter

for await (const _ of this.engine.filled)
this.round(++this.currentRound)
Expand Down
9 changes: 6 additions & 3 deletions demo/p2p-sets.ts
Expand Up @@ -205,13 +205,16 @@ export default class extends LitElement {
if (changed.has('easyMode')) {
this.restartGame()

// Not first time
// Not first time & solo only
if (typeof changed.get('easyMode') != 'undefined' && p2p.peers.length == 1)
this.dispatchEvent(new CustomEvent('game-difficulty'))
}
}

private async restartGame() {
if (p2p.peers.length != 1)
this.easyMode = false

// Make the players
// For multiplayer uses generators defined at the top will be used.
// TODO For singleplayer use the default rules... for now
Expand All @@ -223,7 +226,7 @@ export default class extends LitElement {
p2p.peers.length == 1 ? undefined : linear(this.scoreGainIncrement, this.scoreGainInitial)))

// Number of cards to make
this.cardsLeft = this.easyMode && p2p.peers.length == 1
this.cardsLeft = this.easyMode
// Easy mode - remove opacity
// This is SAFE because opacity is the last feature that's incremented (most signifigant bit/feature)
? (Details.COUNT - 1) ** Details.SIZE
Expand Down Expand Up @@ -431,7 +434,7 @@ export default class extends LitElement {
: html`<slot name="no-singleplayer-score"></slot>`}${
// Big hint
this.easyMode && p2p.peers.length == 1
this.easyMode
&& (this.renderRoot.firstElementChild as LitSets | null)?.selected?.length == 2
// Cache these cards for the render below
&& (firstCard = this.getSelectedCard(0)!)
Expand Down

0 comments on commit 3b1b3c6

Please sign in to comment.