/// <summary> /// Sets the board visually for the start of the game /// </summary> /// <param name="currentGame">The ActiveGameState created in the MainWindow is passed in</param> private void SetBoard(ActiveGameState currentGame) { this.currentGame = currentGame; if (currentGame.PlayersList.Count == 3) { Grid_PlayerThreeScore.Visibility = Visibility.Visible; } if (currentGame.PlayersList.Count == 4) { Grid_PlayerThreeScore.Visibility = Visibility.Visible; Grid_PlayerFourScore.Visibility = Visibility.Visible; } foreach (var p in currentGame.PlayersList) { if (p.IsAi == true) { string name = "Lbl_Player" + p.PlayerName + "Score"; Label playerName = FindName(name) as Label; playerName.Content = "[AI]Player " + p.PlayerName; } } foreach (var p in currentGame.PlayersList) { p.UpdateScore(this.Grid_GameBoard); } this.CardLabelVisibility(); this.UpdateLabels(); this.CheckAiTurn(); }
/// <summary> /// Button Click end the game and return to the Main Menu /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The routed event</param> private void But_NewGame_Click(object sender, RoutedEventArgs e) { int numOfPlayers = 2; int numOfComputers = 0; int startingCards = 10; // Loop through each selection in in the Players ListBox foreach (var i in ListBox_NumOfPlayers.Items) { ListBoxItem currentItem = i as ListBoxItem; if (currentItem.IsSelected) { numOfPlayers = int.Parse(currentItem.Tag.ToString()); break; } } if (Cb_EnableComputer.IsChecked == true) { // Loop through each selection in in the Computers ListBox foreach (var i in ListBox_NumOfComputers.Items) { ListBoxItem currentItem = i as ListBoxItem; if (currentItem.IsSelected) { numOfComputers = int.Parse(currentItem.Tag.ToString()); break; } } } if (Cb_ShortGame.IsChecked == true) { startingCards = 6; } ActiveGameState currentGame = new ActiveGameState(numOfPlayers, numOfComputers, startingCards); GameBoard gameBoard = new GameBoard(currentGame); gameBoard.Show(); this.MainMenuWindow.Close(); }
/// <summary> /// Initializes a new instance of the <see cref="GameBoard"/> class. /// </summary> /// <param name="currentGame">The ActiveGameState created in the MainWindow is passed along</param> public GameBoard(ActiveGameState currentGame) { this.InitializeComponent(); this.SetBoard(currentGame); }