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