Skip to content

Repository files navigation

image

🥊 ONE CLASH FIGHTERS:

A blockchain-powered retro fighting game on OneChain
Play-to-Earn • NFT Fighters • On-Chain Battles • Tournament Staking

OneChain Next.js TypeScript License


📖 Table of Contents


🎮 Overview

One Clash Fighters is a retro-style fighting game that combines classic arcade gameplay with modern blockchain technology. Built on OneChain, players mint unique Fighter NFTs, battle AI opponents, stake OCT tokens in tournaments, and earn rewards based on their performance—all recorded immutably on-chain.

Key Highlights

  • 🎨 NFT Fighters: Mint and own unique fighter characters as NFTs
  • ⚔️ On-Chain Battles: Every victory is recorded on the blockchain
  • 💰 Play-to-Earn: Stake tokens, win battles, claim prizes
  • 🏆 Live Leaderboard: Real-time rankings from blockchain events
  • 🔗 Fully Decentralized: All game logic secured by smart contracts

Gallery

Home Page

A clean, futuristic landing screen where players begin their journey, connect wallets, and explore game modes. image

Select character

Players choose their fighters, each with unique power stats, abilities, and rarity levels. image

You Won

A victory screen showing battle results, rewards earned, and XP gained. image

Save Record in BLockchain

After each match, battle stats are permanently stored on the OneChain blockchain for transparency and fairness. image

image

Main Fight

The core gameplay scene where turn-based combat takes place with animations, attacks, and health tracking. image

LeaderBord

Global rankings showcasing top players based on wins, staking power, and on-chain battle history. image

Stacking

Users can stake tokens inside the game to boost rewards, earn yield, and unlock special characters. image

Stacking on OneChain

The actual OneChain dashboard where staking transactions are executed and verified on-chain. image

🌟 Game Features

Core Gameplay

  • 6 Unique Fighters with distinct stats and abilities
  • Progressive Difficulty - AI gets stronger each round
  • Advanced Combat System - Punch, kick, jump, duck, defense, and special moves
  • Retro Pixel Art - Classic arcade aesthetics
  • Responsive Controls - Smooth keyboard-based combat

Blockchain Features

  • Fighter NFT Minting - Create your fighter on-chain
  • Battle Recording - All victories stored on OneChain
  • Tournament Staking - Stake OCT tokens to enter prize pools
  • Prize Distribution - Winners claim rewards automatically
  • Transparent Leaderboard - Rankings verified on blockchain
  • Profile System - View your NFT fighter and battle history

🎯 How to Play

1️⃣ Connect Wallet

  • Click "Connect Wallet" on the home screen
  • Connect your OneWallet (OneChain compatible wallet)

2️⃣ Mint Your Fighter

  • Navigate to "Character Select"
  • Choose from 6 unique fighters
  • Mint your fighter NFT (small fee required)

3️⃣ Enter Combat

  • Select your minted fighter
  • Battle against AI opponents
  • Use strategic moves to win

4️⃣ Stake & Earn

  • Visit the "Staking" page
  • Stake OCT tokens to enter tournaments
  • Win battles to increase your prize pool share

5️⃣ Track Progress

  • Check the "Leaderboard" for rankings
  • View your "Profile" to see stats and battle history

🥋 Fighter Roster

Each fighter has unique stats that affect combat performance:

graph LR
    A[Fighter Stats] --> B[Power]
    A --> C[Speed]
    A --> D[Defense]
    B --> E[Damage Output]
    C --> F[Attack Speed]
    D --> G[Damage Reduction]
Loading

Fighter Details

Fighter Type Power Speed Defense Specialty
Thunder Fist Boxer 9 6 7 Heavy punches, high damage
🥷 Shadow Strike Ninja 7 10 5 Lightning fast, swift combos
🤖 Cyber Warrior Tech 8 8 6 Balanced, precision strikes
🎭 Mystery Fighter Enigma 6 7 9 Unpredictable, defensive
👑 Street King Brawler 7 7 8 Well-rounded, solid fundamentals
🛡️ Iron Wall Tank 8 5 10 Defensive powerhouse, unbreakable

Combat Controls

Key Action Description
←/→ Move Walk left/right
Jump Leap over attacks
Duck Avoid high kicks
D Punch Quick attack (5 damage)
A Kick Strong attack (10 damage)
S Defense Block incoming damage (1% only)
↑ + A Jump Kick Aerial special (15 damage)

🔄 Game Workflow

