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