Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@
"cssvar.ignore": [],

// add support for autocomplete in JS or JS like files
"cssvar.extensions": ["css", "postcss", "svelte"]
"cssvar.extensions": [
"css",
"postcss",
"svelte"
]
}
3 changes: 3 additions & 0 deletions src/lib/components/Container.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="container m-auto max-w-xl h-full my-4 flex flex-col">
<slot />
</div>
5 changes: 3 additions & 2 deletions src/lib/components/PlayerStats.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import type { NineBallPlayer, NineBallGame } from '$lib';
import type { EightBallGame } from '$lib/eight-ball';
import type { Player as EightBallPlayer } from '$lib/index/player';
import type { StraightPoolGame, StraightPoolPlayer } from '$lib/straight-pool';

export let player: NineBallPlayer | EightBallPlayer;
export let game: NineBallGame | EightBallGame;
export let player: NineBallPlayer | EightBallPlayer | StraightPoolPlayer;
export let game: NineBallGame | EightBallGame | StraightPoolGame;
export let playerNumber: number;
</script>

Expand Down
3 changes: 2 additions & 1 deletion src/lib/components/ProgressBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import type { EightBallPlayer } from '$lib/eight-ball';
import { tweened } from 'svelte/motion';
import { cubicOut } from 'svelte/easing';
import type { StraightPoolPlayer } from '$lib/straight-pool';

export let player: NineBallPlayer | EightBallPlayer;
export let player: NineBallPlayer | EightBallPlayer | StraightPoolPlayer;
let className = '';
export { className as class };
export let reverse = false;
Expand Down
3 changes: 2 additions & 1 deletion src/lib/components/Scoreboard.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<script lang="ts">
import type { EightBallGame } from '$lib/eight-ball';
import type { NineBallGame } from '$lib';
import type { StraightPoolGame } from '$lib/straight-pool';

export let game: NineBallGame | EightBallGame;
export let game: NineBallGame | EightBallGame | StraightPoolGame;
</script>

<div aria-live="polite" class="rounded-lg overflow-hidden">
Expand Down
39 changes: 39 additions & 0 deletions src/lib/components/straight-pool/ControlPad.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<script lang="ts">
import type { StraightPoolGame } from '$lib/straight-pool';
import ControlButtons from '../ControlButtons.svelte';
import { createEventDispatcher } from 'svelte';

export let game: StraightPoolGame;

const dispatch = createEventDispatcher();

function handleIncrement() {
dispatch('increment');
}

function handleDecrement() {
dispatch('decrement');
}

function handleEndTurn() {
dispatch('miss');
}

function handleUndo() {
dispatch('undo');
}
</script>

<div class="flex rounded-xl border-white border-4 overflow-hidden justify-center my-4">
<button on:click={handleIncrement} class="w-full p-4 border-r-2">+</button>
<button on:click={handleDecrement} class="w-full p-4 border-l-2">-</button>
</div>

<button on:click={handleEndTurn}>{game.currentPlayer.name}'s Turn is Over</button>

<div
aria-label="control button container"
class="rounded-xl bg-slate-600 flex justify-self-stretch justify-evenly"
>
<ControlButtons isNineBall={false} isGameOver={false} on:saftey on:timeout on:undo />
</div>
79 changes: 79 additions & 0 deletions src/lib/straight-pool/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
interface IIncrement {
type: 'INCREMENT';
}

interface IDecrement {
type: 'DECREMENT';
}

interface ISafety {
type: 'SAFETY';
}

interface IMiss {
readonly type: 'MISS';
readonly deadBallCount: number;
}

interface IEndRack {
type: 'END_RACK';
deadBallCount: number;
}

interface IUndo {
type: 'UNDO';
}

interface IRedo {
type: 'REDO';
}

interface ITimeOut {
type: 'TIMEOUT';
}


export class Increment implements IIncrement {
readonly type = 'INCREMENT';
}

export class Decrement implements IDecrement {
readonly type = 'DECREMENT';
}

export class Safety implements ISafety {
readonly type = 'SAFETY';
}

export class Miss implements IMiss {
readonly type = 'MISS';
constructor(readonly deadBallCount: number = 0) {}
}

export class EndRack implements IEndRack {
readonly type = 'END_RACK';
deadBallCount = 0;
}

export class Undo implements IUndo {
readonly type = 'UNDO';
}

export class Redo implements IRedo {
readonly type = 'REDO';
}

export class Timeout implements ITimeOut {
readonly type = 'TIMEOUT';
}

export type Action =
| Increment
| Decrement
| Safety
| Miss
| EndRack
| Undo
| Redo
| Timeout

Loading