-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreen.js
More file actions
117 lines (90 loc) · 2.87 KB
/
screen.js
File metadata and controls
117 lines (90 loc) · 2.87 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
function drawStartScreen(){
if(partyIsHost()) {
push()
textSize(30);
text('Take control of your city, Sherif!', width / 2, height / 2);
text('Press ENTER to defend it.', width / 2, height / 2 + 30);
pop()
} else if(my.role !== "observer") {
push()
textSize(20);
text('The Sherif looking for a bandit like you...', width / 2, height / 2);
text('Get ready to show who should control this town', width / 2, height / 2 + 30);
pop()
} else {
push()
textSize(20);
text('The room is already full', width / 2, height / 2);
text('Please wait for the next round', width / 2, height / 2 + 30);
pop()
}
}
function drawEndScreen(){
//display win/lose result
if(partyIsHost()){
whoIsWinner();
}
if (my.role == "player1" && my.isWin == true) image(ASSETS_MANAGER.get("win_red"), 0, 0);
else if (my.role == "player1" && my.isWin == false) image(ASSETS_MANAGER.get("win_blue"), 0, 0);
else if (my.role == "player1" && my.isWin == "even") image(ASSETS_MANAGER.get("draw_end"), 0, 0); //use even score img instead
if (my.role == "player2" && my.isWin == false) image(ASSETS_MANAGER.get("win_red"), 0, 0);
else if (my.role == "player2" && my.isWin == true) image(ASSETS_MANAGER.get("win_blue"), 0, 0);
else if (my.role == "player2" && my.isWin == "even") image(ASSETS_MANAGER.get("draw_end"), 0, 0); //use even score img instead
//instructions to restart the game
if(partyIsHost()){
push()
fill(0)
textSize(20);
textAlign(CENTER);
text('Press ENTER to Restart', width / 2, height - 200);
pop()
// console.log("LMK When it kits !shared with party host - game end")
}
}
function drawInBetweenScreen(){
if (partyIsHost()){
whoIsRoundWinner();
}
//display result of last round
let result = my.receiveScore ? 'You got it!' : 'Try again!';
push()
fill(0)
textSize(30);
textAlign(CENTER);
text(`${result}`, width / 2, height / 2 - 100);
textSize(20);
text(`your score: ${my.score}`, width / 2, height / 2 - 50);
text(`${timer.inbetweenCountdown}`, width / 2, height / 2);
pop()
//instructions to restart the game
}
function whoIsWinner() { // make the player who has the highest score become winner
let highscore = 0;
let isFirstWinner = true;
let even = false;
//determine winning score
for(let p of participants) {
if(p.score > highscore) highscore = p.score;
}
//assgin winner
for(let p of participants) {
if (p.score == highscore){
if (isFirstWinner){
p.isWin = true;
isFirstWinner = false;
} else {
even = true;
}
}
}
if (even){
for(let p of participants) {
p.isWin = "even"
}
}
}
function whoIsRoundWinner(){
for(let p of participants) {
p.receiveScore = ifHasBadge(p) ? true : false; //check if has score this round
}
}