• Townie
    AI
  • Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
saman

saman

mazegame

Just doing a little test run over here
Public
Like
mazegame
Home
Code
4
README.md
game-fixed.js
game.js
H
index.html
Branches
1
Pull requests
Remixes
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
README.md
Code
/
README.md
Search
…
README.md

Coin Collection Game

A turn-based strategy game where you compete against an AI monster to collect coins on a grid-based map. The game features a strategic wall placement phase followed by competitive coin collection.

How to Play

Phase 1: Wall Placement

  • Objective: Strategically place 3 walls to create advantages for yourself
  • Controls: Click on empty tiles to place walls
  • Restrictions:
    • Cannot place walls on player/monster starting positions
    • Cannot place walls on coin locations
    • Cannot place walls that would isolate any coins (making them unreachable)
  • Strategy: Use walls to block the monster's path to coins or create shortcuts for yourself

Phase 2: Coin Collection

  • Objective: Collect as many coins as possible before the monster does
  • Controls: Use arrow keys (↑↓←→) to move your character
  • Game Flow:
    1. You move first using arrow keys
    2. After each of your moves, the monster automatically moves
    3. The game ends when all 5 coins are collected
    4. Winner is determined by who collected the most coins

Game Features

Strategic Wall Placement

  • 3 walls to place at the start of each game
  • Smart validation prevents placing walls that would isolate coins
  • Visual feedback with hover effects and error messages
  • Real-time counter showing remaining walls to place

Grid Generation

  • 10x10 grid with preset walls (12% of tiles) randomly placed for base challenge
  • Smart preset wall placement ensures all coins remain reachable from both starting positions
  • Player starts in top-left corner (👤)
  • Monster starts in bottom-right corner (👹)
  • 5 coins (🪙) placed in strategic locations
  • Additional player walls can be placed on top of this foundation

AI Monster Behavior

  • Uses pathfinding algorithm to find the shortest path to the nearest coin
  • Moves optimally toward coins, making strategic decisions
  • Adapts to player-placed walls and finds alternate routes
  • Will compete directly with the player for coin collection

Visual Elements

  • Player: 👤 (blue)
  • Monster: 👹 (red)
  • Coins: 🪙 (gold)
  • Floor tiles: Light gray with hover effects during placement
  • Wall tiles: Dark gray
  • Score tracking: Real-time display of player score, monster score, remaining coins, and remaining walls

Game Mechanics

  • Two-phase gameplay: Wall placement followed by movement
  • Turn-based movement (player moves, then monster moves)
  • Collision detection with walls
  • Automatic coin collection when stepping on coin tiles
  • Connectivity validation ensures all coins remain reachable
  • Game over screen with final scores and winner announcement
  • "New Game" button to restart with fresh wall placement phase

Technical Implementation

  • Frontend: Vanilla JavaScript with HTML5 and CSS3
  • Styling: TailwindCSS for responsive design
  • Pathfinding: Optimized algorithm for monster AI
  • Grid Generation: Clean slate for strategic wall placement
  • Validation: Breadth-first search to ensure coin accessibility
  • Game State: Complete two-phase game loop with win/lose conditions

Controls

Wall Placement Phase

  • Mouse Click: Click on empty tiles to place walls
  • Visual Feedback: Tiles highlight on hover, error messages for invalid placements

Movement Phase

  • ↑ Arrow Up: Move player up
  • ↓ Arrow Down: Move player down
  • ← Arrow Left: Move player left
  • → Arrow Right: Move player right

General

  • New Game Button: Start a new game with fresh wall placement phase

Strategy Tips

  • Block monster paths: Place walls to force the monster to take longer routes to coins
  • Create shortcuts: Use walls to funnel yourself toward multiple coins efficiently
  • Control center: Walls near the middle can influence access to multiple coins
  • Think ahead: Consider how the monster will move after you place each wall

Enjoy the strategic challenge of outsmarting the AI monster with clever wall placement and quick coin collection!

FeaturesVersion controlCode intelligenceCLI
Use cases
TeamsAI agentsSlackGTM
ExploreDocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.