View Javadoc

1   /*
2   * Copyright 2004 The Apache Software Foundation
3   *
4   * Licensed under the Apache License, Version 2.0 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   *
8   *     http://www.apache.org/licenses/LICENSE-2.0
9   *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
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  	// background = "yellow";
34  	// foreground = "red";
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