Last active
January 3, 2016 11:49
-
-
Save tarynsauer/8458301 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package tictactoe; | |
| import static tictactoe.TictactoeConstants.*; | |
| public class GameSettings { | |
| private UI ui; | |
| private int boardSize; | |
| private Player playerOne; | |
| private Player playerTwo; | |
| private Player playerFirstMove; | |
| public GameSettings() { | |
| } | |
| public void getAllSettings() { | |
| this.ui = new UI(); | |
| this.playerOne = returnPlayer(X_MARKER); | |
| this.playerTwo = returnPlayer(O_MARKER); | |
| this.playerFirstMove = randomizePlayerFirstMove(); | |
| returnBoardSize(); | |
| } | |
| public Player randomizePlayerFirstMove() { | |
| int rand = (Math.random() < 0.5) ? 0 : 1; | |
| if (rand == 0) { | |
| return this.playerOne; | |
| } else { | |
| return this.playerTwo; | |
| } | |
| } | |
| public Player generatePlayer(String type, String marker) { | |
| if (type.equals(HARD_COMPUTER)) { | |
| return new AIPlayer(marker); | |
| } else if (type.equals(EASY_COMPUTER)) { | |
| return new ComputerPlayer(marker); | |
| } else { | |
| return new HumanPlayer(marker); | |
| } | |
| } | |
| public Player returnPlayer(String marker) { | |
| ui.requestPlayerType(marker); | |
| String type = ui.returnPlayerType(); | |
| validatePlayerType(type, marker); | |
| if (type.equals(HUMAN_PLAYER)) | |
| return generatePlayer(type, marker); | |
| else { | |
| String level = getComputerDifficulty(marker); | |
| return generatePlayer(level, marker); | |
| } | |
| } | |
| public void validatePlayerType(String type, String marker) { | |
| if ((!type.equals(HUMAN_PLAYER) && (!type.equals(COMPUTER_PLAYER)))) { | |
| ui.badInputMessage(type); | |
| returnPlayer(marker); | |
| } | |
| } | |
| ... | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment