| 1 | /* |
| 2 | * Copyright (c) 2005 The PseudoQ Project. |
| 3 | * |
| 4 | * This file is part of PseudoQ. |
| 5 | * |
| 6 | * PseudoQ is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU Lesser General Public License as published by |
| 8 | * the Free Software Foundation; either version 2.1 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * PseudoQ is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public License |
| 17 | * along with PseudoQ; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
| 21 | package net.sourceforge.pseudoq.generation; |
| 22 | |
| 23 | import net.sourceforge.pseudoq.model.PuzzleTypeEnum; |
| 24 | |
| 25 | /** |
| 26 | * Factory class for Generator instances. |
| 27 | * @author <a href="http://sourceforge.net/users/stevensa">Andrew Stevens</a> |
| 28 | */ |
| 29 | public class GeneratorFactory { |
| 30 | /** Prevent instantiation as all methods are static. */ |
| 31 | private GeneratorFactory() { |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Create a new Generator instance for the specified puzzle type. The |
| 36 | * actual implementation class returned will depend on the type. |
| 37 | * @param type The puzzle type. |
| 38 | * @param style Generation style enum value. |
| 39 | * @param difficulty Desired puzzle difficulty. |
| 40 | * @return An initialised generator, or null if the puzzle type is unknown |
| 41 | * to the factory. |
| 42 | */ |
| 43 | public static Generator newInstance(PuzzleTypeEnum type, |
| 44 | GenerationStyleEnum style, int difficulty) { |
| 45 | Generator generator = null; |
| 46 | |
| 47 | if (type == null) { |
| 48 | throw new IllegalArgumentException("No puzzle type supplied"); |
| 49 | } |
| 50 | |
| 51 | switch (type) { |
| 52 | case TINY: |
| 53 | generator = new TinyGenerator(new SequentialGridFiller()); |
| 54 | break; |
| 55 | case MINI: |
| 56 | generator = new MiniGenerator(new SequentialGridFiller()); |
| 57 | break; |
| 58 | case MINI_X: |
| 59 | generator = new MiniXGenerator(new SequentialGridFiller()); |
| 60 | break; |
| 61 | case SMALL_X: |
| 62 | generator = new SmallXGenerator(new SequentialGridFiller()); |
| 63 | break; |
| 64 | case STANDARD: |
| 65 | generator = new StandardGenerator(new SequentialGridFiller()); |
| 66 | break; |
| 67 | case SUPER: |
| 68 | generator = new SuperGenerator(new SequentialGridFiller()); |
| 69 | break; |
| 70 | case LARGE: |
| 71 | generator = new LargeGenerator(new SequentialGridFiller()); |
| 72 | break; |
| 73 | case STANDARD_SAMURAI: |
| 74 | generator = new SamuraiGenerator(new SamuraiGridFiller(new SequentialGridFiller())); |
| 75 | break; |
| 76 | default: |
| 77 | assert false : "Should have covered all possibilities"; |
| 78 | // return null |
| 79 | break; |
| 80 | } |
| 81 | |
| 82 | return generator; |
| 83 | } |
| 84 | |
| 85 | } |