flowchart TD
    Start([Player Visits Game]) --> Connect{Wallet Connected?}
    Connect -->|No| ConnectWallet[Connect OneWallet]
    ConnectWallet --> Connect
    Connect -->|Yes| HasNFT{Has Fighter NFT?}
    
    HasNFT -->|No| Select[Character Select Page]
    Select --> Mint[Mint Fighter NFT]
    Mint --> MintTx[Transaction on OneChain]
    MintTx --> HasNFT
    
    HasNFT -->|Yes| Menu[Main Menu]
    Menu --> Choice{Player Choice}
    
    Choice -->|Fight| Fight[Enter Combat]
    Fight --> Battle[Battle AI Opponent]
    Battle --> Win{Victory?}
    Win -->|Yes| Record[Record Battle On-Chain]
    Record --> Prize[Distribute Prize]
    Prize --> UpdateStats[Update Fighter Stats]
    UpdateStats --> NextRound{Continue?}
    NextRound -->|Yes| Difficulty[Increase Difficulty]
    Difficulty --> Battle
    NextRound -->|No| Menu
    Win -->|No| GameOver[Game Over]
    GameOver --> Menu
    
    Choice -->|Stake| Stake[Tournament Staking]
    Stake --> StakeTx[Stake OCT Tokens]
    StakeTx --> Pool[Add to Prize Pool]
    Pool --> Menu
    
    Choice -->|Leaderboard| Leader[View Rankings]
    Leader --> Fetch[Fetch Blockchain Events]
    Fetch --> Display[Display Top Players]
    Display --> Menu
    
    Choice -->|Profile| Profile[View Profile]
    Profile --> ShowNFT[Display Fighter NFT]
    ShowNFT --> ShowHistory[Show Battle History]
    ShowHistory --> Menu
Loading

🔗 OneChain Integration

Blockchain Architecture

graph TB
    subgraph "Frontend (Next.js)"
        UI[User Interface]
        Wallet[Wallet Connection]
        Hooks[React Hooks]
    end
    
    subgraph "OneChain Blockchain"
        NFT[Fighter NFT Module]
        Battle[Battle System Module]
        Stake[Staking Pool Module]
        Events[Blockchain Events]
    end
    
    subgraph "Smart Contract Functions"
        Mint[mint_fighter]
        Record[record_battle]
        StakeFunc[stake_for_tournament]
        Claim[claim_prize]
    end
    
    UI --> Wallet
    Wallet --> Hooks
    Hooks --> Mint
    Hooks --> Record
    Hooks --> StakeFunc
    Hooks --> Claim
    
    Mint --> NFT
    Record --> Battle
    StakeFunc --> Stake
    Claim --> Stake
    
    Battle --> Events
    Events --> UI
Loading

How It Works

  1. Fighter NFT System

    • Each fighter is a unique NFT on OneChain
    • Stores stats: name, type, level, wins, losses, damage
    • Minted via fighter_nft::create_fighter function
    • Owned by player's wallet address
  2. Battle Recording

    • Every battle result is recorded on-chain
    • Emits BattleCompleted event with winner, damage, prize
    • Updates fighter stats (wins, losses, total damage)
    • Creates immutable BattleRecord object
  3. Tournament Staking

    • Players stake OCT tokens to enter tournaments
    • Tokens added to shared prize pool
    • Winners claim 90% of pool (10% burned for APY)
    • All transactions verified on blockchain
  4. Leaderboard System

    • Fetches BattleCompleted events from blockchain
    • Aggregates wins, damage, and prizes per player
    • Real-time rankings updated automatically
    • Fully transparent and verifiable

📜 Smart Contracts

The game uses three Move smart contract modules deployed on OneChain:

1. Fighter NFT Module (fighter_nft.move)

// Creates unique fighter NFTs with stats
public entry fun create_fighter(
    name: vector<u8>,
    fighter_type: u8,
    power: u8,
    speed: u8,
    defense: u8,
    ctx: &mut TxContext
)

Features:

  • Mint fighter NFTs with custom stats
  • Track wins, losses, level, and damage
  • Update stats after each battle
  • Transfer ownership between wallets

2. Battle System Module (battle_system.move)

// Records battle results on-chain
public entry fun record_battle(
    fighter: &mut Fighter,
    winner_damage: u64,
    loser_damage: u64,
    prize: Coin<OCT>,
    round: u64,
    ctx: &mut TxContext
)

Features:

  • Record single-player and PvP battles
  • Emit BattleCompleted events for leaderboard
  • Distribute prize tokens to winners
  • Create immutable battle records

3. Staking Pool Module (staking_pool.move)

// Stake tokens for tournament entry
public entry fun stake_for_tournament(
    pool: &mut TournamentPool,
    stake: Coin<OCT>,
    ctx: &mut TxContext
)

Features:

  • Shared tournament prize pool
  • Track total staked and prize pool
  • Entry fee: 0.01 OCT (configurable)
  • Winners claim 90% of pool

Contract Deployment

The contracts are deployed on OneChain Testnet. To deploy your own:

# Navigate to Move contracts
cd move

# Build contracts
one move build

# Publish to OneChain
one client publish --gas-budget 100000000

