/// <summary> /// Show a name inquiry dialog and perform necessary initialization before starting. The starting game type is selected based on "currentGameType". /// </summary> private void Window_Loaded(object sender, RoutedEventArgs e) { boardSizes = new List<int>(2); boardSizes.Add(8); boardSizes.Add(16); _board.Size = boardSizes[0]; StartDialog dialog = new StartDialog(); dialog.ShowDialog(); if (dialog.PlayerNames[0].Trim() != "") { player1 = dialog.PlayerNames[0]; } if (dialog.PlayerNames[1].Trim() != "") { player2 = dialog.PlayerNames[1]; } game = new BoardGame(_board); IGameLogic gameLogic; switch (currentGameType) { case GameType.breakthrough: gameLogic = new BreakthroughLogic(); break; default: gameLogic = new CheckersLogic(); break; } game.Logic = gameLogic; game.GameOver += new EventHandler(GameOverHandler); game.TurnOver += new EventHandler(TurnChangedHandler); SetupGameStyles(); DrawGameStarter(); game.Start(); }
void GameTypeChangedHandler(Object sender, EventArgs e) { var args = (GameTypeEventArgs)e; GameType gameType = args.GameType; currentGameType = gameType; IGameLogic gameLogic; switch (gameType) { case GameType.breakthrough: gameLogic = new BreakthroughLogic(); break; default: gameLogic = new CheckersLogic(); break; } game.Logic = gameLogic; game.Start(); }