/******************************************************************************************************************************************************** ******** Function: Deck default constructor ******** Description: assigns properties to deck array consisting of 52 Card objects ******** Parameters: none ******** Pre-Conditions: Card array must be initialized ******** Post-Conditions: each Card object in the array now has its own unique properties ********************************************************************************************************************************************************/ public Deck() { for (int i = 0; i < 52; i++) { deckArr[i] = new Card(); } int index = 0; //double for loop, outer assigns suits and inner assigns the type of the card for (CardSuits suit = CardSuits.hearts; suit <= CardSuits.clubs; suit++) { for (CardTypes type = CardTypes.ace; type <= CardTypes.king; type++) { deckArr[index].setName(type); deckArr[index].setValue((int)type); //for the purpose of blackjack all face cards have a value of 10 if ((int)type > 10) { deckArr[index].setValue(10); } index++; } } }
//control demanding options private bool CheckDemandPossibilities(CardRanks rank, CardSuits suit, int playerNumber) { CardsDemandingHandler Handler = new CardsDemandingHandler(); return(Handler.CheckDemandPossibilities(rank, suit, playerNumber, ref demandedRank, ref demandedSuit, ref status, ref PlayersCurrentData)); }
public Card(string card) { card = card.Trim(); card = card.Replace(" ", string.Empty); if (card.Length != 2) { var msg = "The string representation of a card must be exactly two characters"; throw new ArgumentException(msg); } var r = card.First(); var rank = char.IsDigit(r) ? "_" + r : r.ToString(); CardRanks cardRank; if (!Enum.TryParse(rank, out cardRank)) { var msg = "Enum 'CardRanks' does not contain value: " + r; throw new ArgumentException(msg); } Rank = cardRank; var s = card.Last(); CardSuits cardSuit; if (!Enum.TryParse(s.ToString(), true, out cardSuit)) { var msg = "Enum 'CardSuits' does not contain value: " + s; throw new ArgumentException(msg); } Suit = cardSuit; _isRoyal = null; }
private int GetPower() { CardRanks rank = (CardRanks)Enum.Parse(typeof(CardRanks), this.Rank); CardSuits suit = (CardSuits)Enum.Parse(typeof(CardSuits), this.Suit); return((int)rank + (int)suit); }
//control demanding options public bool CheckDemandPossibilities(CardRanks newDemRank, CardSuits newDemSuit, int playerNumber, ref CardRanks demandedRank, ref CardSuits demandedSuit, ref GameStatus status, ref Dictionary <int, SinglePlayerData> PlayersCurrentData) { var logger = NLog.LogManager.GetCurrentClassLogger(); string demandingType = ""; if (Engine.ExtendedLogging) { logger.Info($"+++++++++++++++++++++++++++++++++++++++++++++++++++++++"); logger.Info($"+++++++++++++++++++++++++++++++++++++++++++++++++++++++"); logger.Info($"Demand possibilities checker current gme state: {status.ToString()}."); logger.Info($"+++++++++++++++++++++++++++++++++++++++++++++++++++++++"); logger.Info($"+++++++++++++++++++++++++++++++++++++++++++++++++++++++"); } //can't demand rank and suit at the same time if (newDemRank != CardRanks.None && newDemSuit != CardSuits.None) { string text = "Rank and Suit can not be demanded both at the same time"; logger.Error(text); throw new ArgumentException(text); } //set demanding after placing the card on the table if (newDemRank == CardRanks.None && newDemSuit == CardSuits.None) { demandingType = "none"; demandedRank = CardRanks.None; demandedSuit = CardSuits.None; //status if (status != GameStatus.Battle && status != GameStatus.Stops && status != GameStatus.StopsAndBattle) { status = GameStatus.Standard; } ResetDemandingOptionsForAllPlayers(ref PlayersCurrentData, false); } else if (newDemRank != CardRanks.None && newDemSuit == CardSuits.None) { demandingType = "rank"; SetRankDemandOption(playerNumber, newDemRank, ref demandedRank, ref demandedSuit, ref PlayersCurrentData); //status status = GameStatus.RankDemanding; } else if (newDemRank == CardRanks.None && newDemSuit != CardSuits.None) { demandingType = "suit"; SetSuitDemandOption(playerNumber, newDemSuit, ref demandedRank, ref demandedSuit, ref PlayersCurrentData); //status status = GameStatus.SuitDemanding; } if (Engine.ExtendedLogging) { logger.Info($"Demand possibilities checking done. Demanded rank: {demandedRank.ToString()}, demanded suit: {demandedSuit.ToString()}, type: {demandingType}."); } return(true); }
public void Test_Card_Constructor(string strCard, CardRanks rank, CardSuits suit) { var card2h = new Card(strCard); Assert.AreEqual(rank, card2h.Rank); Assert.AreEqual(suit, card2h.Suit); }
public Deck(List <Card> cards, GameObject cardPrefab, Transform deckSpawnPoint) { ShuffleCards(cards); SpawnCards(cards, cardPrefab, deckSpawnPoint); trumpCard = deck.Pop(); trumpSuit = trumpCard.card.Suit; }
public Card(CardSuits suit, CardNames name) { this.suit = suit; this.name = name; value = (int)name; }
public DisposeTheEngine(ref int jokersInDeck, ref int decksInPlay, ref int startCardsAmount, ref int amountOfPlayers, ref bool staticTest, ref List <PlayingCard> CurrentDeck, ref List <PlayingCard> AlreadyUsedCards, ref Dictionary <int, SinglePlayerData> PlayersCurrentData, ref CardRanks demandedRank, ref CardSuits demandedSuit, ref int amountOfCardsToTake, ref GameStatus status) { jokersInDeck = 0; decksInPlay = 0; startCardsAmount = 0; amountOfPlayers = 0; staticTest = false; //inicialize lists CurrentDeck = null; AlreadyUsedCards = null; PlayersCurrentData = null; //For the game start no Suit nor rank is demanded demandedRank = CardRanks.None; demandedSuit = CardSuits.None; //at the start of game, amount of the cards to take as penalty for loosing the battle is 0 amountOfCardsToTake = 0; // at the start, set the game status to default - standard status = GameStatus.Standard; }
public int Power() { CardSuits cardSuit = (CardSuits)Enum.Parse(typeof(CardSuits), this.cardSuit); CardRank cardRank = (CardRank)Enum.Parse(typeof(CardRank), this.cardRank); return((int)(cardSuit) + (int)(cardRank)); }
protected override int logic(string[] args) { CardSuits reds = CardSuits.Diamonds | CardSuits.Hearts; CardSuits blacks = CardSuits.Clubs.Union(CardSuits.Spades); CardSuits minors = CardSuits.Clubs | CardSuits.Diamonds; CardSuits majors = CardSuits.Hearts.Union(CardSuits.Spades); CardSuits majorBlacks = majors.Intersect(blacks); CardSuits minorReds = minors.Intersect(reds); CardSuits allColors = reds.Union(blacks); CardSuits allLevels = minors.Union(majors); // minors + majors; // cannot use + here log("reds: {0}", reds); log("blacks: {0}", blacks); log("majors: {0}", majors); log("minors: {0}", minors); log("majorBlacks: {0}", majorBlacks); log("minorReds: {0}", minorReds); log("allColors: {0}", allColors); log("allLevels: {0}", allLevels); log("are Hearts a Minor suit? {0}", CardSuits.Hearts.In(minors)); log("what is the intersection of Majors and Minors? {0}", minors.Intersect(majors)); // this displays 0 CardSuits[] all = CardSuits.Clubs.All().ToArray(); // you need " Clubs" because there are no static Extension Methods foreach (CardSuits cardSuit in all) { log(cardSuit.ToString()); } return(0); }
//Confirming of putting card on the table private void BattleWindow_ConfirmButtonClick(object sender, ConfirmPutBattleCardOnTheTableEventArgs e) { //demanding options demandedRankRequest = e.DemandedRank; demandedSuitRequest = e.DemandedSuit; if (MatchingCardInBattleMode.CompareTo(new PlayingCard(e.NewSuit, e.NewRank, MatchingCardInBattleMode.DeckNumber)) == 0) { SendMovementDataToHost(GeneratePerformingAMoveRequestData(true, new List <PlayingCard>() { MatchingCardInBattleMode }, false)); } else { losingBattleCardAutoResponse = true; autoresponseCard = new PlayingCard(MatchingCardInBattleMode.Suit, MatchingCardInBattleMode.Rank, MatchingCardInBattleMode.DeckNumber); autoresponseCard.ChangeCardFromJocker(e.NewSuit, e.NewRank); EngineHostDataOperator Operator = new EngineHostDataOperator(); Operator.ResponseArrived += Operator_ResponseArrived; Operator.ChangeJokerIntoAnotherCard(GenerateJokerChangeRequest( MatchingCardInBattleMode, e.NewRank, e.NewSuit), ThisPlayerControl, SynchCont); } }
public CardObject() { System.Random rnd = new System.Random(); Value = rnd.Next(0, 13); RandomSeed1 = rnd.Next(-1000, 1000); RandomSeed2 = rnd.Next(-1000, 0); switch (rnd.Next(1, 5)) { default: case (1): Shape = CardSuits.Clubs; break; case (2): Shape = CardSuits.Diamonds; break; case (3): Shape = CardSuits.Hearts; break; case (4): Shape = CardSuits.Spades; break; } }
protected virtual void OnConfirmButtonClick(CardSuits suit, CardRanks rank, CardRanks demRank, CardSuits demDuit) { ConfirmButtonClick?.Invoke(this, new ConfirmPutBattleCardOnTheTableEventArgs() { NewRank = rank, NewSuit = suit, DemandedRank = demRank, DemandedSuit = demandedSuit }); }
//method for checking if the card is Brave private void CheckIfCardIsBrave(CardRanks cardRank, CardSuits cardSuit) { if (cardRank == CardRanks.Two || cardRank == CardRanks.Three || (cardRank == CardRanks.King && (cardSuit == CardSuits.Spade || cardSuit == CardSuits.Heart))) { brave = true; } }
public Card(CardSuits suit, CardValues cardVal) { cardSuit = suit; cardValue = cardVal; faceImage = ImageHelper.GetFaceImageForCard(this); backImage = ImageHelper.GetBackImage(); }
public void ToStringTest() { CardSuits suit = CardSuits.Spade; CardRanks rank = CardRanks.Ace; Card card = new(suit, rank); Assert.AreEqual(card.ToString(), ((char)suit).ToString() + ((char)rank).ToString()); }
//method for establishing demanded suit private void SetSuitDemandOption(int playerNumber, CardSuits demSuit, ref CardRanks demandedRank, ref CardSuits demandedSuit, ref Dictionary <int, SinglePlayerData> PlayersCurrentData) { ResetDemandingOptionsForAllPlayers(ref PlayersCurrentData, true); demandedRank = CardRanks.None; demandedSuit = demSuit; PlayersCurrentData[playerNumber].ThisPlayerStartedSuitDemanding = true; }
public void RetainingValueTest() { CardSuits suit = CardSuits.Club; CardRanks rank = CardRanks.Eight; Card card = new(suit, rank); Assert.True(card.Suit == suit && card.Rank == rank); }
private void Button_Click(object sender, RoutedEventArgs e) { ResetSelectionOfSuits(); newDemandedSuit = (CardSuits)(sender as WrapPanelSelectableItem).Tag; (sender as WrapPanelSelectableItem).ItemSelected = Visibility.Visible; var logger = NLog.LogManager.GetCurrentClassLogger(); logger.Info($"New demanded suit: {newDemandedSuit.ToString()}."); }
public CardCorrectnessChecker(PlayingCard cardToCheck, PlayingCard topCard, CardRanks demandedRank, CardSuits demandedSuit, GameStatus status) { this.cardToCheck = cardToCheck; this.topCard = topCard; this.demandedRank = demandedRank; this.demandedSuit = demandedSuit; this.status = status; logger = LogManager.GetCurrentClassLogger(); }
public void CardSuits_SuitListInitiatlized() { // Verify that each of our CardSuits are initialized correctly Assert.IsTrue(CardSuits.getAllSuits().Contains(CardSuits.Clubs)); Assert.IsTrue(CardSuits.getAllSuits().Contains(CardSuits.Diamonds)); Assert.IsTrue(CardSuits.getAllSuits().Contains(CardSuits.Hearts)); Assert.IsTrue(CardSuits.getAllSuits().Contains(CardSuits.Spades)); Assert.AreEqual(4, CardSuits.getAllSuits().Count); }
private void ResetInternalDemandOptions() { jackOrAceInCardsToPutOnTheTable = false; demandedRankRequest = CardRanks.None; IsPlayerDemandingRank = false; RankDemandedByThisPlayer = RankAndSuitNameProvider.GetRankName(CardRanks.None, "pl"); demandedSuitRequest = CardSuits.None; IsPlayerDemandingSuit = false; SuitDemandedByThisPlayer = RankAndSuitNameProvider.GetSuitName(CardSuits.None, "pl"); }
public static void Main() { string rank = Console.ReadLine(); string suit = Console.ReadLine(); CardRank cardRank = (CardRank)Enum.Parse(typeof(CardRank), rank); CardSuits cardSuit = (CardSuits)Enum.Parse(typeof(CardSuits), suit); Console.WriteLine($"Card name: {cardRank} of {cardSuit}; Card power: {(int)cardRank + (int)cardSuit}"); }
public void AceCardTest() { for (int indexSuit = 0; indexSuit < 4; indexSuit++) { CardSuits exampleSuit = (CardSuits)indexSuit; var card = new AceCard(exampleSuit); Assert.IsTrue(card.CardSuit == exampleSuit && card.CardName == CardNames.Ace && card.CardNumber == 11); } }
//method for checking next move direction private void EstablishNextMoveDirection(CardRanks cardRank, CardSuits cardSuit) { if (cardRank == CardRanks.King && cardSuit == CardSuits.Spade) { nextMove = CardMoveDirections.Backward; } else { nextMove = CardMoveDirections.Forward; } }
//method for handling with rank demanding window private void RankDemandingWindowHandle(CardSuits suit) { jackOrAceInCardsToPutOnTheTable = true; Windows.DemandTheRankWindow DemandingWindow = new DemandTheRankWindow(suit) { Owner = this, }; DemandingWindow.RankDemandingWindowClosing += DemandingWindow_RankDemandingWindowClosing; DemandingWindow.ShowDialog(); MemoryManagement.FlushMemory(); }
public DemandTheRankWindow(CardSuits suit) { jackInputSuit = suit; InitializeComponent(); PopulateSuitWrapPanel(); var logger = NLog.LogManager.GetCurrentClassLogger(); logger.Info("Rank demanding choice window initialized"); }
public GameWindowConstructor(GameWindow window, PersonalizedForSpecificPlayerStartGameDataRequest inputData, ref bool willBeClosedByHost, ref int amoutOfPlayersShown, ref int thisPlayerNumber, ref string thisPlayerID, ref string thisPlayerName, ref int minimumPlayerNumber, ref int maximumPlayerNumber, ref Dictionary <int, OtherPlayer> PlayersControlsMapper, ThirdPlayerLocation locationOfThirdPlayer, BackColor cardsBackColor, ref Dictionary <int, Rectangle> ActivePlayerRectangles, ref GameStateData GameStateData, ref List <PlayingCard> CardsChoosenByThisPlayer, ref CardRanks demandedRankRequest, ref CardSuits demandedSuitRequest, ref GameStateDataTranslator GameDataTranslator) { gameWindow = window; //Data context AssignControlsDataContext(); //at the window starts, if it is closed, closing is caused by user willBeClosedByHost = false; //initializing list of cards choosen by this player CardsChoosenByThisPlayer = new List <PlayingCard>(); //assign demanding options demandedRankRequest = CardRanks.None; demandedSuitRequest = CardSuits.None; //assign other player cards control type (horizontal/vertical) AssignOtherPlayersControlsOrientation(); //assigning current game state data for first time GameStateData = inputData.CurrentGameStatusData; GameDataTranslator = new GameStateDataTranslator(); //set local fields based on data passed in InitializeFields(inputData, ref amoutOfPlayersShown, ref thisPlayerNumber, ref thisPlayerID, ref thisPlayerName, ref minimumPlayerNumber, ref maximumPlayerNumber); //set controls visibility ManageControlVisibility(locationOfThirdPlayer, ref amoutOfPlayersShown); //assign player number properties of controlls AssignPlayersNumberIntoPropertiesOfControls(inputData, ref PlayersControlsMapper, ref maximumPlayerNumber, ref thisPlayerNumber, ref minimumPlayerNumber, ref ActivePlayerRectangles); //Assigning color of cards back AssignBackCardColor(cardsBackColor); //assign players Images and players names AssignPlayersAvatarsImagesAndNames(inputData); //assigning colors of rectangles that are backrounds of players names PlayersRectanglesColorAssigner.AssignPlayersRectanglesColors(ref ActivePlayerRectangles, inputData.CurrentPlayerNumber); //enabling this player controls ThisUserControlsEnabler.EnableOrDisableThisUserControls(ref gameWindow.ThisPlayerControl, ref gameWindow.DeckRepresentationControl, inputData.CurrentPlayerNumber); }
//clicking proper game suit - selection of card suit private void SuitButton_Click(object sender, RoutedEventArgs e) { thisSuit = (CardSuits)(sender as WrapPanelSelectableItem).Tag; thisRank = CardRanks.None; var logger = NLog.LogManager.GetCurrentClassLogger(); logger.Info($"New choosen Card suit: {thisSuit.ToString()}."); ResetSelectionOfSuits(); (sender as WrapPanelSelectableItem).ItemSelected = Visibility.Visible; RemoveAllChildrenFromRankScrllView(); PopulateRankWrapPanel(); }
private static byte ExtractCardFromString(string cmd) { cmd = cmd.Replace("10", "T"); cmd = cmd.ToLower(); if (cmd.Length < 1 || cmd.Length > 2) { throw new UnparseableMoveException(Errorstr.CardFormat(), cmd); } CardVals value = CardVals.NONE; CardSuits suit = CardSuits.NONE; char cmdValue = cmd[0]; char cmdSuit = '\0'; if (cmd.Length == 2) { cmdSuit = cmd[1]; } foreach (CardVals val in Enum.GetValues(typeof(CardVals))) { char valabbr = char.ToLower(GetCardValAbbr((byte)val, true)[0]); if (valabbr == cmdValue) { value = val; break; } } if (value == CardVals.NONE) { throw new UnparseableMoveException(Errorstr.CardFormat(), cmd); } if (cmdSuit != '\0') { cmdSuit = char.ToLower(cmdSuit); foreach (CardSuits suitf in Enum.GetValues(typeof(CardSuits))) { char suitabbr = GetCardSuitAbbr((byte)suitf, true); if (suitabbr == cmdSuit) { suit = suitf; break; } } if (suit == CardSuits.NONE) { throw new UnparseableMoveException("Invalid suit provided to a card", cmd); } } byte result = GetCardDigit(value, suit); return(result); }
public Card GetCard(CardValues cardValue, CardSuits suit) { foreach (Card c in this.Cards) { if (c.Value == cardValue && c.Suit == suit) { this.Cards.Remove(c); return c; } } return null; }
//used for counting the number of specific suit cards there are in the hand. static int CardSuitCounter(Card[] setOfCards, CardSuits cardsuit) { int setLength = 5; int returnValue = 0; for (int n = 0; n < setLength; n++) { if (setOfCards[n].CardSuit == cardsuit) { returnValue++; } } return returnValue; }
public void setCard(CardSuits suit, CardValues values) { this.card = new CardLib.Card(suit, values); card.Flip(); pictureBox1.Image = card.FacingImage; }
public Card(CardSuits suits, CardValue value) { Suits = suits; Value = value; }