跳转到内容

重构计划

This implementation plan details the pure structural refactoring of the Genshin Text RPG student project. The goal is to migrate 23 flat Java source files in the default package from E:\C\cDownKeShe\src\ to a clean, well-packaged, single-class-per-file project structure in E:\AI\zcode\object\ke-she\refactored\. All existing gameplay logic, formula values, and visual styles will remain strictly identical.

[!IMPORTANT]

  • All refactored Java files will be put into the package com.genshin.rpg and its subpackages.
  • As per requirements, we will NOT use GameContext. All global states will remain as fields in MainFrame.java to minimize redirection.
  • We will extract elements styling (names, colors, hex values, reaction translation) into view/ui/ElementStyle.java and call it everywhere. This is the only allowed unification/deduplication.
  • Packageless classes that are accessed across packages (such as ElementAttach, SkillSystem, and concrete skills) must be modified to be public.
  • Comments will be added for all constructors and methods (public/protected/private) detailing their purpose, inputs, and outputs/side-effects.

We will create a brand new target folder E:\AI\zcode\object\ke-she\refactored\ and place all files there.

1. Program Entry & Application Shell (com.genshin.rpg and com.genshin.rpg.app)

Section titled “1. Program Entry & Application Shell (com.genshin.rpg and com.genshin.rpg.app)”
  • [NEW] Main.java: Main entry point. Calls MainFrame.
  • [NEW] MainFrame.java: Inherits all game state fields, view panels, and level progression controls from the original MainFrame.java.

2. UI Components & Style (com.genshin.rpg.view and com.genshin.rpg.view.ui)

Section titled “2. UI Components & Style (com.genshin.rpg.view and com.genshin.rpg.view.ui)”
  • [NEW] ElementStyle.java: Consolidates static color and translation queries for ElementTypes and ReactionTypes.
  • [NEW] Panels: LoginPanel.java, MainMenuPanel.java, LevelPanel.java, BattlePanel.java, TeamPanel.java, UpgradePanel.java, BagPanel.java, AdminPanel.java in com.genshin.rpg.view/.
    • Button event handlers will be annotated with // 点击后:①... ②... ③....
    • Internal element styling switches are replaced by calls to ElementStyle.

3. Model Layer (com.genshin.rpg.model and com.genshin.rpg.model.enums)

Section titled “3. Model Layer (com.genshin.rpg.model and com.genshin.rpg.model.enums)”
  • [NEW] ElementAttach.java: Extracted from Character.java as a standalone public class.
  • [NEW] Character.java, Player.java, Enemy.java, Stats.java, Item.java, User.java, SkillData.java, Inventory.java under com.genshin.rpg.model/.
  • [NEW] ElementType.java: Keeps original enum order.
  • [NEW] ReactionType.java: Keeps original order.

4. Service & Combat Logic Layer (com.genshin.rpg.service and com.genshin.rpg.service.skill)

Section titled “4. Service & Combat Logic Layer (com.genshin.rpg.service and com.genshin.rpg.service.skill)”
  • [NEW] CombatSystem.java: Relies on ElementStyle. All combat calculations preserved.
  • [NEW] SkillSystem.java: Extracted from Skill.java as a public class.
  • [NEW] Skills: Skill.java (abstract class), NormalAttack.java, ElementalSkill.java, ElementalBurst.java under com.genshin.rpg.service.skill/.

5. DAO & Persistence Layer (com.genshin.rpg.dao)

Section titled “5. DAO & Persistence Layer (com.genshin.rpg.dao)”
  • [NEW] DBConnector.java: Manages connections and auto-starts MySQL (via hardcoded command execution).
  • [NEW] TableInitializer.java: Initializes database tables and inserts seeds.
  • [NEW] StorageManager.java: Holds facade methods delegating to DBConnector and TableInitializer. Keeps nested static classes AdminCharData and AdminItemData.
  • [NEW] run.bat: Executes compiler (javac) with -encoding UTF-8 and runs com.genshin.rpg.Main.
  • [NEW] REFACTOR_NOTE.md: Contains structural mapping and self-validation logs.

  • We will execute run.bat in refactored/ to compile all source files and run the program.
  • Compilation must produce 0 errors.
  1. Verify the login panel shows up correctly.
  2. Register a new user, check that it writes to DB or triggers fallback.
  3. Verify menu navigation (MainMenu -> Team -> Upgrade -> Level -> Battle -> Bag -> Admin).
  4. Run level 1 battle, check that damage is calculated correctly, elemental reactions trigger, and rewards are granted.
  5. In AdminPanel, perform CRUD operations, check user credentials, save and reload progress.
  6. Verify fallback data loads and saves without MySQL connection.