private bool playCard(CardControl cardControl) { Card cardToBePlayed = cardControl.GetCard(); if (cardToBePlayed.Type == CardType.draw4Wild || cardToBePlayed.Type == CardType.wild) { ColorPickerWindow colorPicker = new ColorPickerWindow(); colorPicker.Owner = this; colorPicker.ShowDialog(); Brush selectedColor = colorPicker.selectedColor; if (selectedColor.Equals(Brushes.Red)) { cardToBePlayed.Color = CardColor.Red; } else if (selectedColor.Equals(Brushes.Green)) { cardToBePlayed.Color = CardColor.Green; } else if (selectedColor.Equals(Brushes.Blue)) { cardToBePlayed.Color = CardColor.Blue; } else if (selectedColor.Equals(Brushes.Yellow)) { cardToBePlayed.Color = CardColor.Yellow; } } bool playSuccess = GameProxy.TryPlayCard(cardToBePlayed);//if special card, color chosen is saved in color attribute to be handled in the server if (playSuccess) { playedCard = true; CardPlayed(cardToBePlayed, username); player1Hand.RemoveCard(cardControl); if (player1Hand.getNrOfCards() == 0) //End game, we won! { EndOfTheGame(username); } } else { MessageBox.Show("Invalid move"); } return(playSuccess); }
private bool isValidCard(Card cardtoplay) { CardControl cardControl = lastPlayedCard.Content as CardControl; Card tableCard = cardControl.GetCard(); // Wild cards can be played on any color if (cardtoplay.Type == CardType.draw4Wild || cardtoplay.Type == CardType.wild) { return(true); } // Any matching color can be played, or matching numbers for normal cards else if (cardtoplay.Color == tableCard.Color || (cardtoplay.Type == CardType.normal && cardtoplay.Number == tableCard.Number)) { return(true); } // Any matching types can also be played else if (cardtoplay.Type == tableCard.Type && cardtoplay.Type != CardType.normal) { return(true); } return(false); }
// Call this locally when turn is finished to prevent deadlock private void endTurn() { int nextPlayerTurn = 0; if (playedCard) { CardControl cardControl = lastPlayedCard.Content as CardControl; if (cardControl != null) { var card = cardControl.GetCard(); if (card.Type == CardType.skip) // If we played a skip card, skip the next player { if (clockWiseGameDirection) { nextPlayerTurn = (nextPlayerTurn + 1) % playerHands.Count(); } else { nextPlayerTurn = (nextPlayerTurn - 1 + playerHands.Count) % playerHands.Count(); } } } } if (clockWiseGameDirection) { nextPlayerTurn = (nextPlayerTurn + 1) % playerHands.Count(); } else { nextPlayerTurn = (nextPlayerTurn - 1 + playerHands.Count) % playerHands.Count(); } TurnChanged(playerHands[nextPlayerTurn].Username); }