//Give a card from hand to the target player public void GiveCardTo(TreasureCard theCard, int target) { theCard.FaceUp = true; players[target].AddToDisplayed(theCard); players[target].Given = true; }
//The give phase of each round, each player gives a card to another player public void GivePhase() { string input; //Set the Given attribute of each player to be false for (int i = 0; i < players.Count; i++) { players[i].Given = false; } //Set current player to be the first player //currentPlayer = players[0]; for (int i = 0; i < players.Count; i++) { bool cardFound = false; //whether a card to give is found bool playerFound = false; //whether a player to give is found TreasureCard theCard = currentPlayer.Displayed[0]; //the card that is selected by the player int target = 0; //the target player int left; //player to the left int right; //player to the right int opposite; //player to the opposite direction foreach (Player player in players) { player.UpdateScore(); } //find left player //when current player is last player if (i == 3) { left = 0; } //get left player else { left = i + 1; } //find right player //when current player is first player if (i == 0) { right = 3; } //get right player else { right = i - 1; } //find opposite player //when current player is first 2 player if (i < 2) { opposite = i + 2; } //when current player is last 2 players else { opposite = i - 2; } //Set current player //currentPlayer = players[i]; //Display opponent information //Write left player displayed cards Console.WriteLine("\r\n" + "The player on your left is : " + players[left].PlayerID + "\r\n" + "This player have displayed cards as following : "); for (int j = 0; j < players[left].Displayed.Count; j++) { Console.WriteLine(players[left].Displayed[j].Name); } //Write right player displayed cards Console.WriteLine("\r\n" + "The player on your right is : " + players[right].PlayerID + "\r\n" + "This player have displayed cards as following : "); for (int j = 0; j < players[right].Displayed.Count; j++) { Console.WriteLine(players[right].Displayed[j].Name); } //Write opposite player displayed cards Console.WriteLine("\r\n" + "The player on your opposite is : " + players[opposite].PlayerID + "\r\n" + "This player have displayed cards as following : "); for (int j = 0; j < players[opposite].Displayed.Count; j++) { Console.WriteLine(players[opposite].Displayed[j].Name); } //Display current player information //Write player ID Console.WriteLine("\r\n" + "Your Player Id is : " + players[i].PlayerID); //Write player displayed cards Console.WriteLine("Your displayed cards are : "); for (int j = 0; j < players[i].Displayed.Count; j++) { Console.WriteLine(players[i].Displayed[j].Name); } //Write player hand cards Console.WriteLine("Cards in your hands are : "); for (int j = 0; j < players[i].Hand.Count; j++) { Console.WriteLine(players[i].Hand[j].Name); } Console.WriteLine("Your current score is : " + players[i].TotalScore); if (players[left].Given && players[right].Given && players[opposite].Given) { Console.WriteLine("All the players have been given cards this round, so you can't give any card"); Console.WriteLine("Your current score is : " + players[i].TotalScore); Console.WriteLine("You are done with your turn, please give seat for next player" + "\r\n" + "Press Any Key to Continue"); Console.ReadLine(); Console.Clear(); continue; } //look for card to give while (!cardFound) { //Let player select card to give Console.WriteLine("\r\n" + "Which card do you want to give?" + "\r\n" + "1. Card from my displayed cards" + "\r\n" + "2. Card from my hand" ); //Get answer from player input = Console.ReadLine(); //Ask which specific card to give if (input == "1") { //Let player choose card in displayed cards Console.WriteLine("\r\n" + "Which card do you want to give?"); //Get answer from player string temp = Console.ReadLine(); //find card with name correspond to user input for (int j = 0; j < players[i].Displayed.Count; j++) { if (players[i].Displayed[j].Name.Equals(temp)) { cardFound = true; theCard = players[i].Displayed[j]; players[i].RemoveFromDisplayed(j); } } //if such a card exist, exit the loop if (cardFound == true) { break; } else { Console.WriteLine("Your selection is invalid, please try again"); continue; } } else if (input == "2") { //Let player choose card in hand Console.WriteLine("\r\n" + "Which card do you want to give?"); //Get answer from player string temp = Console.ReadLine(); //find card with name correspond to user input for (int j = 0; j < players[i].Hand.Count; j++) { if (players[i].Hand[j].Name.Equals(temp)) { cardFound = true; theCard = players[i].Hand[j]; } } //if such a card exist, exit the loop if (cardFound == true) { break; } else { Console.WriteLine("Your selection is invalid, please try again"); continue; } } else { Console.WriteLine("Your selection is invalid, please try again"); continue; } } //look for target player while (!playerFound) { //let player select target to give Console.WriteLine("\r\n" + "Which player do you want to give this card?" + "\r\n" + "1. Player to the left (" + players[left].PlayerID + " with a displayed score of " + players[left].DisplayedScore + ")" + "\r\n" + "2. Player to the right (" + players[right].PlayerID + " with a displayed score of " + players[right].DisplayedScore + ")" + "\r\n" + "3. Player to the opposite (" + players[opposite].PlayerID + " with a displayed score of " + players[opposite].DisplayedScore + ")" ); //get player answer input = Console.ReadLine(); if (input == "1") { //get left player if (!players[left].Given) { target = left; break; } else { Console.WriteLine("Your selection is invalid, please try again"); continue; } } else if (input == "2") { //get right player if (!players[right].Given) { target = right; break; } else { Console.WriteLine("Your selection is invalid, please try again"); continue; } } else if (input == "3") { //get opposite player if (!players[opposite].Given) { target = opposite; break; } else { Console.WriteLine("Your selection is invalid, please try again"); continue; } } else { Console.WriteLine("Your selection is invalid, please try again"); continue; } } GiveCardTo(theCard, target); if (players[i].Displayed.Count == 0) { cardFound = false; while (!cardFound) { Console.WriteLine("\r\n" + "Your displayed card area is currently empty, please choose another card from hand to display"); Console.WriteLine("Cards in your hands are : "); for (int j = 0; j < players[i].Hand.Count; j++) { Console.WriteLine(players[i].Hand[j].Name); } input = Console.ReadLine(); if (input != null) { for (int j = 0; j < players[i].Hand.Count; i++) { if (players[i].Hand[j].Name.Equals(input)) { players[i].AddToDisplayedFromHand(j); cardFound = true; break; } } } } } players[i].UpdateScore(); Console.WriteLine("Your current score is : " + players[i].TotalScore); Console.WriteLine("You are done with your turn, please give seat for next player" + "\r\n" + "Press Any Key to Continue"); Console.ReadLine(); Console.Clear(); } }
//Add a card to player's hand public void AddToHand(TreasureCard newCard) { hand.Add(newCard); }
//Add a card to a player's displayed card directly public void AddToDisplayed(TreasureCard newCard) { newCard.FaceUp = true; displayed.Add(newCard); }
//Add card to deck public void AddCard(TreasureCard newCard) { cards.Add(newCard); }