1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package colors;
18
19 import javax.servlet.http.HttpServletRequest;
20
21 public class ColorGameBean {
22
23 private String background = "yellow";
24 private String foreground = "red";
25 private String color1 = foreground;
26 private String color2 = background;
27 private String hint = "no";
28 private int attempts = 0;
29 private int intval = 0;
30 private boolean tookHints = false;
31
32 public void processRequest(HttpServletRequest request) {
33
34
35
36
37 if (!color1.equals(foreground)) {
38 if (color1.equalsIgnoreCase("black") ||
39 color1.equalsIgnoreCase("cyan")) {
40 background = color1;
41 }
42 }
43
44 if (!color2.equals(background)) {
45 if (color2.equalsIgnoreCase("black") ||
46 color2.equalsIgnoreCase("cyan")) {
47 foreground = color2;
48 }
49 }
50
51 attempts++;
52 }
53
54 public void setColor2(String x) {
55 color2 = x;
56 }
57
58 public void setColor1(String x) {
59 color1 = x;
60 }
61
62 public void setAction(String x) {
63 if (!tookHints)
64 tookHints = x.equalsIgnoreCase("Hint");
65 hint = x;
66 }
67
68 public String getColor2() {
69 return background;
70 }
71
72 public String getColor1() {
73 return foreground;
74 }
75
76 public int getAttempts() {
77 return attempts;
78 }
79
80 public boolean getHint() {
81 return hint.equalsIgnoreCase("Hint");
82 }
83
84 public boolean getSuccess() {
85 if (background.equalsIgnoreCase("black") ||
86 background.equalsIgnoreCase("cyan")) {
87
88 if (foreground.equalsIgnoreCase("black") ||
89 foreground.equalsIgnoreCase("cyan"))
90 return true;
91 else
92 return false;
93 }
94
95 return false;
96 }
97
98 public boolean getHintTaken() {
99 return tookHints;
100 }
101
102 public void reset() {
103 foreground = "red";
104 background = "yellow";
105 }
106
107 public void setIntval(int value) {
108 intval = value;
109 }
110
111 public int getIntval() {
112 return intval;
113 }
114 }
115