After deployment, update lib/onechain-config.ts with your package and pool IDs.


🚀 Installation

Prerequisites

  • Node.js 18+ and npm
  • OneWallet browser extension
  • OneChain testnet OCT tokens (from faucet)

Setup Steps

  1. Clone the repository
git clone https://github.com/yourusername/one-clash-fighters.git
cd one-clash-fighters
  1. Install dependencies
npm install
  1. Configure environment (optional)
# Create .env.local file
NEXT_PUBLIC_PACKAGE_ID=0x33339ae0dbf1d8805eb1413639455b1428484d282c0bdcbe15d1b88921e00f65
  1. Run development server
npm run dev
  1. Open in browser
http://localhost:3000

Build for Production

npm run build
npm start

🛠️ Tech Stack

Frontend

  • Framework: Next.js 14 (App Router)
  • Language: TypeScript 5
  • Styling: Tailwind CSS
  • UI Components: Custom retro-styled components
  • State Management: React Hooks

Blockchain

  • Network: OneChain Testnet
  • Smart Contracts: Move Language
  • Wallet Integration: @mysten/dapp-kit
  • SDK: @mysten/sui (OneChain compatible)
  • Token: OCT (OneChain native token)

Development Tools

  • Package Manager: npm
  • Linting: ESLint
  • Type Checking: TypeScript
  • Version Control: Git

🏗️ Architecture

Project Structure

one-clash-fighters/
├── app/                    # Next.js app directory
│   ├── page.tsx           # Home/menu page
│   ├── select/            # Character selection
│   ├── fight/             # Combat gameplay
│   ├── winner/            # Battle results
│   ├── leaderboard/       # Rankings page
│   ├── staking/           # Tournament staking
│   └── profile/           # User profile
├── components/            # React components
├── hooks/                 # Custom React hooks
│   ├── use-fighter-nft.ts
│   ├── use-battle-recording.ts
│   └── use-staking.ts
├── lib/                   # Utilities and config
│   ├── onechain-config.ts
│   ├── fighters.ts
│   └── game-utils.ts
├── move/                  # Smart contracts
│   └── sources/
│       ├── fighter_nft.move
│       ├── battle_system.move
│       └── staking_pool.move
├── providers/             # Context providers
└── public/                # Static assets

Data Flow

sequenceDiagram
    participant User
    participant Frontend
    participant Wallet
    participant OneChain
    participant SmartContract

    User->>Frontend: Connect Wallet
    Frontend->>Wallet: Request Connection
    Wallet->>Frontend: Wallet Connected
    
    User->>Frontend: Mint Fighter
    Frontend->>Wallet: Sign Transaction
    Wallet->>OneChain: Submit Transaction
    OneChain->>SmartContract: Execute mint_fighter
    SmartContract->>OneChain: Create NFT
    OneChain->>Frontend: Transaction Success
    
    User->>Frontend: Win Battle
    Frontend->>Wallet: Sign Battle Record
    Wallet->>OneChain: Submit Transaction
    OneChain->>SmartContract: Execute record_battle
    SmartContract->>OneChain: Emit Event + Update Stats
    OneChain->>Frontend: Battle Recorded
    
    User->>Frontend: View Leaderboard
    Frontend->>OneChain: Query Events
    OneChain->>Frontend: Return Battle Events
    Frontend->>User: Display Rankings
Loading

🎨 Game Mechanics

Combat System

  • Hit Detection: Precise collision boxes for each fighter
  • Damage Calculation: Based on fighter power stat and move type
  • Defense Mechanism: Blocking reduces damage to 1%
  • Special Moves: Jump kicks deal 50% more damage
  • AI Behavior: Adaptive difficulty with strategic decision-making

Progression System

  • Difficulty Scaling: Each round increases AI damage by 20%
  • Fighter Leveling: Win battles to increase fighter level
  • Stat Tracking: Cumulative damage dealt and taken
  • Win/Loss Record: Permanent on-chain history

Economy

  • Mint Fee: 0.001 OCT per fighter NFT
  • Entry Fee: 0.01 OCT to stake in tournaments
  • Prize Pool: 90% distributed to winners, 10% burned
  • Battle Rewards: Variable based on performance

📊 Leaderboard Metrics

Rankings are calculated from blockchain data:

  1. Total Wins - Number of victories
  2. Total Damage - Cumulative damage dealt
  3. Total Prize - OCT tokens earned
  4. Last Battle - Timestamp of most recent fight

All data is fetched from BattleCompleted events emitted by smart contracts.


🤝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


🔗 Links


🙏 Acknowledgments

  • OneChain team for blockchain infrastructure
  • Next.js team for the amazing framework
  • Retro gaming community for inspiration

Built with ❤️ on OneChain

Fight. Earn. Dominate.

About

Ultimate retro-style fighting game built with Next.js and React.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages