// This method is to tell the dealer draw a card to the current player. private void btnHit_Click(object sender, RoutedEventArgs e) { Card card = shoe.Deal(); if (CalculatePoints() > 21) { MessageBox.Show("You Bust! Point is: " + CalculatePoints()); // Update the current player info myLstCards.Items.Insert(0, card); btnHit.IsEnabled = btnStand.IsEnabled = false; UpdateCurrentPlayerInfo(CalculatePoints()); // Call the stand method to invoke next player, because the current player Bust. shoe.Stand(); } else { // Update the current player info and shoe cards count myLstCards.Items.Insert(0, card); UpdateCurrentPlayerInfo(CalculatePoints()); } }
// ******************* Helper methods ********************** private void connectToCardTable() { try { // Connect to the Shoe service using DUPLEX channel (for callbacks) DuplexChannelFactory <IShoe> channel = new DuplexChannelFactory <IShoe>(this, "ShoeEndPoint"); shoe = channel.CreateChannel(); if (shoe.Join(txtAlias.Text)) { // Deal two cards to each player and the dealer in the first round for (int i = 0; i < 2; i++) { Card card = shoe.Deal(); // Update the current player info myLstCards.Items.Insert(0, card); } UpdateCurrentPlayerInfo(CalculatePoints()); txtAlias.IsEnabled = btnSet.IsEnabled = false; } else { // Alias rejected by the service so nullify service proxies shoe = null; txtAlias.IsEnabled = btnSet.IsEnabled = true; MessageBox.Show("ERROR: Alias in use. Please try again."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }