Source Code Cross Referenced for Game.java in  » Web-Framework » rife-1.6.1 » model » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » rife 1.6.1 » model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: Game.java 3364 2006-07-10 10:33:29Z gbevin $ $Revision: 3364 $
003:         * $Date: 2006-04-16 15:36:52 +0200 (Sun, 16 Apr 2006) $
004:         *
005:         * ==================================================================== Licensed
006:         * under the Apache License, Version 2.0 (the "License"); you may not use this
007:         * file except in compliance with the License. You may obtain a copy of the
008:         * License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
014:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
015:         * License for the specific language governing permissions and limitations under
016:         * the License.
017:         */
018:        package model;
019:
020:        import java.io.Serializable;
021:        import java.util.ArrayList;
022:        import java.util.List;
023:
024:        /**
025:         * Implementation of the actual hangman game model. The model holds the word
026:         * generator, the current word, retries remaining and the correctLetters that
027:         * have been guessed. It also answers questions such as whether all retries have
028:         * been used.
029:         *
030:         * @author Chris Turner
031:         * @author Jonathan Locke
032:         * @author Geert Bevin
033:         */
034:        public class Game implements  Serializable {
035:            /** Number of guesses allowed */
036:            private int guessesAllowed;
037:
038:            /** Number of guesses remaining */
039:            private int guessesRemaining;
040:
041:            /** The letters */
042:            private final List<Letter> letters = new ArrayList<Letter>();
043:
044:            /** The word being guessed by the user */
045:            private Word word;
046:
047:            /** Word generator */
048:            private WordGenerator wordGenerator;
049:
050:            /**
051:             * Return the number of guesses remaining.
052:             *
053:             * @return The number of guesses
054:             */
055:            public int getGuessesRemaining() {
056:                return guessesRemaining;
057:            }
058:
059:            /**
060:             * @return The letters in the game
061:             */
062:            public List<Letter> getLetters() {
063:                return letters;
064:            }
065:
066:            /**
067:             * Get the current word that is being guessed or has been guessed.
068:             *
069:             * @return The current word
070:             */
071:            public Word getWord() {
072:                return word;
073:            }
074:
075:            /**
076:             * Guess the given letter for the current word. If the letter matches then
077:             * the word is updated otherwise the guesses remaining counter is reduced.
078:             * The letter guessed is also recorded.
079:             *
080:             * @param letter
081:             *            The letter being guessed
082:             * @return True if guess was correct
083:             */
084:            public boolean guess(final Letter letter) {
085:                if (!letter.isGuessed()) {
086:                    final boolean correct = word.guess(letter);
087:                    if (!correct) {
088:                        guessesRemaining--;
089:                    }
090:                    return correct;
091:                }
092:                return false;
093:            }
094:
095:            /**
096:             * Check whether the user has used up all of their guesses.
097:             *
098:             * @return Whether all of the user's guesses have been used
099:             */
100:            public boolean isLost() {
101:                return guessesRemaining == 0;
102:            }
103:
104:            /**
105:             * Check whether the user has successfully guessed all of the correctLetters
106:             * in the word.
107:             *
108:             * @return Whether all of the correctLetters have been guessed or not
109:             */
110:            public boolean isWon() {
111:                return word.isGuessed();
112:            }
113:
114:            /**
115:             * Play another game with same settings
116:             */
117:            public void newGame() {
118:                newGame(guessesAllowed, wordGenerator);
119:            }
120:
121:            /**
122:             * Initialise the hangman read for a new game.
123:             *
124:             * @param guessesAllowed
125:             *            Number of guesses allowed
126:             * @param wordGenerator
127:             *            The word generator
128:             */
129:            public void newGame(final int guessesAllowed,
130:                    final WordGenerator wordGenerator) {
131:                this .guessesAllowed = guessesAllowed;
132:                this .guessesRemaining = guessesAllowed;
133:                this .word = wordGenerator.next();
134:                this .wordGenerator = wordGenerator;
135:
136:                // Add letters
137:                letters.clear();
138:                for (char c = 'a'; c <= 'z'; c++) {
139:                    letters.add(new Letter(c));
140:                }
141:            }
142:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.