惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
J
Java Code Geeks
罗磊的独立博客
雷峰网
雷峰网
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
爱范儿
爱范儿
B
Blog RSS Feed
腾讯CDC
Apple Machine Learning Research
Apple Machine Learning Research
D
Docker
Recent Announcements
Recent Announcements
T
Tailwind CSS Blog
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Vercel News
Vercel News
小众软件
小众软件
人人都是产品经理
人人都是产品经理
云风的 BLOG
云风的 BLOG
IT之家
IT之家
Blog — PlanetScale
Blog — PlanetScale
I
InfoQ
S
SegmentFault 最新的问题

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
I Built 2 Browser Puzzle Games from Scratch A deep-dive i...
7x Games · 2026-05-11 · via DEV Community

I Built 2 Browser Puzzle Games from Scratch This Week 🎮

As part of my ongoing project — 7x.games — I'm building 150+ original,
SEO-optimized browser games. This week I shipped two puzzle games:

  • 🧪 Color Sort Puzzle — pour colored liquids between test tubes to sort them by color
  • 🧱 Block Blast — place Tetris-style blocks on an 8×8 grid, clear rows & columns

No game engines. No canvas libraries. Just React, and CSS.

Here's what I learned building both.


🧪 Color Sort Puzzle

The mechanic seems trivial but the solver logic is not.

The key challenge was level validation — generating a solvable puzzle
every time. I built a backtracking solver that simulates valid pour sequences
before presenting a level to the player.

// A pour is valid only if:
// - Source tube is not empty
// - Target tube is not full
// - Top color of source matches top color of target (or target is empty)
const isValidPour = (from, to) => {
  if (from.length === 0) return false
  if (to.length === TUBE_SIZE) return false
  if (to.length > 0 && to[to.length - 1] !== from[from.length - 1]) return false
  return true
}

Enter fullscreen mode Exit fullscreen mode

Other interesting bits:

  • Undo stack with full state snapshots
  • Auto-win detection after each pour
  • 50+ difficulty-scaled levels generated algorithmically

🧱 Block Blast

This one was trickier on the interaction side.

Drag-and-Drop with Proximity Snapping

Standard drag-and-drop maps your cursor to the grid. But on a crowded board,
being 1px off means you miss the gap entirely.

I implemented a 3×3 proximity search — the game scans a neighborhood
around your finger and snaps to the closest valid placement:

for (let dr = -1; dr <= 1; dr++) {
  for (let dc = -1; dc <= 1; dc++) {
    const r = baseRow + dr
    const c = baseCol + dc

    if (canPlaceBlock(grid, shape, r, c)) {
      const dist = Math.sqrt(dr * dr + dc * dc)
      if (dist < minDistance) {
        minDistance = dist
        bestPos = { row: r, col: c }
      }
    }
  }
}

Enter fullscreen mode Exit fullscreen mode

This made the game feel 10x more playable on mobile immediately.

Web Audio Sound Effects — Zero Dependencies

Instead of loading audio files, I synthesized all sounds via the Web Audio API:

const playSound = (type) => {
  const ctx = new AudioContext()
  const osc = ctx.createOscillator()
  const gain = ctx.createGain()
  osc.connect(gain)
  gain.connect(ctx.destination)

  if (type === 'clear') {
    osc.type = 'triangle'
    osc.frequency.setValueAtTime(523.25, ctx.currentTime)              // C5
    osc.frequency.linearRampToValueAtTime(1046.50, ctx.currentTime + 0.3) // C6
    gain.gain.setValueAtTime(0.2, ctx.currentTime)
    gain.gain.exponentialRampToValueAtTime(0.01, ctx.currentTime + 0.3)
    osc.start()
    osc.stop(ctx.currentTime + 0.3)
  }
}

Enter fullscreen mode Exit fullscreen mode

Three sounds (place, clear, game over) — 0 bytes of audio assets.

Mobile Scroll Freeze During Drag

The tricky part: you want the page to scroll normally, but freeze the moment
the user grabs a block.

React's synthetic touch events are passive by default, so preventDefault
doesn't work inside them. The fix: register a non-passive listener on
mount using a ref that updates synchronously:

const isDraggingRef = useRef(false)

useEffect(() => {
  const blockScroll = (e) => {
    if (isDraggingRef.current && e.cancelable) e.preventDefault()
  }
  // { passive: false } is KEY — allows preventDefault to work
  window.addEventListener('touchmove', blockScroll, { passive: false })
  return () => window.removeEventListener('touchmove', blockScroll)
}, [])

// Then on touchStart of a block:
isDraggingRef.current = true  // synchronous — no state lag

Enter fullscreen mode Exit fullscreen mode

Using useState here would fail because the state update is async
the browser already starts scrolling before React re-renders.


SEO Integration

Both games are pre-rendered static pages in Next.js with:

  • Full metadata object + OpenGraph tags in layout.js
  • VideoGame + FAQPage JSON-LD structured data via next/script
  • Registered in sitemap.xml automatically via the games registry
  • Long-form strategy articles on each game page for topical authority

What's Next

I'm continuing to build original games for 7x.games — the goal is 150+
fully SEO-optimized, original browser games. Each game is a standalone
Next.js static page with its own schema, metadata, and content strategy.

🔗 Play both games:

🔗 Follow the build: https://www.instagram.com/buntynamberdar

Drop a ❤️ if you found the non-passive touch trick useful — took me longer than I'd like to admit to figure that one out! 😅