/Users/lyon/j4p/src/net/server/colors/ColorGameBean.java

1    /* 
2     * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved. 
3     * 
4     * This software is the confidential and proprietary information of Sun 
5     * Microsystems, Inc. ("Confidential Information").  You shall not 
6     * disclose such Confidential Information and shall use it only in 
7     * accordance with the terms of the license agreement you entered into 
8     * with Sun. 
9     * 
10    * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE 
11    * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 
12    * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
13    * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES 
14    * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING 
15    * THIS SOFTWARE OR ITS DERIVATIVES. 
16    * 
17    * CopyrightVersion 1.0 
18    */ 
19    
20   package net.server.colors; 
21    
22   import javax.servlet.http.HttpServletRequest; 
23    
24   public class ColorGameBean { 
25    
26       private String background = "yellow"; 
27       private String foreground = "red"; 
28       private String color1 = foreground; 
29       private String color2 = background; 
30       private String hint = "no"; 
31       private int attempts = 0; 
32       private int intval = 0; 
33       private boolean tookHints = false; 
34    
35       public void processRequest(HttpServletRequest request) { 
36    
37           // background = "yellow"; 
38           // foreground = "red"; 
39    
40           if (!color1.equals(foreground)) { 
41               if (color1.equalsIgnoreCase("black") || 
42                       color1.equalsIgnoreCase("cyan")) { 
43                   background = color1; 
44               } 
45           } 
46    
47           if (!color2.equals(background)) { 
48               if (color2.equalsIgnoreCase("black") || 
49                       color2.equalsIgnoreCase("cyan")) { 
50                   foreground = color2; 
51               } 
52           } 
53    
54           attempts++; 
55       } 
56    
57       public void setColor2(String x) { 
58           color2 = x; 
59       } 
60    
61       public void setColor1(String x) { 
62           color1 = x; 
63       } 
64    
65       public void setAction(String x) { 
66           if (!tookHints) 
67               tookHints = x.equalsIgnoreCase("Hint"); 
68           hint = x; 
69       } 
70    
71       public String getColor2() { 
72           return background; 
73       } 
74    
75       public String getColor1() { 
76           return foreground; 
77       } 
78    
79       public int getAttempts() { 
80           return attempts; 
81       } 
82    
83       public boolean getHint() { 
84           return hint.equalsIgnoreCase("Hint"); 
85       } 
86    
87       public boolean getSuccess() { 
88           if (background.equalsIgnoreCase("black") || 
89                   background.equalsIgnoreCase("cyan")) { 
90    
91               if (foreground.equalsIgnoreCase("black") || 
92                       foreground.equalsIgnoreCase("cyan")) 
93                   return true; 
94               else 
95                   return false; 
96           } 
97    
98           return false; 
99       } 
100   
101      public boolean getHintTaken() { 
102          return tookHints; 
103      } 
104   
105      public void reset() { 
106          foreground = "red"; 
107          background = "yellow"; 
108      } 
109   
110      public void setIntval(int value) { 
111          intval = value; 
112      } 
113   
114      public int getIntval() { 
115          return intval; 
116      } 
117  } 
118   
119