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