// Computer Evolution Idle Game class ComputerEvolution { constructor() { this.money = 50; this.totalEarned = 0; this.investors = 0; this.soundEnabled = true; this.lastSave = Date.now(); // Prestige system this.prestigeMultiplier = 1; this.totalPrestiges = 0; this.prestigeThreshold = 10; // Minimum 10% investors to prestige // Hardware this.hardware = { hdd: { quantity: 1, capacity: 12, // MB used: 0, baseCost: { quantity: 2.5, capacity: 1.9 }, costMultiplier: 1.5 }, cpu: { cores: 1, speed: 38.7, // MHz used: 0, baseCost: { cores: 50, speed: 23 }, costMultiplier: 1.6 }, ram: { quantity: 1, capacity: 31.3, // MB used: 0, baseCost: { quantity: 50, capacity: 23 }, costMultiplier: 1.5 }, motherboard: { level: 1, maxOS: 2, baseCost: 11.5, costMultiplier: 2.5 } }; // OS Levels this.osLevels = [ { name: "Sixtem 1.0", multiplier: 1, reqMotherboard: 1 }, { name: "Sixtem 2.0", multiplier: 1.5, reqMotherboard: 1 }, { name: "Sixtem 3.0", multiplier: 2.5, reqMotherboard: 2 }, { name: "Sixtem Pro", multiplier: 4, reqMotherboard: 3 }, { name: "Sixtem Ultra", multiplier: 7, reqMotherboard: 4 }, { name: "Quantum OS", multiplier: 12, reqMotherboard: 5 } ]; this.currentOS = 1; // Index // Apps this.availableApps = [ { id: 'terminal', name: 'Terminal', icon: 'terminal', cost: 0, income: 0.5, storage: 2, ram: 1, color: 'bg-gray-800', installed: true }, { id: 'loserar', name: 'Loserar', icon: 'file-archive', cost: 100, income: 2, storage: 4, ram: 2, color: 'bg-pink-500', installed: false }, { id: 'landbrush', name: 'Landbrush', icon: 'paintbrush', cost: 500, income: 5, storage: 8, ram: 4, color: 'bg-purple-500', installed: false }, { id: 'webnav', name: 'WebNav', icon: 'globe', cost: 2000, income: 12, storage: 16, ram: 8, color: 'bg-blue-500', installed: false }, { id: 'mailer', name: 'Mailer', icon: 'mail', cost: 8000, income: 30, storage: 32, ram: 16, color: 'bg-yellow-500', installed: false }, { id: 'musicbox', name: 'MusicBox', icon: 'music', cost: 25000, income: 80, storage: 64, ram: 32, color: 'bg-red-500', installed: false }, { id: 'videocut', name: 'VideoCut', icon: 'video', cost: 100000, income: 200, storage: 128, ram: 64, color: 'bg-indigo-500', installed: false }, { id: 'gamedev', name: 'GameDev', icon: 'gamepad-2', cost: 500000, income: 600, storage: 256, ram: 128, color: 'bg-green-500', installed: false } ]; this.installedApps = ['terminal']; this.init(); } init() { this.loadGame(); this.updateUI(); this.renderApps(); // Game loop setInterval(() => this.gameLoop(), 100); setInterval(() => this.saveGame(), 30000); // Auto-save every 30s // Update UI every 100ms for smooth progress bars setInterval(() => this.updateProgressBars(), 100); } gameLoop() { const income = this.calculateIncome(); this.money += income / 10; // Divide by 10 because we run 10 times per second this.totalEarned += income / 10; // Update investors based on total earned this.investors = Math.min(100, (this.totalEarned / 1000000) * 100); this.updateUI(); } calculateIncome() { let baseIncome = 1.6; // Base OS income // Add app incomes this.installedApps.forEach(appId => { const app = this.availableApps.find(a => a.id === appId); if (app) baseIncome += app.income; }); // Apply CPU speed multiplier const cpuMultiplier = 1 + (this.hardware.cpu.speed / 100); // Apply OS multiplier const osMultiplier = this.osLevels[this.currentOS].multiplier; // Apply Prestige multiplier // Formula: 1 + (investors% / 100) * 0.5 at 10%, up to 1 + (100/100) * 2 = 3x at 100% // But we use the stored prestigeMultiplier which is calculated at prestige time return baseIncome * cpuMultiplier * osMultiplier * this.prestigeMultiplier; } calculatePrestigeBoost() { // Calculate potential boost based on current investors // At 10%: 1.1x boost (10% increase) // At 50%: 1.5x boost (50% increase) // At 100%: 2.5x boost (150% increase) if (this.investors < this.prestigeThreshold) return 0; // Formula: 1 + (investors / 100) * 1.5 // 10% = 1.15x, 100% = 2.5x const boost = 1 + (this.investors / 100) * 1.5; return boost; } canPrestige() { return this.investors >= this.prestigeThreshold; } prestige() { if (!this.canPrestige()) { this.showToast('Cannot Prestige', `You need at least ${this.prestigeThreshold}% investors!`); return; } const boost = this.calculatePrestigeBoost(); const oldMultiplier = this.prestigeMultiplier; this.prestigeMultiplier *= boost; this.totalPrestiges++; // Reset game progress this.money = 50; this.totalEarned = 0; this.investors = 0; // Reset hardware this.hardware = { hdd: { quantity: 1, capacity: 12, used: 0, baseCost: { quantity: 2.5, capacity: 1.9 }, costMultiplier: 1.5 }, cpu: { cores: 1, speed: 38.7, used: 0, baseCost: { cores: 50, speed: 23 }, costMultiplier: 1.6 }, ram: { quantity: 1, capacity: 31.3, used: 0, baseCost: { quantity: 50, capacity: 23 }, costMultiplier: 1.5 }, motherboard: { level: 1, maxOS: 2, baseCost: 11.5, costMultiplier: 2.5 } }; // Reset OS this.currentOS = 1; // Reset apps this.installedApps = ['terminal']; this.availableApps.forEach(app => { app.installed = app.id === 'terminal'; }); // Close modal if open this.toggleSettings(); this.showToast('Prestige Complete!', `Boost: ${boost.toFixed(2)}x\nTotal Multiplier: ${oldMultiplier.toFixed(2)}x → ${this.prestigeMultiplier.toFixed(2)}x`, 5000); this.updateUI(); this.renderApps(); this.saveGame(); } calculateUsage() { let storageUsed = 0; let ramUsed = 0; let cpuUsed = 0; this.installedApps.forEach(appId => { const app = this.availableApps.find(a => a.id === appId); if (app) { storageUsed += app.storage; ramUsed += app.ram; cpuUsed += app.income; // Higher income apps use more CPU } }); return { storage: storageUsed, ram: ramUsed, cpu: cpuUsed }; } formatMoney(amount) { if (amount >= 1e12) return '$' + (amount / 1e12).toFixed(2) + 'T'; if (amount >= 1e9) return '$' + (amount / 1e9).toFixed(2) + 'B'; if (amount >= 1e6) return '$' + (amount / 1e6).toFixed(2) + 'M'; if (amount >= 1e3) return '$' + (amount / 1e3).toFixed(2) + 'K'; return '$' + amount.toFixed(2); } formatBytes(mb) { if (mb >= 1024) return (mb / 1024).toFixed(2) + 'GB'; if (mb >= 1) return mb.toFixed(2) + 'MB'; return (mb * 1024).toFixed(0) + 'kB'; } formatFreq(mhz) { if (mhz >= 1000) return (mhz / 1000).toFixed(2) + 'GHz'; return mhz.toFixed(2) + 'MHz'; } getUpgradeCost(component, type) { const hw = this.hardware[component]; const currentLevel = hw[type]; return hw.baseCost[type] * Math.pow(hw.costMultiplier, currentLevel - 1); } getMotherboardCost() { const mb = this.hardware.motherboard; return mb.baseCost * Math.pow(mb.costMultiplier, mb.level - 1); } upgrade(component, type) { const cost = this.getUpgradeCost(component, type); if (this.money >= cost) { this.money -= cost; this.hardware[component][type]++; this.updateUI(); this.showToast('Upgrade Complete', `${component.toUpperCase()} ${type} upgraded!`); } } upgradeMotherboard() { const cost = this.getMotherboardCost(); if (this.money >= cost) { this.money -= cost; this.hardware.motherboard.level++; this.hardware.motherboard.maxOS = this.hardware.motherboard.level + 1; this.checkOSUpgrade(); this.updateUI(); this.showToast('Motherboard Upgraded', 'You can now install better OS versions!'); } } checkOSUpgrade() { // Auto-upgrade OS if possible for (let i = this.osLevels.length - 1; i >= 0; i--) { if (this.hardware.motherboard.level >= this.osLevels[i].reqMotherboard && i > this.currentOS) { this.currentOS = i; this.showToast('OS Upgraded', `Welcome to ${this.osLevels[i].name}!`); break; } } } installApp(appId) { const app = this.availableApps.find(a => a.id === appId); if (!app || app.installed) return; const usage = this.calculateUsage(); const maxStorage = this.hardware.hdd.capacity * this.hardware.hdd.quantity; const maxRam = this.hardware.ram.capacity * this.hardware.ram.quantity; if (usage.storage + app.storage > maxStorage) { this.showToast('Error', 'Not enough storage space!'); return; } if (usage.ram + app.ram > maxRam) { this.showToast('Error', 'Not enough RAM!'); return; } if (this.money < app.cost) { this.showToast('Error', 'Not enough money!'); return; } this.money -= app.cost; app.installed = true; this.installedApps.push(appId); this.renderApps(); this.updateUI(); this.closeAppStore(); this.showToast('App Installed', `${app.name} has been installed!`); } manualClick(event) { const amount = 1 + (this.hardware.cpu.cores * 0.5); this.money += amount; this.totalEarned += amount; // Visual feedback const floatEl = document.createElement('div'); floatEl.className = 'fixed pointer-events-none text-green-600 font-bold text-xl money-animation z-50'; floatEl.textContent = '+' + this.formatMoney(amount); floatEl.style.left = event.clientX + 'px'; floatEl.style.top = event.clientY + 'px'; document.body.appendChild(floatEl); setTimeout(() => floatEl.remove(), 1000); this.updateUI(); } updateUI() { // Header document.getElementById('balance-display').textContent = this.formatMoney(this.money); document.getElementById('income-display').textContent = this.formatMoney(this.calculateIncome()); document.getElementById('investors-display').textContent = this.investors.toFixed(1) + '%'; // Update prestige display const prestigeDisplay = document.getElementById('prestige-display'); const prestigeBtn = document.getElementById('prestige-btn'); const currentMultiplierEl = document.getElementById('current-prestige-multiplier'); const totalPrestigesEl = document.getElementById('total-prestiges'); if (prestigeDisplay) { prestigeDisplay.textContent = this.prestigeMultiplier.toFixed(2) + 'x'; } if (currentMultiplierEl) { currentMultiplierEl.textContent = this.prestigeMultiplier.toFixed(2) + 'x'; } if (totalPrestigesEl) { totalPrestigesEl.textContent = this.totalPrestiges; } // Update prestige button state if (prestigeBtn) { if (this.canPrestige()) { const potentialBoost = this.calculatePrestigeBoost(); const potentialMultiplier = this.prestigeMultiplier * potentialBoost; prestigeBtn.innerHTML = `
Income: +${this.formatMoney(app.income)}/s
Uses: ${this.formatBytes(app.storage)} storage, ${this.formatBytes(app.ram)} RAM
All apps installed! Check back later for updates.
'; } modal.classList.remove('hidden'); lucide.createIcons(); } closeAppStore() { document.getElementById('app-store-modal').classList.add('hidden'); } toggleSettings() { const modal = document.getElementById('settings-modal'); modal.classList.toggle('hidden'); } toggleSound() { this.soundEnabled = !this.soundEnabled; document.getElementById('sound-text').textContent = this.soundEnabled ? 'Sound' : 'Muted'; document.getElementById('sound-btn').classList.toggle('bg-emerald-600'); document.getElementById('sound-btn').classList.toggle('bg-gray-600'); } showInfo(component) { const info = { hdd: { title: 'Hard Drive', text: 'Stores your applications. Upgrade capacity to install more apps, or quantity for redundancy.' }, cpu: { title: 'Processor', text: 'Processes data. More cores and speed increases your income multiplier.' }, ram: { title: 'Memory', text: 'Required to run applications. Each app needs RAM to function.' }, motherboard: { title: 'Motherboard', text: 'Determines which OS versions you can support. Required for major upgrades.' } }; if (info[component]) { this.showToast(info[component].title, info[component].text, 5000); } } showToast(title, text, duration = 3000) { const toast = document.getElementById('info-toast'); document.getElementById('info-title').textContent = title; document.getElementById('info-text').textContent = text; toast.classList.remove('translate-y-20', 'opacity-0'); setTimeout(() => { toast.classList.add('translate-y-20', 'opacity-0'); }, duration); } saveGame() { const data = { money: this.money, totalEarned: this.totalEarned, investors: this.investors, hardware: this.hardware, currentOS: this.currentOS, installedApps: this.installedApps, availableApps: this.availableApps.map(app => ({ id: app.id, installed: app.installed })), prestigeMultiplier: this.prestigeMultiplier, totalPrestiges: this.totalPrestiges }; localStorage.setItem('computerEvolutionSave', JSON.stringify(data)); this.showToast('Game Saved', 'Your progress has been saved!'); } loadGame() { const saved = localStorage.getItem('computerEvolutionSave'); if (saved) { try { const data = JSON.parse(saved); this.money = data.money || 50; this.totalEarned = data.totalEarned || 0; this.investors = data.investors || 0; if (data.hardware) this.hardware = data.hardware; if (data.currentOS) this.currentOS = data.currentOS; if (data.installedApps) this.installedApps = data.installedApps; if (data.availableApps) { data.availableApps.forEach(savedApp => { const app = this.availableApps.find(a => a.id === savedApp.id); if (app) app.installed = savedApp.installed; }); } if (data.prestigeMultiplier) this.prestigeMultiplier = data.prestigeMultiplier; if (data.totalPrestiges) this.totalPrestiges = data.totalPrestiges; this.showToast('Game Loaded', 'Welcome back!'); } catch (e) { console.error('Failed to load save:', e); } } } resetGame() { if (confirm('Are you sure you want to reset all progress?')) { localStorage.removeItem('computerEvolutionSave'); location.reload(); } } } // Initialize game const game = new ComputerEvolution(); // Prevent context menu on right click for game feel document.addEventListener('contextmenu', e => e.preventDefault());