-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscore.js
More file actions
42 lines (39 loc) · 894 Bytes
/
score.js
File metadata and controls
42 lines (39 loc) · 894 Bytes
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
function Score(){
this.userScore = 0;
this.cpuScore = 0;
this.rectSize = height*width/13000;
this.textSize = this.rectSize;
this.draw = function(){
this.drawUserScore();
this.drawCPUScore();
}
this.addPoint = function(player){
switch(player){
case(USER):
this.userScore += 1;
break;
case(CPU):
this.cpuScore += 1;
break;
}
resetGame();
}
this.drawUserScore = function(){
fill(255,255,255);
rectMode(CENTER);
rect(width*14/15, height/10, this.rectSize, this.rectSize);
textSize(this.textSize);
textAlign(CENTER, CENTER);
fill(0,0,0);
text(this.userScore, width*14/15, height/10);
}
this.drawCPUScore = function(){
fill(255,255,255);
rectMode(CENTER);
rect(width*1/15, height/10, this.rectSize, this.rectSize);
textSize(this.textSize);
textAlign(CENTER, CENTER);
fill(0,0,0);
text(this.cpuScore, width*1/15, height/10);
}
}