-
Notifications
You must be signed in to change notification settings - Fork 1
/
Quiz.pde
81 lines (66 loc) · 2.15 KB
/
Quiz.pde
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
class Quiz{
Quiz(PVector _pos, PVector _size){
size = _size;
pos = _pos;
}
void draw(){
for (int i = 0; i < categories.size(); i++){
categories.get(i).draw();
}
}
void keyPress(char key){
if (key == 'q'){
TC.findWinningTeam();
state = Jeopardy.JeopardyState.WINNING_SCREEN;
}
}
void keyPressed(){
if (key == 'q'){
TC.findWinningTeam();
state = Jeopardy.JeopardyState.WINNING_SCREEN;
}
}
void click(PVector click, boolean left){
// Check that click was within Quiz window
if(mouseX > pos.x && mouseX < pos.x + size.x && mouseY > pos.y && mouseY < pos.y + size.y){
// Find which category was clicked
int t = (int)Math.floor(mouseX / (size.x / categories.size()));
// Call click function on clicked category
currentlyPlaying = categories.get(t).click();
}
}
public int getPoints(color _c, boolean correct){
if (currentlyPlaying == null) return 0;
if (currentlyPlaying.state != 3) return 0;
if (correct){
currentlyPlaying.setWinningColor(_c);
}
return int(currentlyPlaying.value);
}
public void setSize(PVector _size){
size = _size;
for (int i = 0; i < categories.size(); i++){
categories.get(i).setSize(new PVector(size.x / categories.size(), size.y));
}
}
void load(String path){
String[] categoryNames = listFileNames(sketchPath() + "/data/" + path);
for (int i = 0; i < categoryNames.length; i++){
categories.add(new Category( new PVector(size.x / categoryNames.length * i, pos.y), new PVector(size.x / categoryNames.length, size.y), categoryNames[i]));
}
}
private String[] listFileNames(String dir){
File file = new File(dir);
if (file.isDirectory()) {
String names[] = file.list();
return names;
} else {
error.setError("No directory found named " + dir);
return new String[0];
}
}
List<Category> categories = new ArrayList <Category>();
PVector size = new PVector(0,0);
PVector pos = new PVector(0,0);
Button currentlyPlaying;
};