1 package net.sourceforge.simplegamenet.specs.model;
2
3 import net.sourceforge.simplegamenet.specs.to.GameSettings;
4 import net.sourceforge.simplegamenet.specs.to.Version;
5 import net.sourceforge.simplegamenet.specs.tools.MultiPlayerGameSettings;
6
7 /***
8 * An abstract superclass which represents the game. All the game module classes originate directly
9 * or indirectly from the subclass of this game interface. The subclass of this game interface
10 * should be set as the main class of the game package for the SimpleGameNet framework to find.
11 *
12 * @author Geoffrey De Smet
13 * @version 1.0, 2003-06-18
14 * @see net.sourceforge.simplegamenet.specs.model.GameServer
15 * @see net.sourceforge.simplegamenet.specs.model.GamePlayerClient
16 * @see net.sourceforge.simplegamenet.specs.to.GameSettings
17 */
18 abstract public class GameFactory implements Comparable {
19
20 private String name;
21 private Version version;
22 private String description;
23 private String author;
24
25 /***
26 * Creates a new game interface and sets required information about the game. Every subclass
27 * should call this constructor with <code>super</code>.
28 * <p/>
29 * The arguments are shown in the connection wizard and the "Status" tab.
30 *
31 * @param name The name of the game. This name can contain spaces but should resemble the
32 * jar file and package name.
33 * @param version The version of the game, which is used to assert that a server and its
34 * clients run the same game version.
35 * @param description the description of the game
36 * @param author the name of the author or group of authors who wrote the game
37 */
38 protected GameFactory(String name, Version version, String description,
39 String author) {
40 this.name = name;
41 this.version = version;
42 this.description = description;
43 this.author = author;
44 }
45
46 /***
47 * Creates a new game server.
48 *
49 * @param serverEngine the server engine to construct a new game server with
50 * @return a new game server
51 */
52 public abstract GameServer createGameServer(ServerEngine serverEngine);
53
54 /***
55 * Creates a new game player client.
56 *
57 * @param clientEngine the client engine to construct a new game player client with
58 * @return a new game player client
59 */
60 public abstract GamePlayerClient createGamePlayerClient(ClientEngine clientEngine);
61
62 /***
63 * Creates new game settings with default values. The SimpleGameNet framework uses these game
64 * settings to create the first game settings panel.
65 *
66 * @return new game settings
67 */
68 public GameSettings createDefaultGameSettings() {
69 return new MultiPlayerGameSettings();
70 }
71
72 /***
73 * Returns <code>true</code> if the game includes a bot. Currently bots are not yet supported by
74 * the SimpleGameNet framework. This method will be used in future versions of the SimpleGameNet
75 * framework.
76 *
77 * @return <code>true</code> if the game includes a bot
78 */
79 public boolean isBotProvided() {
80 return false;
81 }
82
83
84
85
86
87
88
89
90 /***
91 * Gets the name of the game.
92 *
93 * @return the name of the game
94 */
95 public String getName() {
96 return name;
97 }
98
99 /***
100 * Returns the name appended with the version string of the game.
101 *
102 * @return the name appended with the version string of the game
103 */
104 public String toString() {
105 return name + " v" + version.toString();
106 }
107
108 /***
109 * Gets the version of the game.
110 *
111 * @return the version of the game
112 */
113 public Version getVersion() {
114 return version;
115 }
116
117 /***
118 * Gets the description of the game.
119 *
120 * @return the description of the game
121 */
122 public String getDescription() {
123 return description;
124 }
125
126 /***
127 * Gets the author of the game.
128 *
129 * @return the author of the game
130 */
131 public String getAuthor() {
132 return author;
133 }
134
135 /***
136 * Returns the oldest version the SimpleGameNet framework can have to be able to run this game.
137 * If the game module requires functionality which is only provided by a newer SimpleGameNet
138 * framework, this method can prevent older SimpleGameNet frameworks not to run this game.
139 * <p/>
140 * If a subclass does not overwrite this method it always returns the oldest version of the
141 * SimpleGameNet framework.
142 *
143 * @return the oldest version the SimpleGameNet framework can have to be able to run this game
144 */
145 public Version getMinimumSimpleGameNetVersion() {
146 return new Version(0, 1, 0);
147 }
148
149 /***
150 * Compares this game interface to the specified object. The result is <code>true</code> if both
151 * game interfaces have the same name and author.
152 *
153 * @param o the o to compare this game interface against
154 * @return <code>true</code> if the game interfaces have the same name and author
155 */
156 public boolean equals(Object o) {
157 if (o == null || !(o instanceof GameFactory)) {
158 return false;
159 }
160 GameFactory gameFactory = (GameFactory) o;
161 return name.equals(gameFactory.name) && author.equals(gameFactory.author);
162 }
163
164 /***
165 * Compares two game interfaces lexicographically, primarily on name and secondarily on author.
166 *
167 * @param o the object to compare this game interface against
168 * @return the value <code>0</code> if the argument game interfaces name with author is equal to
169 * those of this game interface, a value less than <code>0</code> if this game
170 * interfaces name with author is lexicographically less than those of the argument and
171 * a value greater than <code>0</code> if this game interfaces name with author is
172 * lexicographically greater than those of the argument.
173 */
174 public int compareTo(Object o) {
175 if (o == null || !(o instanceof GameFactory)) {
176 return -1;
177 }
178 GameFactory gameFactory = (GameFactory) o;
179 int compareNames = name.compareTo(gameFactory.name);
180 if (compareNames != 0) {
181 return compareNames;
182 } else {
183 return author.compareTo(gameFactory.author);
184 }
185 }
186
187 }