1 | /* |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
3 | * contributor license agreements. See the NOTICE file distributed with |
---|
4 | * this work for additional information regarding copyright ownership. |
---|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
6 | * (the "License"); you may not use this file except in compliance with |
---|
7 | * the License. You may obtain a copy of the License at |
---|
8 | * |
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
10 | * |
---|
11 | * Unless required by applicable law or agreed to in writing, software |
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | * See the License for the specific language governing permissions and |
---|
15 | * limitations under the License. |
---|
16 | */ |
---|
17 | package colors; |
---|
18 | |
---|
19 | import javax.servlet.http.*; |
---|
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 | // background = "yellow"; |
---|
35 | // foreground = "red"; |
---|
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 | |
---|