Source Code Cross Referenced for ScoreGame.java in  » Wiki-Engine » fitnesse » eg » bowling » fixtures » 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 » Wiki Engine » fitnesse » eg.bowling.fixtures 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
002:        // Released under the terms of the GNU General Public License version 2 or later.
003:        package eg.bowling.fixtures;
004:
005:        import eg.bowling.*;
006:        import fitnesse.fixtures.TableFixture;
007:
008:        public class ScoreGame extends TableFixture {
009:            private Bowling game;
010:
011:            public static final int STRIKE = -1;
012:            public static final int SPARE = -2;
013:            public static final int BLANK = -3;
014:            public static final int ERROR = -4;
015:
016:            protected void doStaticTable(int rows) {
017:                game = new BowlingGame();
018:                doRolls();
019:                doScores();
020:            }
021:
022:            private void doRolls() {
023:                for (int roll = 0; roll < 21; roll++) {
024:                    int pins = parseRoll(roll);
025:                    if (pins == SPARE)
026:                        spare(roll);
027:                    else if (pins == STRIKE)
028:                        strike(roll);
029:                    else if (pins == BLANK)
030:                        blank(roll);
031:                    else if (pins == ERROR)
032:                        wrongRoll(roll);
033:                    else {
034:                        roll(pins);
035:                    }
036:                }
037:            }
038:
039:            private int parseRoll(int roll) {
040:                String rollText = getText(1, roll);
041:                if (rollText.equals("/"))
042:                    return SPARE;
043:                else if (rollText.equals("X"))
044:                    return STRIKE;
045:                else if (rollText.equals(""))
046:                    return BLANK;
047:                else {
048:                    try {
049:                        int pins = Integer.parseInt(rollText);
050:                        return pins;
051:                    } catch (NumberFormatException e) {
052:                        return ERROR;
053:                    }
054:                }
055:            }
056:
057:            private void spare(int rollNumber) {
058:                if (odd(rollNumber))
059:                    wrongRoll(rollNumber);
060:                else {
061:                    int previousRoll = parseRoll(rollNumber - 1);
062:                    if (previousRoll < 0)
063:                        wrongRoll(rollNumber);
064:                    else
065:                        roll(10 - previousRoll);
066:                }
067:            }
068:
069:            private void wrongRoll(int rollNumber) {
070:                wrong(1, rollNumber);
071:            }
072:
073:            private void strike(int rollNumber) {
074:                if (rollNumber == 18)
075:                    roll(10);
076:                else if (rollNumber == 19 && parseRoll(18) == STRIKE)
077:                    roll(10);
078:                else if (rollNumber == 20
079:                        && (parseRoll(19) == STRIKE || parseRoll(19) == SPARE))
080:                    roll(10);
081:                else if (odd(rollNumber))
082:                    wrongRoll(rollNumber);
083:                else {
084:                    int previousRoll = parseRoll(rollNumber - 1);
085:                    if (previousRoll != BLANK)
086:                        wrongRoll(rollNumber);
087:                    else
088:                        roll(10);
089:                }
090:            }
091:
092:            private boolean odd(int rollNumber) {
093:                return (rollNumber % 2) != 1;
094:            }
095:
096:            private void blank(int roll) {
097:                if (roll == 20 && parseRoll(19) != SPARE
098:                        && parseRoll(18) != STRIKE)
099:                    return;
100:                if (parseRoll(roll + 1) == STRIKE)
101:                    return;
102:                wrongRoll(roll);
103:            }
104:
105:            private void roll(int pins) {
106:                game.roll(pins);
107:            }
108:
109:            private void doScores() {
110:                for (int frame = 0; frame < 10; frame++) {
111:                    int expectedScore = getScore(frame);
112:                    int actualScore = game.score(frame + 1);
113:                    if (expectedScore == actualScore)
114:                        rightScore(frame);
115:                    else
116:                        wrongScore(frame, "" + actualScore);
117:                }
118:
119:            }
120:
121:            private void rightScore(int frame) {
122:                right(2, scoreIndex(frame));
123:            }
124:
125:            private void wrongScore(int frame, String actual) {
126:                wrong(2, scoreIndex(frame), actual);
127:            }
128:
129:            private int getScore(int frame) {
130:                return Integer.parseInt(getText(2, scoreIndex(frame)));
131:            }
132:
133:            private int scoreIndex(int frame) {
134:                return frame * 2 + 1;
135:            }
136:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.