Skip to content

Repository files navigation

Edu-Tycoon Core Game Engine

A headless, data-driven business simulation game engine built with TypeScript, Zustand, and decimal.js.

๐ŸŽฏ Overview

Edu-Tycoon is a modular game engine that separates game logic from content. The engine reads business parameters from configuration files rather than hard-coding them, making it easy to add new businesses and mechanics without changing core code.

Key Features

  • Data-Driven Architecture: Add new businesses by editing JSON config, not code
  • Arbitrary-Precision Math: Uses decimal.js for all financial calculations to handle numbers > $10^15
  • Educational Mechanics: Skill system that directly impacts business efficiency
  • Persistent State: Auto-saves to localStorage with custom Decimal serialization
  • Headless Design: Pure logic engine with no UI dependencies
  • Type-Safe: Built with TypeScript strict mode

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Config Layer   โ”‚  Static content (Skills, Businesses)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Logic Registry  โ”‚  Factory pattern: logicType โ†’ Calculation Formula
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Game Store     โ”‚  Zustand state management + Game loop
โ”‚   (Zustand)     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Persistence    โ”‚  localStorage with Decimal serialization
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“ Project Structure

src/
โ”œโ”€โ”€ core/
โ”‚   โ”œโ”€โ”€ types.ts           # TypeScript interfaces (GameState, BusinessConfig, etc.)
โ”‚   โ”œโ”€โ”€ logicRegistry.ts   # Business logic factory (LINEAR_SIMPLE, etc.)
โ”‚   โ””โ”€โ”€ efficiency.ts      # Skill-based efficiency calculator
โ”œโ”€โ”€ config/
โ”‚   โ””โ”€โ”€ gameData.ts        # Static content (SKILLS, BUSINESSES)
โ”œโ”€โ”€ store/
โ”‚   โ””โ”€โ”€ useGameStore.ts    # Zustand store with tick, buyUpgrade, unlockSkill
โ””โ”€โ”€ test.ts                # Comprehensive test suite

๐Ÿš€ Getting Started

Installation

npm install

Running Tests

npm test

This runs the comprehensive test suite that validates:

  • State initialization
  • Business logic calculations
  • Efficiency system
  • Buy/upgrade mechanics
  • Tick revenue generation
  • Skill unlocking
  • Large number handling
  • localStorage persistence

Build

npm run build

๐ŸŽฎ Core Concepts

1. Businesses

Businesses are defined in src/config/gameData.ts. Each business has:

  • logicType: Determines the calculation formula (e.g., LINEAR_SIMPLE)
  • params: Configuration for the formula (baseCost, baseRevenue, growthFactor)
  • reqSkills: Skills needed for 100% efficiency

Example:

{
  id: "biz_lemonade_stand",
  name: "Lemonade Stand",
  logicType: "LINEAR_SIMPLE",
  params: {
    baseCost: 10,
    baseRevenue: 1,
    growthFactor: 1.07
  },
  reqSkills: ["skill_financial_literacy", "skill_sales_psychology"]
}

2. Logic Types

The engine uses a factory pattern to map logic types to formulas:

LINEAR_SIMPLE

  • Upgrade Cost: baseCost ร— (growthFactor)^level
  • Revenue: level ร— baseRevenue ร— efficiency

Future logic types (e.g., BANKING, IT_PROJECT) can be added by implementing the BusinessLogic interface.

3. Skills

Skills reduce efficiency penalties. Each skill has a penaltyWeight (0.0 to 1.0). If a business requires a skill the player doesn't have, efficiency is reduced by that skill's weight.

Efficiency Formula: ฮฑ = max(0.1, 1.0 - ฮฃ penaltyWeights of missing skills)

Example:

  • Business requires 2 skills: Financial Literacy (0.3) and Sales Psychology (0.2)
  • Player has no skills: Efficiency = 1.0 - 0.3 - 0.2 = 50%
  • Player learns Financial Literacy: Efficiency = 1.0 - 0.2 = 80%
  • Player learns both: Efficiency = 100%

