Back to project page Do-not-get-annoyed.
The source code is released under:
Apache License
If you think the Android project Do-not-get-annoyed listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package mn100013d.pmu.services; /*from w w w. j a va 2 s . co m*/ import java.util.ArrayList; import mn100013d.pmu.controllers.GameController; import mn100013d.pmu.models.Board; import mn100013d.pmu.models.CPUGamePlayer; import mn100013d.pmu.models.Color; import mn100013d.pmu.models.GamePlayer; import mn100013d.pmu.models.HumanGamePlayer; import android.util.Log; public class GamePlayerFactory { public static final String DEBUG = "mn100013d.pmu.services.DEBUG"; private static final ArrayList<String> REGULAR_OPTIONS = new ArrayList<String>(); private ShakeDetector shakeDetector; private Randomizer randomizer; private int firstPlayerIndex = 0; private Boolean FIRST_PLAYER_INDEX_VALUE_AVAILABLE = false; static { REGULAR_OPTIONS.add("CPU"); REGULAR_OPTIONS.add("HUMAN"); REGULAR_OPTIONS.add("OFF"); } public GamePlayerFactory(ShakeDetector shakeDetector, Randomizer randomizer) { this.randomizer = randomizer; this.shakeDetector = shakeDetector; Log.i(DEBUG, "GamePlayerFactory has been created"); } private GamePlayer create(String name, String option, int color, Board board, GameController gController) { if (option.equalsIgnoreCase("CPU")) { Log.i(DEBUG, "CPUGamePlayer created"); return new CPUGamePlayer(name, color, board, gController, randomizer); } if (option.equalsIgnoreCase("HUMAN")) { Log.i(DEBUG, "HumanGamePlayer created"); return new HumanGamePlayer(name, color, board, gController, shakeDetector); } return null; } public Boolean firstPlayerIndexValueIsAvailable() { return FIRST_PLAYER_INDEX_VALUE_AVAILABLE; } public int getFirstPlayerIndex() { if (FIRST_PLAYER_INDEX_VALUE_AVAILABLE) return firstPlayerIndex; Log.wtf(DEBUG, "First Player Index is not available! Please use firstPlayerIndexValueIsAvailable" + " to determin if value is available. Return value is -1"); return -1; } public GamePlayer[] create(String[] names, String[] options, Board board, GameController gController) { GamePlayer[] players = new GamePlayer[4]; Log.i(DEBUG, "Create metod called"); if (options.length != 4) { Log.w(DEBUG, "String[] options length must be 4"); return null; } int[] colors = { Color.RED, Color.BLUE, Color.GREEN, Color.YELLOW }; for (int i = 0; i < 4; i++) { if (!REGULAR_OPTIONS.contains(options[i])) { Log.w(DEBUG, "option must be one of the values CPU, " + "HUMAN, OFF, invalid value on the index of " + i); return null; } players[i] = create(names[i], options[i], colors[i], board, gController); if (players[i] != null){ if (!FIRST_PLAYER_INDEX_VALUE_AVAILABLE) { firstPlayerIndex = i; FIRST_PLAYER_INDEX_VALUE_AVAILABLE = true; } } } return players; } }