-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCosmetics.js
More file actions
73 lines (61 loc) · 2.4 KB
/
Cosmetics.js
File metadata and controls
73 lines (61 loc) · 2.4 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
/**
* represents the cosmetics of a user profile
* including functions of storing changing the cosmetics theme, cosmetics points, and spending cosmetics points
* @class
*/
class Cosmetics {
/**
* create an instance of cosmetics
* @constructor
* @param {String []} availableThemes Showing the array of available custometic themes for purchase
*/
constructor(availableThemes) {
this.availableThemes = availableThemes;
this.availablePoints = 0; //initializing point
}
/**
* changes the theme of the cosmetics to the desired choice
* @param {String} theme - an input of selected theme
* @returns {void}
*/
changeTheme(theme) {
//implements changed theme for cosmetics
//takes in one of the available theme of cosmetics
//validates whether the theme exists or not
if(!this.availableThemes.includes(theme)){
throw new Error('Invalid theme');
}
}
/**
* a function for player earning points recorded into the user profile
* @param {Number} earnedpoints - takes in a number of gained points
* @returns {Number} Number - returns how much points is gained by the player
*/
earnpoints(earnedpoints) {
//implements points gaining function for themed cosmetics
//adding the points to the cumulative total in the user profile
//validation of earned points
if(typeof earnedpoints != 'number' || earnedpoints < 0){
throw new Error('Invalid points');
}
//adding earned points to available points
this.availablePoints += earnedpoints;
return this.availablePoints; //return amount of available points
}
/**
* a function for deducting the spent points from the user profile
* @param {Number} spendPoints - the amount of points that is going to be deducted from the user profile
* @return {void}
*/
spendPoints(spendPoints) {
//implementation of spending points for cosmetics
//validates if there is enough points in the user profile statistics
//rejects the transaction if there is not enought points
//validation of amount of points
if(this.availablePoints < spendPoints){
throw new Error('Not enough points');
}
//deduct points when cosmetic theme is bought by user
this.availablePoints -= spendPoints;
}
}