KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > innig > macker > example > modularity > game > GameFactory


1 package net.innig.macker.example.modularity.game;
2
3 import net.innig.macker.example.modularity.game.impl.*;
4 import java.util.*;
5
6 public class GameFactory
7     {
8     public static Set getGameNames()
9         {
10         Set games = new TreeSet();
11         games.add("(R)ochambeau");
12         games.add("(P)risoner's Dilemma");
13         return Collections.unmodifiableSet(games);
14         }
15     
16     public static Game createGame(String JavaDoc name)
17         {
18         name = name.trim().toLowerCase();
19         if("rochambeau".startsWith(name))
20             return new RochambeauGame();
21         if("prisoner's dilemma".startsWith(name))
22             return new PrisonersDilemmaGame();
23         throw new IllegalArgumentException JavaDoc("Unknown game: " + name);
24         }
25     }
26
Popular Tags