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 public void processRequest(HttpServletRequest request) {
32
33
34
35
36 if (! color1.equals(foreground)) {
37 if (color1.equalsIgnoreCase("black") ||
38 color1.equalsIgnoreCase("cyan")) {
39 background = color1;
40 }
41 }
42
43 if (! color2.equals(background)) {
44 if (color2.equalsIgnoreCase("black") ||
45 color2.equalsIgnoreCase("cyan")) {
46 foreground = color2;
47 }
48 }
49
50 attempts++;
51 }
52
53 public void setColor2(String x) {
54 color2 = x;
55 }
56
57 public void setColor1(String x) {
58 color1 = x;
59 }
60
61 public void setAction(String x) {
62 if (!tookHints)
63 tookHints = x.equalsIgnoreCase("Hint");
64 hint = x;
65 }
66
67 public String getColor2() {
68 return background;
69 }
70
71 public String getColor1() {
72 return foreground;
73 }
74
75 public int getAttempts() {
76 return attempts;
77 }
78
79 public boolean getHint() {
80 return hint.equalsIgnoreCase("Hint");
81 }
82
83 public boolean getSuccess() {
84 if (background.equalsIgnoreCase("black") ||
85 background.equalsIgnoreCase("cyan")) {
86
87 if (foreground.equalsIgnoreCase("black") ||
88 foreground.equalsIgnoreCase("cyan"))
89 return true;
90 else
91 return false;
92 }
93
94 return false;
95 }
96
97 public boolean getHintTaken() {
98 return tookHints;
99 }
100
101 public void reset() {
102 foreground = "red";
103 background = "yellow";
104 }
105
106 public void setIntval(int value) {
107 intval = value;
108 }
109
110 public int getIntval() {
111 return intval;
112 }
113 }
114