Changed around line 1
+ class CultivationGame {
+ constructor() {
+ this.level = 1;
+ this.qi = 0;
+ this.progress = 0;
+ this.cultivating = false;
+ this.initializeElements();
+ this.bindEvents();
+ }
+
+ initializeElements() {
+ this.levelElement = document.getElementById('level');
+ this.qiElement = document.getElementById('qi');
+ this.progressElement = document.getElementById('progress');
+ this.messagesElement = document.getElementById('messages');
+ this.cultivateButton = document.getElementById('cultivate');
+ this.breakthroughButton = document.getElementById('breakthrough');
+ this.character = document.getElementById('player');
+ }
+
+ bindEvents() {
+ this.cultivateButton.addEventListener('click', () => this.toggleCultivation());
+ this.breakthroughButton.addEventListener('click', () => this.breakthrough());
+ }
+
+ toggleCultivation() {
+ this.cultivating = !this.cultivating;
+ this.cultivateButton.textContent = this.cultivating ? '停止修炼' : '修炼';
+
+ if (this.cultivating) {
+ this.cultivationLoop();
+ this.addMessage('开始修炼...');
+ this.character.style.boxShadow = '0 0 50px var(--qi-color)';
+ } else {
+ this.character.style.boxShadow = 'none';
+ this.addMessage('停止修炼');
+ }
+ }
+
+ cultivationLoop() {
+ if (!this.cultivating) return;
+
+ this.qi += Math.random() * 2;
+ this.progress += Math.random() * 3;
+
+ if (this.progress >= 100) {
+ this.breakthroughButton.disabled = false;
+ this.addMessage('突破机缘已到!');
+ }
+
+ this.updateUI();
+ requestAnimationFrame(() => setTimeout(() => this.cultivationLoop(), 1000));
+ }
+
+ breakthrough() {
+ if (this.progress < 100) return;
+
+ this.level++;
+ this.progress = 0;
+ this.breakthroughButton.disabled = true;
+ this.addMessage(`突破成功!当前境界: 练气${this.level}层`);
+ this.createBreakthroughEffect();
+ this.updateUI();
+ }
+
+ createBreakthroughEffect() {
+ const effect = document.createElement('div');
+ effect.style.cssText = `
+ position: absolute;
+ left: 50%;
+ top: 50%;
+ transform: translate(-50%, -50%);
+ width: 200px;
+ height: 200px;
+ background: radial-gradient(circle, var(--qi-color), transparent);
+ animation: expand 2s ease-out forwards;
+ opacity: 0.8;
+ `;
+ document.querySelector('.cultivation-effects').appendChild(effect);
+ setTimeout(() => effect.remove(), 2000);
+ }
+
+ addMessage(text) {
+ const message = document.createElement('div');
+ message.textContent = text;
+ this.messagesElement.insertBefore(message, this.messagesElement.firstChild);
+ }
+
+ updateUI() {
+ this.levelElement.textContent = `境界: 练气${this.level}层`;
+ this.qiElement.textContent = `灵气: ${Math.floor(this.qi)}`;
+ this.progressElement.style.width = `${this.progress}%`;
+ }
+ }
+
+ document.addEventListener('DOMContentLoaded', () => {
+ new CultivationGame();
+ });