/// <summary> /// Creates a GameWindow containing the given game View control. /// </summary> public GameWindow(IWpfGameFactory factory, NumberOfPlayers players) { // Set the DynamicResource named GameView to the given control. var gameView = factory.CreateGameView(players); this.Resources.Add("GameView", gameView.ViewControl); this.Resources.Add("ViewModel", gameView.ViewModel); // Register an event handler for when the game is finished. gameView.ViewModel.GameFinished += ViewModel_GameFinished; InitializeComponent(); // Set up bindings manually -- there are ways to do this in XAML, but I want to demonstrate the C# equivalent. mAdvantageLabel.SetBinding(Label.ContentProperty, new Binding() { Path = new PropertyPath("BoardAdvantage"), Converter = factory.CreateBoardAdvantageConverter() } ); mPlayerLabel.SetBinding(Label.ContentProperty, new Binding() { Path = new PropertyPath("CurrentPlayer"), Converter = factory.CreateCurrentPlayerConverter() } ); }
/// <summary> /// Creates a GameWindow containing the given game View control. /// </summary> public GameWindow(IWpfGameFactory factory) { // Set the DynamicResource named GameView to the given control. var gameView = factory.CreateGameView(); this.Resources.Add("GameView", gameView.ViewControl); this.Resources.Add("ViewModel", gameView.ViewModel); InitializeComponent(); }
private void Button_Click(object sender, RoutedEventArgs e) { Button b = sender as Button; IWpfGameFactory gameType = b.DataContext as IWpfGameFactory; var gameWindow = new GameWindow(gameType, mHumanBtn.IsChecked.Value ? NumberOfPlayers.Two : NumberOfPlayers.One) { Title = gameType.GameName }; gameWindow.Closed += GameWindow_Closed; gameWindow.Show(); this.Hide(); }
private void Button_Click(object sender, RoutedEventArgs e) { Button b = sender as Button; // Retrieve the game type bound to the button IWpfGameFactory gameType = b.DataContext as IWpfGameFactory; // Construct a GameWindow to play the game. var gameWindow = new GameWindow(gameType) { Title = gameType.GameName }; // When the GameWindow closes, we want to show this window again. gameWindow.Closed += GameWindow_Closed; // Show the GameWindow, hide the Choice window. gameWindow.Show(); this.Hide(); }
public GameChoiceWindow() { InitializeComponent(); Type IWpfGameFactory = typeof(IWpfGameFactory); var files = Directory.GetFiles("games"); foreach (var f in Directory.GetFiles("games")) { Console.WriteLine(f); // Strip " games\ " folder name string file = f.Substring(6); // strips .dll ending file = file.Substring(0, file.Length - 4); // Load from assembly for strong named Assembly.Load($"{file}, Version=1.0.0.0, Culture=neutral, PublicKeyToken=68e71c13048d452a"); //// if file ends with dll // if (file.Substring(file.Length - 3) == "dll") { // Load file //Assembly.LoadFrom(f); } List <object> GamesList = new List <object>(); var boardTypes = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(a => a.GetTypes()) .Where(t => IWpfGameFactory.IsAssignableFrom(t) && t.IsClass); foreach (var val in boardTypes) { IWpfGameFactory v = (IWpfGameFactory)val.GetConstructor(Type.EmptyTypes).Invoke(null); GamesList.Add(v); } this.Resources["GameTypes"] = GamesList; }