Skip to content

Commit

Permalink
update happinessImpact
Browse files Browse the repository at this point in the history
  • Loading branch information
penpen72 committed Dec 17, 2024
1 parent a6ff088 commit c8deb41
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 48 deletions.
40 changes: 20 additions & 20 deletions data.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@

// 所有選項的幸福度增加一倍,例如原本+2就改成+4, -3改成-6
const monthlyOptions = [
{ id: 1, text: "舉辦免費下午茶", happinessImpact: +4 },
{ id: 2, text: "加班一次(無補休)", happinessImpact: -6 },
{ id: 3, text: "團隊建築課程", happinessImpact: +6 },
{ id: 4, text: "高層演講會議", happinessImpact: -2 },
{ id: 5, text: "發放小額獎金", happinessImpact: +4 },
{ id: 6, text: "新制度實施(增加工作流程)", happinessImpact: -4 },
{ id: 7, text: "公司郊遊日", happinessImpact: +8 },
{ id: 8, text: "延後薪資發放", happinessImpact: -8 },
{ id: 9, text: "生日慶祝派對", happinessImpact: +6 },
{ id: 10, text: "部門間競賽(輸家被懲罰)", happinessImpact: -4 },
{ id: 11, text: "免費健康檢查", happinessImpact: +4 },
{ id: 12, text: "禁止私人上網(嚴格管制)", happinessImpact: -6 },
{ id: 13, text: "員工意見箱(定期反饋)", happinessImpact: +2 },
{ id: 14, text: "減少年終獎金", happinessImpact: -6 },
{ id: 15, text: "提供員工家庭日", happinessImpact: +6 },
{ id: 16, text: "團隊閱讀分享會", happinessImpact: +2 },
{ id: 17, text: "無預警加班", happinessImpact: -4 },
{ id: 18, text: "員工健身房補助", happinessImpact: +4 },
{ id: 19, text: "調整座位(提升舒適度)", happinessImpact: +2 },
{ id: 20, text: "嚴格績效考核(壓力提升)", happinessImpact: -2 }
{ id: 1, text: "舉辦免費下午茶", happinessImpact: +8 },
{ id: 2, text: "加班一次", happinessImpact: -12 },
{ id: 3, text: "團隊建築課程", happinessImpact: +12 },
{ id: 4, text: "高層演講會議", happinessImpact: -10 },
{ id: 5, text: "發放小額獎金", happinessImpact: +8 },
{ id: 6, text: "新制度實施", happinessImpact: -8 },
{ id: 7, text: "公司郊遊日", happinessImpact: +16 },
{ id: 8, text: "延後薪資發放", happinessImpact: -16 },
{ id: 9, text: "生日慶祝派對", happinessImpact: +12 },
{ id: 10, text: "部門間競賽", happinessImpact: -8 },
{ id: 11, text: "免費健康檢查", happinessImpact: +8 },
{ id: 12, text: "禁止私人上網", happinessImpact: -12 },
{ id: 13, text: "員工意見箱(定期反饋)", happinessImpact: +4 },
{ id: 14, text: "減少年終獎金", happinessImpact: -12 },
{ id: 15, text: "提供員工家庭日", happinessImpact: +12 },
{ id: 16, text: "團隊閱讀分享會", happinessImpact: +4 },
{ id: 17, text: "無預警加班", happinessImpact: -8 },
{ id: 18, text: "員工健身房補助", happinessImpact: +8 },
{ id: 19, text: "調整座位", happinessImpact: +4 },
{ id: 20, text: "績效考核", happinessImpact: -20 }
];

const leaveReasons = [
Expand Down
63 changes: 35 additions & 28 deletions game.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,7 @@ async function nextMonth() {

if (currentMonth > 12) {
await endOfYearCheck();
if (!gameOver) {
year++;
yearsPassed++;
currentMonth = 1;
totalPositiveImpact = 0;
totalNegativeImpact = 0;

yearlyRecords.push({
year: year,
events: [],
endOfYearInfo: {}
});

document.getElementById('results').innerHTML = '';
updateTopStatus();
updateHappinessBar();
nextMonth();
}
return;
return; // 年度結束後,不直接繼續,由玩家點擊「繼續」按鈕繼續
}

showMonthChoices();
Expand Down Expand Up @@ -131,26 +113,29 @@ async function endOfYearCheck() {
turnoverRate = 0.05;
}

// 每年最多只能離職一人
let leftThisYear = 0;
let leaveDetails = [];

for (let i = 0; i < people; i++) {
if (Math.random() < turnoverRate) {
leftThisYear++;
leftThisYear = 1; // 有人離職
let reason = leaveReasons[Math.floor(Math.random()*leaveReasons.length)];
leaveDetails.push(reason);
break; // 離職一人後立刻停止
}
}

if (leftThisYear > 0) {
people -= leftThisYear;
people -= 1; // 只減少一人
for (let reason of leaveDetails) {
resultsDiv.innerHTML += `有一名員工離職,原因:${reason}<br>`;
updateImage('image/byebye.png');
await delay(50);
}
// 有人離職顯示 byebye.png
updateImage('image/byebye.png');
} else {
resultsDiv.innerHTML += `所有人留下了!<br>`;
// 無人離職顯示 celebrate.png
updateImage('image/celebrate.png');
}

Expand All @@ -164,15 +149,37 @@ async function endOfYearCheck() {
turnoverRate: turnoverRate
};

// 短暫顯示當年結果圖片
updateImage('image/year_end_summary.png');
await delay(3000); // 暫停1秒顯示年度結果圖片
// 年度結束後不繼續下一年,顯示一個「繼續」按鈕
// 清空 month-choices 並顯示繼續按鈕
const monthChoiceContainer = document.getElementById('month-choices');
monthChoiceContainer.innerHTML = `<button class="choice-button" onclick="continueToNextYear()">繼續</button>`;
}

function continueToNextYear() {
if (gameOver) return;

if (people <= 0) {
endGame();
} else {
updateTopStatus();
return;
}

// 開始下一年
year++;
yearsPassed++;
currentMonth = 1;
totalPositiveImpact = 0;
totalNegativeImpact = 0;

yearlyRecords.push({
year: year,
events: [],
endOfYearInfo: {}
});

document.getElementById('results').innerHTML = '';
updateTopStatus();
updateHappinessBar();
nextMonth();
}

function endGame() {
Expand Down

0 comments on commit c8deb41

Please sign in to comment.