/// <summary> /// Constructor for the MonopolyWindowViewModel. /// The game board used must be passed as a parameter. /// </summary> /// <param name="savefile">The savefile to be used if selected.</param> /// <param name="boardDirectory">Directory of the game board to be used.</param> /// <param name="players">List of the players in the game.</param> /// <param name="settings">Dictionary of the settings to be used.</param> public MonopolyWindowViewModel(IDialogCoordinator instance, MonopolyHandler savefile, string boardDirectory = null, List <Player> players = null, Dictionary <string, object> settings = null) { Dialogs = instance; // Set the DialogCoordinator to the one define in App.xaml.cs // If a savefile exists, load the savefile. var alreadyStarted = false; if (savefile != null) { // Load the boardgame and get underway. alreadyStarted = true; Handler = savefile; Handler.ViewModel = this; } else { // This is a new game, hurray! // The new handler... Handler = new MonopolyHandler(this, settings); // ...must load the selected board. Handler.BoardConfiguration = DeserialisePathIntoGameboard(boardDirectory); // Then, the deseralised BoardConfiguration must be formatted for view. This must be set to equal the Board in the view. Handler.Board = Handler.BoardConfiguration.FormatForView(); // It's time to establish the players. foreach (Player player in players) { Handler.InitPlayer(player); } // Before we start, we must also load and deseralise the chance and community chest cards. // As these are stored in the game resources and made by the programmer, we can assume they do not need error checking. Handler.ChanceCards = JsonConvert.DeserializeObject <Queue <Card> >(File.ReadAllText(Environment.CurrentDirectory + @"\Resources\ChanceCards.json")); Handler.CommunityChestCards = JsonConvert.DeserializeObject <Queue <Card> >(File.ReadAllText(Environment.CurrentDirectory + @"\Resources\CommunityChestCards.json")); } // Establish visual configuration - board scale, rotations, etc. // We zoom in by 1.05x to allow for movement correlating with the most position. BoardScale = 1.05; RotateButtonRotation = 360; // The board is now ready to go, and the game can begin. Handler.Start(alreadyStarted); }