public int PlayCard(Card card, int row, Card targetCard, bool player) { CaravanRow[] caravanRows = (row > 3) ? theirCaravans : myCaravans; int rowIndex = (row - 1) % 3; CaravanRow caravan = caravanRows[rowIndex]; if (targetCard == null) { caravan.addNumberedCard(card); } else { caravan.AddFaceCard(card, targetCard); if (card.GetRank() == Rank.Queen) { caravan.FlipIncreasing(); } if (card.GetRank() == Rank.Jack) { caravan.RemoveCard(targetCard); } } return(-1); }
public CaravanRow GetCaravan(int n) { CaravanRow[] rows = (n > 3) ? theirCaravans : myCaravans; CaravanRow row = rows[(n - 1) % 3]; return(row); }
public bool isGameOver() { int count = 0; for (int i = 0; i < 3; i++) { if (CaravanRow.isSold(theirCaravans[i]) || CaravanRow.isSold(myCaravans[i])) { count++; } } return(count == 3); }
public bool checkWinner() { int mySold = 0; int oppSold = 0; for (int i = 0; i < 3; i++) { CaravanRow mine = myCaravans[i]; CaravanRow theirs = theirCaravans[i]; if (CaravanRow.isSold(mine) && !CaravanRow.isSold(theirs)) { mySold++; } else if (!CaravanRow.isSold(mine) && CaravanRow.isSold(theirs)) { oppSold++; } else if (CaravanRow.isSold(mine) && CaravanRow.isSold(theirs)) { if (mine.GetScore() > theirs.GetScore()) { mySold++; } else if (mine.GetScore() < theirs.GetScore()) { oppSold++; } else { mySold++; oppSold++; } } } return(mySold >= oppSold); }
public static bool isSold(CaravanRow caravan) { return(caravan.score >= 21 && caravan.score <= 26); }
public bool ValidateMove(string move) { if (move.Contains("play")) { string[] tokens = move.Split(' '); int h = Int32.Parse(tokens[1]); int n = Int32.Parse(tokens[2]); CaravanRow row = gameBoard.GetCaravan(n); Card card = myPlayer.CardAt(h); if (tokens.Length == 4) { int c = Int32.Parse(tokens[3]); if (card.GetRank() == Rank.Queen) { if (row.GetSize() != c) { Console.WriteLine("Must play queen on last card."); return(false); } } if (row.GetNumFaceCardsAt(c) >= 3) { Console.WriteLine("Cannot attach more than 3 face cards to a number card"); } return(row.GetNumFaceCardsAt(c) < 3); } else if (tokens.Length == 3) { if (row.GetSize() == 0) { return(true); } if (card.GetRank() != row.GetEnd().GetRank() && card.GetSuite() == row.GetEnd().GetSuite()) { if (row.IsIncreasing() && card.GetValue() < row.GetEnd().GetValue()) { row.FlipIncreasing(); } else if (!row.IsIncreasing() && card.GetValue() > row.GetEnd().GetValue()) { row.FlipIncreasing(); } return(true); } if (row.GetEnd().GetRank() == card.GetRank()) { Console.WriteLine("Cannot play same card value twice in a row"); return(false); } if (row.GetSize() == 1) { if (row.IsIncreasing() && card.GetValue() < row.GetEnd().GetValue()) { row.FlipIncreasing(); } else if (!row.IsIncreasing() && card.GetValue() > row.GetEnd().GetValue()) { row.FlipIncreasing(); } return(true); } if (row.IsIncreasing()) { if (card.GetValue() > row.GetEnd().GetValue()) { return(true); } Console.WriteLine("Cannot play card of lower value"); return(false); } else { if (card.GetValue() < row.GetEnd().GetValue()) { return(true); } Console.WriteLine("Cannot play card of higher value"); return(false); } } } return(move.Contains("discard") || move.Contains("reset") || move == "give up"); }
public string GetMove() { string move = ""; string temp = ""; bool done = false; List <Card> hand = myPlayer.GetHand(); while (!done) { move = ""; Console.WriteLine("Would you like to 'play' a card, 'discard' a card, 'reset' a caravan, or 'give up'?"); temp = Console.ReadLine(); if (temp == "give up") { return(temp); } else if (temp == "play") { move += temp; ClearLastLine(); Console.WriteLine("Choose a card from your hand to play or enter cancel"); temp = GetNumber(hand.Count); if (temp == "cancel") { ClearLastLine(); continue; } move += " " + temp; int n = Int32.Parse(temp); Card c = hand[n - 1]; if (c.GetValue() > 10) { ClearLastLine(); ClearLastLine(); Console.WriteLine("Choose a caravan between 1-6 (4-6 are your opponent's) or enter cancel"); temp = GetNumber(6); if (temp == "cancel") { ClearLastLine(); continue; } move += " " + temp; ClearLastLine(); ClearLastLine(); Console.WriteLine("Choose a card in caravan " + temp + " or enter cancel"); int r = Int32.Parse(temp); CaravanRow row = gameBoard.GetCaravan(r); temp = GetNumber(row.GetSize()); if (temp == "cancel") { ClearLastLine(); continue; } move += " " + temp; return(move); } else { ClearLastLine(); ClearLastLine(); Console.WriteLine("Choose a caravan between 1-3 or enter cancel"); temp = GetNumber(3); if (temp == "cancel") { ClearLastLine(); continue; } move += " " + temp; return(move); } } else if (temp == "discard") { move += temp; ClearLastLine(); Console.WriteLine("Choose a card from your hand to discard or enter cancel"); temp = GetNumber(hand.Count); if (temp == "cancel") { ClearLastLine(); continue; } move += " " + temp; return(move); } else if (temp == "reset") { move += temp; ClearLastLine(); Console.WriteLine("Which caravan would you like to reset? Cancel action with 'cancel'"); temp = GetNumber(3); if (temp == "cancel") { ClearLastLine(); continue; } move += " " + temp; return(move); } else { ClearLastLine(); Console.WriteLine("Invalid command"); continue; } } return(move); }