-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsmallProject.js
More file actions
89 lines (72 loc) · 2.49 KB
/
Copy pathsmallProject.js
File metadata and controls
89 lines (72 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
var smallProjectTitles = ["Project 1", "Project 2", "Project 3"];
var smallProjectTitlesAmount = smallProjectTitles.length;
var SmallProject = {
title: "Title",
currAmount: 0,
totalAmount: 0,
reward: 0,
updateTitle: function() {
$("#smallProjectTitle").text(this.title);
},
updateAmounts: function() {
var amounts = $("#smallProjectProgressAmount");
amounts.children("span.currentAmount").html(this.currAmount);
amounts.children("span.totalAmount").html(this.totalAmount);
this.updateProgressBar();
},
updateProgressBar: function() {
var percentage = 100;
if(this.totalAmount != 0)
percentage = Math.floor(this.currAmount/this.totalAmount*100);
$("#smallProjectProgressBarBackground").css("width", percentage+"%");
$("#smallProjectProgressBarLabel").text(percentage+"%");
},
updateReward: function() {
$("#smallProjectRewardAmount").text(this.reward);
},
update: function() {
this.updateTitle();
this.updateAmounts();
this.updateReward();
},
getRandomRequirements: function() {
return randomInteger(Player.level*5, Player.level*10);
},
getRandomReward: function() {
return randomInteger(Player.level*5, Player.level*10);
},
shuffle: function() {
this.title = smallProjectTitles[Math.floor(Math.random()*smallProjectTitlesAmount)];
this.currAmount = 0;
this.totalAmount = this.getRandomRequirements();
this.reward = this.getRandomReward();
this.update();
},
addPoints: function(points) {
this.currAmount += points;
if(this.currAmount > this.totalAmount)
this.currAmount = this.totalAmount;
// Check if finished project
if(this.currAmount == this.totalAmount)
{
// Project is finished
++Player.projectsCompleted;
Achievements.checkAchievementsType("projectsCompleted");
cash += this.reward;
Achievements.checkAchievementsType("totalCash");
updateCash();
this.shuffle();
if(soundsEnabled)
{
//document.getElementById("cash_in").play();
//console.log("play");
//$("#cash_in").trigger("play");
playCashSound();
}
}
this.updateAmounts();
},
buttonClick: function() {
SmallProject.addPoints(Player.clickPower);
}
};