/// <summary> /// Constructor for TableVm /// </summary> public TableVM() { this.deck = new DeckVM(); this.players = new ObservableCollection <PersonVM>(); this.dealer = new PersonVM() { PlayerNumber = 0, PlayerName = "Dealer" }; this.numPlayers = 0; this.nextHandButton = Visibility.Hidden; this.playerNameTxtBoxes = Visibility.Hidden; this.numPlayersTxtBox = Visibility.Visible; this.playerCards = Visibility.Hidden; this.startGameButton = Visibility.Hidden; this.NextHandCommand = new CommandHelper() { CanExecuteDelegate = x => true, ExecuteDelegate = x => this.NextHandCmdExecuted() }; this.QuitGameCommand = new CommandHelper() { CanExecuteDelegate = x => true, ExecuteDelegate = x => this.QuitGameCmdExecuted() }; this.CreatePlayersCommand = new CommandHelper() { CanExecuteDelegate = x => true, ExecuteDelegate = x => this.CreatePlayersCmdExecuted() }; this.LayoutPlayersCommand = new CommandHelper() { CanExecuteDelegate = x => this.LayoutPlayersCanExecute(), ExecuteDelegate = x => this.LayoutPlayersCmdExecuted() }; this.StartGameCommand = new CommandHelper() { CanExecuteDelegate = x => true, ExecuteDelegate = x => this.StartGameCmdExecuted() }; this.StandCommand = new CommandHelper() { CanExecuteDelegate = x => StandCanExecute(x), ExecuteDelegate = x => this.StandCmdExecuted(x) }; this.HitCommand = new CommandHelper() { CanExecuteDelegate = x => this.HitCanExecute(x), ExecuteDelegate = x => this.HitCmdExecuted(x) }; }
/// <summary> /// Adds a card obtained from the deck to the players hand. /// </summary> /// <param name="deck"> The deck from which the card will be dealt</param> public void DealCard(DeckVM deck) { CardVM card = deck.AddCard(); card.CardOffset = new Thickness(((this.cardsInHand.Count - 1) * 5), (this.cardsInHand.Count - 1) * 7, (this.cardsInHand.Count - 1) * -45, 0); // Storyboard animation = new Storyboard(); card.CardTransform = new RotateTransform(this.cardsInHand.Count * 10, 0, 0); if (this.cardsInHand.Count < 1) { card.FaceUp = true; } else if (this.handIsVisible == true) { card.FaceUp = true; } else { card.FaceUp = false; } this.cardsInHand.Insert(0,card); if (this.cardsInHand.Count > 3) { for (int i = 0; i < this.cardsInHand.Count; i++) { cardsInHand[this.cardsInHand.Count - 1 - i].CardTransform = new RotateTransform((i - (this.cardsInHand.Count - 3)) * 10, 0, 0); } } if (this.CardsInHand.Count == 4) { for (int i = (this.cardsInHand.Count - 1); i > (this.cardsInHand.Count - 3); i--) { cardsInHand[i].CardOffset = new Thickness( ((((this.cardsInHand.Count - i) - 3) * -1) * -18), ((((this.cardsInHand.Count - i) - 1.5) * -1) * 23) * (this.cardsInHand.Count - i), (((this.cardsInHand.Count - i) - 1.5) * -18) * (this.cardsInHand.Count - i), (((this.cardsInHand.Count - i) - 1.25) * -18) * (this.cardsInHand.Count - i)); } } else if (this.cardsInHand.Count == 5) { for (int i = (this.cardsInHand.Count - 1); i > (this.cardsInHand.Count - 4); i--) { cardsInHand[i].CardOffset = new Thickness( (((this.cardsInHand.Count - i) - 4) * -1) * -20, (((this.cardsInHand.Count - i) - 4) * -1) * 7, ((this.cardsInHand.Count - i) - 1) * -33, ((this.cardsInHand.Count - i) - 1) * 0); } } else if (this.cardsInHand.Count == 6) { for (int i = (this.cardsInHand.Count - 1); i > (this.cardsInHand.Count - 5); i--) { cardsInHand[i].CardOffset = new Thickness( (Math.Abs((this.cardsInHand.Count - i) - 5)) * -20, (Math.Abs((this.cardsInHand.Count - i) - 5)) * 8, ((this.cardsInHand.Count - i) - 1) * -35, ((this.cardsInHand.Count - i) - 1) * 0); } } this.CurrentScore(); }