Files
warOfCoins/pages/result/result.js
2025-12-07 22:53:46 +08:00

252 lines
7.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// result.js
const app = getApp()
Page({
data: {
event: null,
selectedStrategies: [],
result: {
title: "",
description: "",
score: 0,
scoreText: "",
imageClass: ""
},
historyLessons: [],
isLoading: true,
showShareTip: false
},
onLoad: function() {
wx.showLoading({
title: '分析结果中...',
mask: true
});
const selectedEvent = app.globalData.selectedEvent;
const selectedStrategies = app.globalData.selectedStrategies;
if (!selectedEvent || !selectedStrategies || selectedStrategies.length === 0) {
wx.showToast({
title: '缺少必要数据',
icon: 'none',
duration: 2000
});
setTimeout(() => {
wx.navigateBack();
}, 2000);
return;
}
// 模拟结果计算延迟,增强体验
setTimeout(() => {
// 计算结果
const result = this.calculateResult(selectedEvent, selectedStrategies);
const lessons = this.generateHistoryLessons(selectedEvent, selectedStrategies);
this.setData({
event: selectedEvent,
selectedStrategies: selectedStrategies,
result: result,
historyLessons: lessons,
isLoading: false
});
wx.hideLoading();
}, 1500);
},
calculateResult: function(event, strategies) {
// 基础分数,根据策略数量和适用性计算
let score = 0;
const maxScore = 100;
const strategiesCount = strategies.length;
// 针对每个策略评分
strategies.forEach(item => {
const strategy = item.strategy;
// 策略是否适用于当前事件类型
if (strategy.applicable && strategy.applicable.includes(event.type)) {
// 基础加分
score += 20;
// 根据危机等级和策略类型给予额外加分
if (event.level === 3) { // 高级危机
if (strategiesCount >= 3) { // 多种策略组合应对高级危机
score += 10;
}
} else if (event.level === 2) { // 中级危机
if (strategiesCount >= 2) { // 至少两种策略
score += 5;
}
}
// 根据策略选择的轮次给予不同评分
// 某些危机类型在早期应对更有效
if (item.round === 1 && (event.type === 'fakeCurrency' || event.type === 'exchange')) {
score += 5; // 早期应对金融类危机更有效
}
// 组合策略加分(比如经济+行政双管齐下)
const typeCount = this.countStrategyTypes(strategies);
if (typeCount >= 2) { // 如果使用了至少两种不同类型的策略
score += 5;
}
} else {
// 使用了不适用的策略
score -= 10;
}
});
// 最终得分不超过100不低于0
score = Math.min(Math.max(score, 0), maxScore);
// 根据得分确定结果文本
let title = "";
let description = "";
let scoreText = "";
let imageClass = "";
if (score >= 90) {
title = "完美应对!";
description = "您的策略组合非常出色,充分借鉴了历史经验,有效应对了" + event.title + "。根据地经济形势明显好转,边币稳定流通,人民生活得到保障。";
scoreText = "卓越";
imageClass = "result-excellent";
} else if (score >= 70) {
title = "有效应对";
description = "您的策略组合较为合理,基本控制了" + event.title + "带来的影响。根据地经济形势稳定,边币信任度维持,保障了基本生活需求。";
scoreText = "良好";
imageClass = "result-good";
} else if (score >= 40) {
title = "基本应对";
description = "您的部分策略发挥了作用,但面对" + event.title + "仍有不足。根据地经济受到一定冲击,边币价值有所波动,生活水平略有下降。";
scoreText = "一般";
imageClass = "result-average";
} else {
title = "应对失败";
description = "您的策略未能有效应对" + event.title + "。根据地经济遭受重创,边币严重贬值,人民生活陷入困境。建议重新思考策略组合。";
scoreText = "不佳";
imageClass = "result-poor";
}
return {
title: title,
description: description,
score: score,
scoreText: scoreText,
imageClass: imageClass
};
},
// 统计策略类型数量
countStrategyTypes: function(strategies) {
const types = new Set();
strategies.forEach(item => {
if (item.strategy.id.startsWith('economic')) {
types.add('economic');
} else if (item.strategy.id.startsWith('admin')) {
types.add('administrative');
} else if (item.strategy.id.startsWith('mob')) {
types.add('mobilization');
}
});
return types.size;
},
// 生成历史经验教训
generateHistoryLessons: function(event, strategies) {
const lessons = [];
// 根据事件类型和策略选择生成相关历史经验
if (event.type === 'fakeCurrency') {
lessons.push({
title: "货币稳定的关键经验",
content: "历史上,边区政府通过加强金融制度建设和稳定物价,有效维护了边币流通秩序。"
});
} else if (event.type === 'shortage') {
lessons.push({
title: "应对物资短缺的经验",
content: "各根据地在物资匮乏时期,通过发展生产、精简机构、厉行节约等多种方式度过难关。"
});
} else if (event.type === 'exchange') {
lessons.push({
title: "汇率稳定的历史借鉴",
content: "边区政府曾通过调整法币与边币比价、加强市场监管等措施,保障币值稳定。"
});
}
// 根据策略选择添加具体历史案例
const hasEconomic = strategies.some(item => item.strategy.id.startsWith('economic'));
const hasAdmin = strategies.some(item => item.strategy.id.startsWith('admin'));
const hasMob = strategies.some(item => item.strategy.id.startsWith('mob'));
if (hasEconomic && hasAdmin) {
lessons.push({
title: "经济与行政措施协同",
content: "历史经验表明,经济措施与行政手段相结合,能形成系统性解决方案,效果优于单一策略。"
});
}
if (hasMob) {
lessons.push({
title: "群众基础的重要性",
content: "边区政府的各项政策能够成功实施,离不开广大人民群众的支持与参与。动员群众是解决危机的基础。"
});
}
return lessons;
},
// 重新应对按钮点击事件
handleRestart: function() {
wx.showLoading({
title: '准备中...',
mask: true
});
setTimeout(() => {
wx.hideLoading();
wx.navigateBack({
delta: 1
});
}, 800);
},
// 返回首页按钮点击事件
handleBackToHome: function() {
wx.showLoading({
title: '返回首页...',
mask: true
});
setTimeout(() => {
wx.hideLoading();
wx.navigateBack({
delta: 2
});
}, 800);
},
// 分享按钮点击事件
handleShare: function() {
this.setData({
showShareTip: true
});
setTimeout(() => {
this.setData({
showShareTip: false
});
}, 3000);
},
// 生命周期函数
onShareAppMessage: function() {
return {
title: `我在边区危机中获得了${this.data.result.score}分的评价!`,
path: '/pages/index/index',
imageUrl: '/images/share-img.jpg' // 需要提供分享图片
};
}
})