A browser-based tactical game where you program samurai AI using strategic card decks!
Code Samurai is a unique tactical battle game where you:
- Choose a Samurai with unique stats (HP, Attack, Defense, Speed)
- Select a Strategic Deck with IF-THEN card logic to control your fighter's AI
- Battle AI Opponents from Newbie to Boss difficulty
- Earn XP and Level Up with persistent progress tracking
- Unlock Titles by defeating challenging opponents
All running 100% in your browser with no backend required!
- Kenji the Novice - Balanced fighter
- Hiroshi the Defender - High HP tank
- Akira the Berserker - Glass cannon
- Takeshi the Master - Tactical expert
- Yuki the Ninja - Speed demon
- Ryu the Dragon - Elite warrior
Each deck contains 5 condition-action card pairs (IF-DO logic):
- Aggressive - All-out attack
- Defensive - Survive and counter
- Tactical - Smart decisions
- Berserker - Pure aggression
- Control - Distance management
- 🟢 Training Dummy (Lv.1) - 30% mistake rate
- 🟡 Veteran Warrior (Lv.2) - Solid tactics
- 🟠 Expert Duelist (Lv.3) - Highly skilled
- 🔴 Grand Master (Lv.4) - Near perfect
- 💀 Shadow Shogun (Lv.5) - Ultimate boss
- Level System with XP progression
- Win/Loss Statistics and win rate
- Battle History (last 100 battles)
- Unlockable Titles for achievements
- Data Export/Import for backups
Visit the live game (once deployed):
https://krymets.github.io/code-samurai/
# Clone repository
git clone https://github.com/krymets/code-samurai.git
cd code-samurai/frontend
# Install dependencies
npm install
# Run dev server
npm run dev
# Open http://localhost:3000cd frontend
npm run build
# Output in dist/ folder-
Push to GitHub:
git add . git commit -m "Deploy game" git push origin main
-
Enable GitHub Pages in repository settings:
- Settings → Pages → Source: GitHub Actions
-
Done! Game will auto-deploy via GitHub Actions
See GITHUB_PAGES_DEPLOYMENT.md for detailed instructions.
Each deck has 5 cards with Condition → Action logic:
IF HP Critical (< 20%)
→ DO Fast Retreat
IF Enemy Close (< 150px)
→ DO Attack Closest
IF Outnumbered
→ DO DefendDuring battle, the samurai evaluates cards top-to-bottom and executes the first matching condition.
Real-time combat simulation with:
- Movement AI - Chase, retreat, circle, dash
- Combat System - Damage calculation with attack/defense
- Cooldowns - Attack speed and special abilities
- Physics - Collision, bounds checking
- Canvas Rendering - Visual battle representation
code-samurai/
├── .github/
│ └── workflows/
│ └── deploy.yml # Auto-deploy to GitHub Pages
├── frontend/
│ ├── src/
│ │ ├── components/
│ │ │ └── game/
│ │ │ ├── CharacterSelect.jsx
│ │ │ ├── DeckSelect.jsx
│ │ │ ├── OpponentSelect.jsx
│ │ │ ├── BattleArena.jsx # Canvas battle rendering
│ │ │ ├── BattleResult.jsx
│ │ │ └── StatsPanel.jsx
│ │ ├── data/
│ │ │ └── gameData.js # All game content
│ │ ├── engine/
│ │ │ └── battleEngine.js # Battle logic
│ │ ├── services/
│ │ │ └── storage.js # localStorage management
│ │ ├── pages/
│ │ │ └── GamePage.jsx
│ │ └── App.jsx
│ ├── vite.config.js
│ └── package.json
├── README.md
└── GITHUB_PAGES_DEPLOYMENT.md
- React 18 - UI framework
- Vite - Build tool & dev server
- Canvas API - Battle visualization
- localStorage - Data persistence
- GitHub Actions - CI/CD pipeline
- Damage Formula:
max(1, Attack - Defense) - Defend Ability: Reduces damage by 50%
- Berserk Mode: +50% damage multiplier
- Battle Timeout: 2 minutes (winner by HP %)
- XP System: Earn XP by winning battles
- Level Up: XP requirement increases by 1.5x per level
- Titles: Unlock by defeating specific opponents
- Statistics: Track wins, losses, streaks, damage
Opponents have modifiers affecting:
- Decision Delay: Reaction time (0.2s - 1.5s)
- Mistake Chance: Probability of wrong decision (0% - 30%)
- Aggression: Combat behavior (0.5 - 1.0)
All data stored in browser localStorage:
codeSamurai_playerStats- Level, XP, win/losscodeSamurai_battleHistory- Recent battlescodeSamurai_settings- User preferences
Note: Clearing browser data will reset progress! Use Export Data feature to backup.
- Check
vite.config.js→basematches your repo name - Example:
/code-samurai/for repocode-samurai
cd frontend
rm -rf node_modules package-lock.json
npm install
npm run build- Data is in localStorage (browser-specific)
- Use Export/Import in stats panel
- Different browsers = different saves
Contributions welcome! Ideas:
- New samurais and decks
- Additional card types
- Tournament mode
- Multiplayer (PvP)
- More AI opponents
- Sound effects & music
MIT License - Free to use, modify, and distribute!
Built with ❤️ for open source gaming community
Author: Code Samurai Team Version: 2.0.0 (Browser Standalone)
⭐ Star this repo if you enjoy the game! 🐛 Report issues: GitHub Issues 🎮 Play now: Live Demo