final
[des2015.git] / mart / ev3 / ex2 / nl / ru / des / bluetooth / ColorMemory.java
1 package nl.ru.des.bluetooth;
2
3 import java.util.Arrays;
4 import java.util.HashSet;
5 import java.util.List;
6 import java.util.Set;
7
8 import lejos.hardware.Sound;
9 import lejos.robotics.Color;
10 import nl.ru.des.LCDPrinter;
11
12 public class ColorMemory implements MessageHandler {
13 public static final List<Integer> COLORSTOFIND = Arrays.asList(new Integer[] {Color.BLUE, Color.RED, Color.YELLOW});
14 private Set<Integer> colors;
15
16 public ColorMemory() {
17 colors = new HashSet<Integer>();
18 }
19
20 @Override
21 public void handleMessage(String message) {
22 int color = Integer.valueOf(message);
23 if(!colors.contains(color)){
24 colors.add(Integer.valueOf(message));
25 Sound.beep();
26 LCDPrinter.print(colors.toString());
27 }
28 }
29
30 public boolean finished() {
31 return colors.containsAll(COLORSTOFIND);
32 }
33
34 public void addColor(int current) {
35 if(!colors.contains(current)){
36 colors.add(current);
37 Sound.buzz();
38 LCDPrinter.print(colors.toString());
39 BTController.sendMessage(Integer.toString(current));
40 }
41 }
42 }