001: /*
002: * Copyright 2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package colors;
017:
018: import javax.servlet.http.*;
019:
020: public class ColorGameBean {
021:
022: private String background = "yellow";
023: private String foreground = "red";
024: private String color1 = foreground;
025: private String color2 = background;
026: private String hint = "no";
027: private int attempts = 0;
028: private int intval = 0;
029: private boolean tookHints = false;
030:
031: public void processRequest(HttpServletRequest request) {
032:
033: // background = "yellow";
034: // foreground = "red";
035:
036: if (!color1.equals(foreground)) {
037: if (color1.equalsIgnoreCase("black")
038: || color1.equalsIgnoreCase("cyan")) {
039: background = color1;
040: }
041: }
042:
043: if (!color2.equals(background)) {
044: if (color2.equalsIgnoreCase("black")
045: || color2.equalsIgnoreCase("cyan")) {
046: foreground = color2;
047: }
048: }
049:
050: attempts++;
051: }
052:
053: public void setColor2(String x) {
054: color2 = x;
055: }
056:
057: public void setColor1(String x) {
058: color1 = x;
059: }
060:
061: public void setAction(String x) {
062: if (!tookHints)
063: tookHints = x.equalsIgnoreCase("Hint");
064: hint = x;
065: }
066:
067: public String getColor2() {
068: return background;
069: }
070:
071: public String getColor1() {
072: return foreground;
073: }
074:
075: public int getAttempts() {
076: return attempts;
077: }
078:
079: public boolean getHint() {
080: return hint.equalsIgnoreCase("Hint");
081: }
082:
083: public boolean getSuccess() {
084: if (background.equalsIgnoreCase("black")
085: || background.equalsIgnoreCase("cyan")) {
086:
087: if (foreground.equalsIgnoreCase("black")
088: || foreground.equalsIgnoreCase("cyan"))
089: return true;
090: else
091: return false;
092: }
093:
094: return false;
095: }
096:
097: public boolean getHintTaken() {
098: return tookHints;
099: }
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: }
|