test_wall_config_integration.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // 测试墙体配置集成
  2. // 验证MainUIController是否正确使用wall.json配置
  3. console.log('=== 墙体配置集成测试 ===');
  4. // 模拟wall.json配置数据
  5. const mockWallConfig = {
  6. wallConfig: {
  7. maxLevel: 5,
  8. healthByLevel: {
  9. "1": 100,
  10. "2": 500,
  11. "3": 1200,
  12. "4": 1500,
  13. "5": 2000
  14. },
  15. upgradeCosts: {
  16. "1": 100,
  17. "2": 300,
  18. "3": 1000,
  19. "4": 2000
  20. }
  21. }
  22. };
  23. // 模拟SaveDataManager的方法
  24. class MockSaveDataManager {
  25. constructor() {
  26. this.wallConfig = mockWallConfig;
  27. this.playerData = {
  28. wallLevel: 1,
  29. money: 1000
  30. };
  31. }
  32. getWallLevel() {
  33. return this.playerData.wallLevel;
  34. }
  35. getWallUpgradeCost() {
  36. const costs = this.wallConfig.wallConfig.upgradeCosts;
  37. return costs[this.playerData.wallLevel.toString()] || 0;
  38. }
  39. getWallHealthByLevel(level) {
  40. const healthMap = this.wallConfig.wallConfig.healthByLevel;
  41. return healthMap[level.toString()] || 0;
  42. }
  43. getWallMaxLevel() {
  44. return this.wallConfig.wallConfig.maxLevel || 5;
  45. }
  46. }
  47. // 测试升级信息显示逻辑
  48. function testUpgradeInfoDisplay() {
  49. console.log('\n--- 测试升级信息显示 ---');
  50. const sdm = new MockSaveDataManager();
  51. // 测试不同等级的显示
  52. for (let level = 1; level <= 5; level++) {
  53. sdm.playerData.wallLevel = level;
  54. const currentLevel = sdm.getWallLevel();
  55. const cost = sdm.getWallUpgradeCost();
  56. const currentHp = sdm.getWallHealthByLevel(currentLevel);
  57. const nextHp = sdm.getWallHealthByLevel(currentLevel + 1);
  58. const maxLevel = sdm.getWallMaxLevel();
  59. console.log(`等级 ${level}:`);
  60. console.log(` 升级费用: ${cost}`);
  61. console.log(` 当前血量: ${currentHp}`);
  62. console.log(` 下级血量: ${nextHp}`);
  63. console.log(` 血量显示: ${currentHp}>>${nextHp}`);
  64. console.log(` 是否达到最大等级: ${currentLevel >= maxLevel}`);
  65. console.log('');
  66. }
  67. }
  68. // 测试升级逻辑
  69. function testUpgradeLogic() {
  70. console.log('--- 测试升级逻辑 ---');
  71. const sdm = new MockSaveDataManager();
  72. // 测试各种升级场景
  73. const testCases = [
  74. { level: 1, money: 50, desc: '金币不足' },
  75. { level: 1, money: 150, desc: '正常升级' },
  76. { level: 5, money: 5000, desc: '已达最大等级' },
  77. { level: 4, money: 1500, desc: '升级到最大等级前' }
  78. ];
  79. testCases.forEach((testCase, index) => {
  80. console.log(`\n测试案例 ${index + 1}: ${testCase.desc}`);
  81. sdm.playerData.wallLevel = testCase.level;
  82. sdm.playerData.money = testCase.money;
  83. const currentLevel = sdm.getWallLevel();
  84. const cost = sdm.getWallUpgradeCost();
  85. const maxLevel = sdm.getWallMaxLevel();
  86. console.log(` 当前等级: ${currentLevel}`);
  87. console.log(` 当前金币: ${testCase.money}`);
  88. console.log(` 升级费用: ${cost}`);
  89. console.log(` 最大等级: ${maxLevel}`);
  90. // 检查升级条件
  91. if (currentLevel >= maxLevel) {
  92. console.log(' 结果: 墙体已达到最大等级');
  93. } else if (testCase.money < cost) {
  94. console.log(` 结果: 钞票不足,需要${cost}钞票`);
  95. } else {
  96. console.log(' 结果: 可以升级');
  97. }
  98. });
  99. }
  100. // 运行测试
  101. testUpgradeInfoDisplay();
  102. testUpgradeLogic();
  103. console.log('\n=== 测试完成 ===');
  104. console.log('MainUIController现在应该正确使用wall.json配置数据了!');