-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuitarHero.java
36 lines (28 loc) · 1.01 KB
/
GuitarHero.java
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
import java.util.*;
public class GuitarHero
{
public static void main(String[] args) {
String keyboard = "q2we4r5ty7u8i9op-[=zxdcfvgbnjmk,.;/' ";
HashMap<Character, GuitarString> guitar = new HashMap<>();
for(int i = 0; i < keyboard.length(); i++)
{
guitar.put(keyboard.charAt(i), new GuitarString(440 * Math.pow(1.05956, i -24)));
}
while (true) {
double s = 0;
if (StdDraw.hasNextKeyTyped()) {
char key = StdDraw.nextKeyTyped();
if(guitar.containsKey(key))
guitar.get(key).pluck();
}
for(int i = 0; i < keyboard.length(); i++) {
s += guitar.get(keyboard.charAt(i)).sample();
}
StdAudio.play(s);
// advance the simulation of each guitar string by one step
for(int i = 0; i < keyboard.length(); i++) {
guitar.get(keyboard.charAt(i)).tic();
}
}
}
}