重构计划
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.
User Review Required
Section titled “User Review Required”[!IMPORTANT]
- All refactored Java files will be put into the package
com.genshin.rpgand its subpackages.- As per requirements, we will NOT use
GameContext. All global states will remain as fields inMainFrame.javato minimize redirection.- We will extract elements styling (names, colors, hex values, reaction translation) into
view/ui/ElementStyle.javaand 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 bepublic.- Comments will be added for all constructors and methods (public/protected/private) detailing their purpose, inputs, and outputs/side-effects.
Proposed Changes
Section titled “Proposed Changes”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.javaincom.genshin.rpg.view/.- Button event handlers will be annotated with
// 点击后:①... ②... ③.... - Internal element styling switches are replaced by calls to
ElementStyle.
- Button event handlers will be annotated with
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.javaas a standalonepublicclass. - [NEW]
Character.java,Player.java,Enemy.java,Stats.java,Item.java,User.java,SkillData.java,Inventory.javaundercom.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.javaas apublicclass. - [NEW] Skills: Skill.java (abstract class),
NormalAttack.java,ElementalSkill.java,ElementalBurst.javaundercom.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
AdminCharDataandAdminItemData.
6. Build and Helper Files
Section titled “6. Build and Helper Files”- [NEW] run.bat: Executes compiler (
javac) with-encoding UTF-8and runscom.genshin.rpg.Main. - [NEW] REFACTOR_NOTE.md: Contains structural mapping and self-validation logs.
Verification Plan
Section titled “Verification Plan”Automated Verification
Section titled “Automated Verification”- We will execute
run.batinrefactored/to compile all source files and run the program. - Compilation must produce
0 errors.
Manual Verification Checklist
Section titled “Manual Verification Checklist”- Verify the login panel shows up correctly.
- Register a new user, check that it writes to DB or triggers fallback.
- Verify menu navigation (MainMenu -> Team -> Upgrade -> Level -> Battle -> Bag -> Admin).
- Run level 1 battle, check that damage is calculated correctly, elemental reactions trigger, and rewards are granted.
- In AdminPanel, perform CRUD operations, check user credentials, save and reload progress.
- Verify fallback data loads and saves without MySQL connection.