solitaire-svelte Svelte Themes

Solitaire Svelte

Solitaire card game built with Svelte, Tailwind CSS v4, Vite, and tested with Vitest + Playwright

Solitaire Svelte

A classic Klondike Solitaire card game built with Svelte 5, Tailwind CSS v4, and Vite.

Features

  • ๐Ÿƒ Classic Klondike (Patience) solitaire rules
  • โฑ๏ธ Timer and move counter
  • ๐ŸŽฏ Auto-complete when possible
  • โœจ Smooth card animations
  • ๐Ÿ“ฑ Responsive design (desktop & mobile)
  • โ™ฟ Accessible with keyboard navigation
  • ๐Ÿงช Comprehensive test suite (TDD)

Tech Stack

Getting Started

Prerequisites

  • Node.js 18+
  • npm

Installation

# Clone the repository
git clone https://github.com/lingster/solitaire-svelte.git
cd solitaire-svelte

# Install dependencies
npm install --legacy-peer-deps

# Start development server
npm run dev

Testing

# Run unit tests
npm run test

# Run unit tests in watch mode
npm run test:watch

# Run E2E tests
npm run test:e2e

# Run E2E tests with UI
npm run test:e2e:ui

# Run all tests
npm run test:all

Building

# Build for production
npm run build

# Preview production build
npm run preview

Project Structure

solitaire-svelte/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ lib/
โ”‚   โ”‚   โ”œโ”€โ”€ types.ts        # TypeScript types
โ”‚   โ”‚   โ”œโ”€โ”€ game.ts         # Game logic
โ”‚   โ”‚   โ”œโ”€โ”€ game.test.ts    # Unit tests (TDD)
โ”‚   โ”‚   โ”œโ”€โ”€ store.ts        # Svelte stores
โ”‚   โ”‚   โ”œโ”€โ”€ Card.svelte     # Card component
โ”‚   โ”‚   โ”œโ”€โ”€ Pile.svelte     # Pile component
โ”‚   โ”‚   โ””โ”€โ”€ Board.svelte    # Game board
โ”‚   โ”œโ”€โ”€ App.svelte          # Main app
โ”‚   โ”œโ”€โ”€ main.ts             # Entry point
โ”‚   โ””โ”€โ”€ app.css             # Tailwind styles
โ”œโ”€โ”€ e2e/
โ”‚   โ””โ”€โ”€ solitaire.spec.ts   # Playwright E2E tests
โ”œโ”€โ”€ public/                  # Static assets
โ”œโ”€โ”€ playwright.config.ts     # Playwright config
โ”œโ”€โ”€ vite.config.ts          # Vite config
โ””โ”€โ”€ wrangler.toml           # Cloudflare config

Game Rules (Klondike)

Objective

Move all 52 cards to the four foundation piles, building each from Ace to King by suit.

Setup

  • 28 cards dealt to 7 tableau piles (1-7 cards each)
  • Top card of each tableau pile is face up
  • Remaining 24 cards form the stock pile

Rules

  • Foundations: Build up by suit from Ace to King
  • Tableau: Build down by alternating colors (red/black)
  • Stock: Click to draw cards to waste pile
  • Empty tableau: Only Kings can be placed
  • Move stacks: Can move properly sequenced card stacks between tableau piles

Deployment

Cloudflare Pages

  1. Fork/clone this repository
  2. Connect to Cloudflare Pages
  3. Set build command: npm run build
  4. Set output directory: dist
  5. Add environment variables if needed

Or deploy via CLI:

npm run build
npx wrangler pages deploy dist --project-name=solitaire-svelte

GitHub Actions

The repository includes a CI/CD workflow that:

  1. Runs unit tests
  2. Builds the project
  3. Runs E2E tests
  4. Deploys to Cloudflare Pages (on main branch)

Set these secrets in your GitHub repository:

  • CLOUDFLARE_API_TOKEN
  • CLOUDFLARE_ACCOUNT_ID

Development

TDD Workflow

This project was built using Test-Driven Development:

  1. Write failing tests for game logic
  2. Implement minimal code to pass tests
  3. Refactor while keeping tests green
  4. Add E2E tests for UI interactions

Adding Features

  1. Write tests first in game.test.ts
  2. Implement in game.ts
  3. Update UI components
  4. Add E2E tests in e2e/

License

MIT

Top categories

Loading Svelte Themes