private static bool PlayerOneWinsWar(DeckOfCards playerOne, DeckOfCards playerTwo) { var playerOneWins = false; //Console.WriteLine("WAR: {0}, {1}", cardPlayerOne.Name, cardPlayerTwo.Name); var moreCardsPlayerOne = playerOne.Deal(2); var moreCardsPlayerTwo = playerTwo.Deal(2); if (moreCardsPlayerOne.Cards[1].Beats(moreCardsPlayerTwo.Cards[1])) { playerOneWins = true; } else if (moreCardsPlayerTwo.Cards[1].Beats(moreCardsPlayerOne.Cards[1])) { // playerOneWins = false; } else { playerOneWins = PlayerOneWinsWar(playerOne, playerTwo); } if (playerOneWins) { playerOne.Add(moreCardsPlayerTwo.Cards); playerOne.Add(moreCardsPlayerOne.Cards); } else { playerTwo.Add(moreCardsPlayerTwo.Cards); playerTwo.Add(moreCardsPlayerOne.Cards); } return(playerOneWins); }
private static DeckOfCards GenerateTestDeck() { var deckOfCards = new DeckOfCards(); deckOfCards.Add(new Card(2, new Suite(1))); deckOfCards.Add(new Card(3, new Suite(1))); deckOfCards.Add(new Card(4, new Suite(1))); deckOfCards.Add(new Card(5, new Suite(1))); deckOfCards.Add(new Card(6, new Suite(1))); return(deckOfCards); }
public void CollectCards() { if (UsedPile.Count > 0) { foreach (var card in UsedPile) // Add used cards back to deck and then clear used pile :P { DeckOfCards.Add(card); } UsedPile.Clear(); } }
public void PlayTrick(DeckOfCards playerOne, DeckOfCards playerTwo) { try { var cardPlayerOne = playerOne.Deal(1).Cards[0]; var cardPlayerTwo = playerTwo.Deal(1).Cards[0]; var playerOneWins = false; if (cardPlayerOne.SameRankAs(cardPlayerTwo)) { playerOneWins = PlayerOneWinsWar(playerOne, playerTwo); } else if (cardPlayerOne.Beats(cardPlayerTwo)) { playerOneWins = true; } if (playerOneWins) { //Console.WriteLine("{0} beats {1} - cards to player 1", cardPlayerOne.Name, cardPlayerTwo.Name); playerOne.Add(cardPlayerOne); playerOne.Add(cardPlayerTwo); } else { //Console.WriteLine("{0} beats {1} - cards to player 2", cardPlayerTwo.Name, cardPlayerOne.Name); playerTwo.Add(cardPlayerOne); playerTwo.Add(cardPlayerTwo); } } catch { // move along } }
//Programos paleidime - sis metodas - 1 public void ConstructDeck() { for (int i = 0; i < 52; i++) { ICard _newcard = new Card(); do { _newcard.Sign = CardSignVariations[random.Next(0, 13)]; _newcard.Suit = CardSuitVariations[random.Next(0, 4)]; }while (DeckOfCards.Exists(x => x.Sign == _newcard.Sign && x.Suit == _newcard.Suit)); DeckOfCards.Add(_newcard); } }
public void Сroupier(int countPlayer) { int rankCard = 1; foreach (var type in new[] { "шестерка", "семерка", "восмерка", "девятка", "десятка", "валет", "дама", "король", "туз" }) { foreach (var suit in new[] { "черви", "бубни", "крести", "пики" }) { DeckOfCards.Add(new Card { Rank = rankCard, Type = type, Suit = suit }); } rankCard++; } var rand = new Random(); for (int i = 0; i < DeckOfCards.Count; i++) { var tmp = DeckOfCards[i]; DeckOfCards.RemoveAt(i); DeckOfCards.Insert(rand.Next(DeckOfCards.Count), tmp); } int countCardForPlayer = /*Koloda.Count / countPlayer*/ 2; // для теста поставил число 2 for (int j = 0; j < countPlayer; j++) { Players.Add(new Player()); for (int i = 0; i < countCardForPlayer; i++) { Players[j].Import.Add(DeckOfCards.First()); DeckOfCards.Remove(DeckOfCards.First()); } } }