static void Main(string[] args) { var ticTacToeBoard = new string[3, 3]; IPlayer player1; IPlayer player2; var gameEngine = new GameEngine(); var gameVisualizer = new GameVisualizer(); var gameManager = new GameManager(gameVisualizer, gameEngine); gameVisualizer.printInstructions(); // Loops until the player has chosen an option while (true) { Console.WriteLine("Choose playing mode - 2PLAYER or AI?"); var mode = Console.ReadLine().ToUpper(); if (mode.Equals("2PLAYER")) { player1 = new RealPlayer(); player2 = new RealPlayer(); break; } else if (mode.Equals("AI")) { player1 = new RealPlayer(); player2 = new AIPlayer(); break; } Console.WriteLine(); Console.WriteLine("That is not a valid option"); } gameManager.PlayGame(ticTacToeBoard, player1, player2); }
static void Main(string[] args) { string[,] TicTacToeBoard = new string[3, 3]; GameEngine gameEngine = new GameEngine(); GameVisualizer gameVisualizer = new GameVisualizer(); GameManager gameManager = new GameManager(gameVisualizer, gameEngine); gameManager.StartGame(TicTacToeBoard); }
static void Main(string[] args) { string[,] TicTacToeBoard = new string[3, 3]; // Use an interface to encourage polymorphism - ability of an object to take on many forms IPlayer player1; IPlayer player2; VictoryValidator gameEngine = new VictoryValidator(); GameVisualizer gameVisualizer = new GameVisualizer(); // Inject dependencies GameManager gameManager = new GameManager(gameVisualizer, gameEngine); //GameWindow gameWindow = new GameWindow(); //gameWindow.ShowDialog(); while (true) { Console.WriteLine("Choose playing mode - 2 Players or Computer(AI)?"); var mode = Console.ReadLine().ToUpper(); // Polymorphism - Two objects are of the same type, but they can be interchangable and defined by the user if (mode.Equals("2 PLAYERS")) { player1 = new RealPlayer(); player2 = new RealPlayer(); break; } else if (mode.Equals("AI")) { player1 = new RealPlayer(); player2 = new AIPlayer(); break; } } //Play game just plays game, not about who the players are, so its better to pass in the players to play the game. gameManager.PlayGame(TicTacToeBoard, player1, player2); }
[STAThread] //STA-Single Threaded Apartment, refers to the threading model used by the current main thread. static void Main(string[] args) { string[,] TicTacToeBoard = new string[3, 3]; // Use an interface to encourage polymorphism - ability of an object to take on many forms IPlayer player1; IPlayer player2; VictoryValidator gameEngine = new VictoryValidator(); GameVisualizer gameVisualizer = new GameVisualizer(); // Inject dependencies GameManager gameManager = new GameManager(gameVisualizer, gameEngine); //GameWindow gameWindow = new GameWindow(); //gameWindow.ShowDialog(); while (true) { Console.WriteLine("Choose playing mode - 2 Players or Computer(AI)?"); var mode = Console.ReadLine().ToUpper(); // Polymorphism - Two objects are of the same type, but they can be interchangable and defined by the user if (mode.Equals("2 PLAYERS")) { player1 = new RealPlayer(); player2 = new RealPlayer(); break; } else if (mode.Equals("AI")) { player1 = new RealPlayer(); player2 = new AIPlayer(); break; } } //Play game just plays game, not about who the players are, so its better to pass in the players to play the game. gameManager.PlayGame(TicTacToeBoard, player1, player2); }
// Inject our classes as "dependencies" in our constructors // Pass in class names in actual parameters (dependency injection) public GameManager(GameVisualizer argGameVisualizer, VictoryValidator argVictoryValidator) { _gameVisualizer = argGameVisualizer; _victoryValidator = argVictoryValidator; }
public GameManager(GameVisualizer gameVisualizer, GameEngine gameEngine) { _gameVisualizer = gameVisualizer; _gameEngine = gameEngine; }