4. The Game Loop

The tick(deltaTime) function runs periodically (e.g., every 1 second) to generate revenue:

for each unlocked business:
  rawRevenue = calculateRawRevenue(level)
  efficiency = calculateEfficiency(business, unlockedSkills)
  finalRevenue = rawRevenue ร— efficiency ร— deltaTime
  money += finalRevenue

๐Ÿงช API Reference

Store Actions

import { useGameStore } from './store/useGameStore';

const store = useGameStore.getState();

// Buy or upgrade a business
store.buyUpgrade("biz_lemonade_stand");

// Unlock a skill
store.unlockSkill("skill_financial_literacy");

// Run the game loop (1 second)
store.tick(1);

// Reset the game
store.resetGame();

// Get upgrade cost
const cost = store.getUpgradeCost("biz_lemonade_stand");

// Get current revenue per second
const revenue = store.getCurrentRevenue("biz_lemonade_stand");

// Get efficiency for a business
const efficiency = store.getEfficiency("biz_lemonade_stand");

State Access

const state = useGameStore.getState();

console.log(state.money.toString());           // Current wallet balance
console.log(state.businesses);                 // All business states
console.log(state.unlockedSkills);            // List of learned skills

๐Ÿ”ง Extending the Engine

Adding a New Business

  1. Add a new entry to BUSINESSES in src/config/gameData.ts:
{
  id: "biz_coffee_shop",
  name: "Coffee Shop",
  description: "A cozy cafรฉ serving premium coffee",
  reqSkills: ["skill_customer_service", "skill_financial_literacy"],
  logicType: "LINEAR_SIMPLE",
  params: {
    baseCost: 100,
    baseRevenue: 5,
    growthFactor: 1.15
  }
}

That's it! The engine automatically picks it up. No code changes needed.

Adding a New Logic Type

  1. Add the type to LogicType in src/core/types.ts:
export type LogicType = "LINEAR_SIMPLE" | "EXPONENTIAL_COMPLEX";
  1. Implement the logic class in src/core/logicRegistry.ts:
class ExponentialComplexLogic implements BusinessLogic {
  calculateUpgradeCost(level: number): Decimal {
    // Your formula here
  }
  
  calculateRawRevenue(level: number): Decimal {
    // Your formula here
  }
}
  1. Add it to the factory function:
export function getBusinessLogic(config: BusinessConfig): BusinessLogic {
  switch (config.logicType) {
    case "LINEAR_SIMPLE":
      return new LinearSimpleLogic(config.params);
    case "EXPONENTIAL_COMPLEX":
      return new ExponentialComplexLogic(config.params);
    // ...
  }
}

Adding a New Skill

Add a new entry to SKILLS in src/config/gameData.ts:

{
  id: "skill_customer_service",
  name: "Customer Service Excellence",
  bookInfo: {
    title: "How to Win Friends and Influence People",
    author: "Dale Carnegie",
    summary: "Master the art of customer relations..."
  },
  penaltyWeight: 0.25
}

๐Ÿ“Š Technical Specifications

  • Language: TypeScript 5+ (Strict Mode)
  • State Management: Zustand with persist middleware
  • Math Library: decimal.js for arbitrary-precision arithmetic
  • Persistence: localStorage with custom Decimal serialization
  • Module System: ESM (ES Modules)

๐ŸŽ“ Educational Philosophy

Edu-Tycoon teaches business concepts through gameplay:

  • Financial Literacy: Understanding costs, revenue, and profit margins
  • Compound Growth: Exponential scaling of upgrade costs
  • Skill Investment: Learning pays dividends through increased efficiency
  • Opportunity Cost: Choosing which businesses and skills to prioritize

๐Ÿ“ License

MIT

๐Ÿค Contributing

This is an MVP. Future enhancements could include:

  • More business logic types (banking, IT projects, real estate)
  • Prestige system for long-term progression
  • Multiplayer competition
  • Event system for random market changes
  • Achievement system

Built with โค๏ธ for education and gameplay

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages