Created
March 23, 2015 21:23
-
-
Save pumpkincouture/6204e9ae59c7bb0a9035 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
| public class SetUpTicTacToeGame { | |
| private List<Integer> userChoices; | |
| private Board board; | |
| private GameParticipants player1; | |
| private GameParticipants player2; | |
| private PrintStream output; | |
| private Scanner input; | |
| private UserInterface ui; | |
| private BoardRulesInterface boardRules; | |
| private Game game; | |
| public SetUpTicTacToeGame(List<Integer> userChoices) { | |
| this.userChoices = userChoices; | |
| } | |
| public void setUpGame() { | |
| setUpCommandLine(); | |
| setUpBoard(); | |
| setUpRules(); | |
| setUpPlayers(); | |
| setUpOrder(); | |
| getGame(); | |
| } | |
| public void setUpCommandLine() { | |
| output = new PrintStream(System.out); | |
| input = new Scanner(System.in); | |
| ui = new CommandLineInterface(output, input); | |
| } | |
| public void setUpBoard() { | |
| board = new Board(userChoices.get(0)); | |
| } | |
| public Board getBoard() { | |
| return board; | |
| } | |
| public void setUpRules() { | |
| switch(userChoices.get(0)) { | |
| case 3: | |
| boardRules = new BoardRules(board); | |
| break; | |
| case 4: | |
| boardRules = new BoardRules(board); | |
| } | |
| } | |
| public BoardRulesInterface getBoardRules() { | |
| return boardRules; | |
| } | |
| public void setUpPlayers() { | |
| switch(userChoices.get(1)) { | |
| case 1: | |
| player1 = new Human("X", (CommandLineInterface) ui); | |
| player2 = new Human("O", (CommandLineInterface) ui); | |
| break; | |
| case 2: | |
| player1 = new Human("X", (CommandLineInterface) ui); | |
| player2 = new SimpleAI("O", board); | |
| break; | |
| case 3: | |
| player1 = new Human("X", (CommandLineInterface) ui); | |
| player2 = new HardAI("O", boardRules, board); | |
| break; | |
| case 4: | |
| player1 = new SimpleAI("O", board); | |
| player2 = new HardAI("X", boardRules, board); | |
| break; | |
| } | |
| } | |
| public void setUpOrder() { | |
| GameParticipants switchedPlayer = player1; | |
| switch(userChoices.get(2)) { | |
| case 2: | |
| player1 = player2; | |
| player2 = switchedPlayer; | |
| break; | |
| } | |
| } | |
| public GameParticipants getPlayerOne() { | |
| return player1; | |
| } | |
| public GameParticipants getPlayerTwo() { | |
| return player2; | |
| } | |
| public void getGame() { | |
| game = new Game(player1, player2, board, ui, boardRules); | |
| game.start(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment