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 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 ("Unknown game: " + name); 24 } 25 } 26 | Popular Tags |